From f229084baa383ebd81c5d04db1ede5dc71017904 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 13 Apr 2020 15:48:56 +0100 Subject: Basic polymorphic named procedure parameters for procedures and records --- src/check_type.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/check_type.cpp') 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))) { -- cgit v1.2.3