CHECK 3 done

Enhance support for polymorphic procedures in type checking

1. In src/check_type.cpp, added special handling for polymorphic procedures used as default parameter values. We now allow a polymorphic procedure to be used as a default parameter value, even when its type parameters can't be immediately determined.

2. In src/check_expr.cpp, we modified the check_is_assignable_to_with_score function to handle the special case of assigning a polymorphic procedure as a default parameter. The function now allows a polymorphic procedure to be assigned to a concrete procedure type in this specific context.
This commit is contained in:
bogwi
2025-05-05 17:53:32 +09:00
parent af0e067a12
commit af6b763449
2 changed files with 39 additions and 10 deletions
+10 -1
View File
@@ -1910,9 +1910,18 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
case ParameterValue_Location:
case ParameterValue_Expression:
case ParameterValue_Value:
// Special case for polymorphic procedures as default values
if (param_value.ast_value != nullptr) {
Entity *e = entity_from_expr(param_value.ast_value);
if (e != nullptr && e->kind == Entity_Procedure && is_type_polymorphic(e->type)) {
// Allow polymorphic procedures as default parameter values
// The type will be correctly determined at call site
break;
}
}
gbString str = type_to_string(type);
error(params[i], "A default value for a parameter must not be a polymorphic constant type, got %s", str);
gb_string_free(str);
gb_string_free(str);
break;
}
}