diff options
| author | gingerBill <bill@gingerbill.org> | 2020-04-13 15:48:56 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-04-13 15:48:56 +0100 |
| commit | f229084baa383ebd81c5d04db1ede5dc71017904 (patch) | |
| tree | b2f5f4ace82547fd96e1e6bf3279dd300272c928 /src/check_type.cpp | |
| parent | f09b6a4c90805a562b2252430f844e85d06f1ee1 (diff) | |
Basic polymorphic named procedure parameters for procedures and records
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 089e66c4d..6df824ec1 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -469,7 +469,9 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array< is_polymorphic = true; can_check_fields = false; } - e = alloc_entity_constant(scope, token, operand.type, operand.value); + if (e == nullptr) { + e = alloc_entity_constant(scope, token, operand.type, operand.value); + } } } else { if (is_type_param) { @@ -1672,11 +1674,19 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is } } if (is_poly_name) { - if (op.mode == Addressing_Constant) { - poly_const = op.value; - } else { - error(op.expr, "Expected a constant value for this polymorphic name parameter"); - success = false; + bool valid = false; + if (is_type_proc(op.type)) { + Entity *proc_entity = entity_from_expr(op.expr); + valid = proc_entity != nullptr; + poly_const = exact_value_procedure(proc_entity->identifier ? proc_entity->identifier : op.expr); + } + if (!valid) { + if (op.mode == Addressing_Constant) { + poly_const = op.value; + } else { + error(op.expr, "Expected a constant value for this polymorphic name parameter"); + success = false; + } } } if (is_type_untyped(default_type(type))) { |