mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Correct default procedure parameter logic
This commit is contained in:
+17
-5
@@ -1254,8 +1254,11 @@ ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type *
|
|||||||
} else if (allow_caller_location && o.mode == Addressing_Context) {
|
} else if (allow_caller_location && o.mode == Addressing_Context) {
|
||||||
param_value.kind = ParameterValue_Value;
|
param_value.kind = ParameterValue_Value;
|
||||||
param_value.ast_value = expr;
|
param_value.ast_value = expr;
|
||||||
|
} else if (o.value.kind != ExactValue_Invalid) {
|
||||||
|
param_value.kind = ParameterValue_Constant;
|
||||||
|
param_value.value = o.value;
|
||||||
} else {
|
} else {
|
||||||
error(expr, "Default parameter must be a constant");
|
error(expr, "Default parameter must be a constant, %d", o.mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1414,10 +1417,19 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
|
|||||||
type = t_invalid;
|
type = t_invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param_value.kind != ParameterValue_Invalid && is_type_polymorphic(type)) {
|
if (is_type_polymorphic(type)) {
|
||||||
gbString str = type_to_string(type);
|
switch (param_value.kind) {
|
||||||
error(params[i], "A default value for a parameter must not be a polymorphic constant type, got %s", str);
|
case ParameterValue_Invalid:
|
||||||
gb_string_free(str);
|
case ParameterValue_Constant:
|
||||||
|
case ParameterValue_Nil:
|
||||||
|
break;
|
||||||
|
case ParameterValue_Location:
|
||||||
|
case ParameterValue_Value:
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user