parapoly: allow a constant default value for a polymorphic parameter

This commit is contained in:
gingerBill committed 2026-10-01 10:53:29 +01:00
1 parent efe87b06ec
commit 3551707607
2 files changed
+21 -5

No files matched your search

+15 -5
View File
@@ -6814,11 +6814,21 @@ gb_internal CallArgumentError check_call_arguments_internal(CheckerContext *c, A
}
if (!context_allocator_error) {
ordered_operands[i].mode = Addressing_Value;
ordered_operands[i].type = e->type;
if (e->Variable.param_value.kind == ParameterValue_Nil)
ordered_operands[i].type = t_untyped_nil;
ordered_operands[i].expr = e->Variable.param_value.original_ast_expr;
if (is_type_polymorphic(e->type) && e->Variable.param_value.kind == ParameterValue_Constant) {
// NOTE(bill): The parameter type is still polymorphic, so a constant default (e.g. `y: T = 0`) cannot be typed as '$T' here.
// Defer it like an untyped argument: determination resolves the parameter from the other arguments,
// then the default is materialized against the concrete type (reporting a clear error if it does not fit).
ordered_operands[i].mode = Addressing_Invalid;
ordered_operands[i].type = t_invalid;
ordered_operands[i].expr = e->Variable.param_value.original_ast_expr;
ordered_operands[i].deferred_untyped_arg = true;
} else {
ordered_operands[i].mode = Addressing_Value;
ordered_operands[i].type = e->type;
if (e->Variable.param_value.kind == ParameterValue_Nil)
ordered_operands[i].type = t_untyped_nil;
ordered_operands[i].expr = e->Variable.param_value.original_ast_expr;
}
dummy_argument_count += 1;
score += assign_score_function(1);