mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Prevent other parameters being the default value
This commit is contained in:
@@ -1008,6 +1008,20 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper
|
|||||||
return t_invalid;
|
return t_invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_expr_from_another_parameter(CheckerContext *ctx, Ast *expr) {
|
||||||
|
if (expr->kind == Ast_SelectorExpr) {
|
||||||
|
Ast *lhs = expr->SelectorExpr.expr;
|
||||||
|
return is_expr_from_another_parameter(ctx, lhs);
|
||||||
|
} else if (expr->kind == Ast_Ident) {
|
||||||
|
Operand x= {};
|
||||||
|
Entity *e = check_ident(ctx, &x, expr, nullptr, nullptr, false);
|
||||||
|
if (e->flags & EntityFlag_Param) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location) {
|
ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location) {
|
||||||
ParameterValue param_value = {};
|
ParameterValue param_value = {};
|
||||||
@@ -1053,11 +1067,19 @@ ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type *
|
|||||||
param_value.kind = ParameterValue_Constant;
|
param_value.kind = ParameterValue_Constant;
|
||||||
param_value.value = exact_value_procedure(e->identifier);
|
param_value.value = exact_value_procedure(e->identifier);
|
||||||
add_entity_use(ctx, e->identifier, e);
|
add_entity_use(ctx, e->identifier, e);
|
||||||
|
} else {
|
||||||
|
if (e->flags & EntityFlag_Param) {
|
||||||
|
error(expr, "Default parameter cannot be another parameter");
|
||||||
|
} else {
|
||||||
|
if (is_expr_from_another_parameter(ctx, expr)) {
|
||||||
|
error(expr, "Default parameter cannot be another parameter");
|
||||||
} else {
|
} else {
|
||||||
param_value.kind = ParameterValue_Value;
|
param_value.kind = ParameterValue_Value;
|
||||||
param_value.ast_value = expr;
|
param_value.ast_value = expr;
|
||||||
add_entity_use(ctx, e->identifier, e);
|
add_entity_use(ctx, e->identifier, e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user