aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorbogwi <bogwi@rakumail.jp>2025-05-05 17:53:32 +0900
committerbogwi <bogwi@rakumail.jp>2025-05-05 17:53:32 +0900
commitaf6b763449a7876f08b3edaf9875c57769f10bd4 (patch)
tree1e93695d784ea4e3aa83a30d1fc0cde1558c6c4b /src/check_type.cpp
parentaf0e067a12079cc16020e264c6157bb5581c9cf4 (diff)
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.
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 452da4023..431698459 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -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;
}
}