mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Improve error message on using with procedure parameters #568
This commit is contained in:
+1
-1
@@ -1207,7 +1207,7 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool where_clause_ok = evaluate_where_clauses(ctx, decl->scope, &decl->proc_lit->ProcLit.where_clauses, true);
|
bool where_clause_ok = evaluate_where_clauses(ctx, nullptr, decl->scope, &decl->proc_lit->ProcLit.where_clauses, true);
|
||||||
if (!where_clause_ok) {
|
if (!where_clause_ok) {
|
||||||
// NOTE(bill, 2019-08-31): Don't check the body as the where clauses failed
|
// NOTE(bill, 2019-08-31): Don't check the body as the where clauses failed
|
||||||
return;
|
return;
|
||||||
|
|||||||
+5
-2
@@ -6300,7 +6300,7 @@ Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *clauses, bool print_err) {
|
bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Array<Ast *> *clauses, bool print_err) {
|
||||||
if (clauses != nullptr) {
|
if (clauses != nullptr) {
|
||||||
for_array(i, *clauses) {
|
for_array(i, *clauses) {
|
||||||
Ast *clause = (*clauses)[i];
|
Ast *clause = (*clauses)[i];
|
||||||
@@ -6308,9 +6308,11 @@ bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *cla
|
|||||||
check_expr(ctx, &o, clause);
|
check_expr(ctx, &o, clause);
|
||||||
if (o.mode != Addressing_Constant) {
|
if (o.mode != Addressing_Constant) {
|
||||||
if (print_err) error(clause, "'where' clauses expect a constant boolean evaluation");
|
if (print_err) error(clause, "'where' clauses expect a constant boolean evaluation");
|
||||||
|
if (print_err && call_expr) error(call_expr, "at caller location");
|
||||||
return false;
|
return false;
|
||||||
} else if (o.value.kind != ExactValue_Bool) {
|
} else if (o.value.kind != ExactValue_Bool) {
|
||||||
if (print_err) error(clause, "'where' clauses expect a constant boolean evaluation");
|
if (print_err) error(clause, "'where' clauses expect a constant boolean evaluation");
|
||||||
|
if (print_err && call_expr) error(call_expr, "at caller location");
|
||||||
return false;
|
return false;
|
||||||
} else if (!o.value.value_bool) {
|
} else if (!o.value.value_bool) {
|
||||||
if (print_err) {
|
if (print_err) {
|
||||||
@@ -6352,6 +6354,7 @@ bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *cla
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (call_expr) error(call_expr, "at caller location");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -6617,7 +6620,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type
|
|||||||
ctx.curr_proc_sig = e->type;
|
ctx.curr_proc_sig = e->type;
|
||||||
|
|
||||||
GB_ASSERT(decl->proc_lit->kind == Ast_ProcLit);
|
GB_ASSERT(decl->proc_lit->kind == Ast_ProcLit);
|
||||||
if (!evaluate_where_clauses(&ctx, decl->scope, &decl->proc_lit->ProcLit.where_clauses, false)) {
|
if (!evaluate_where_clauses(&ctx, operand->expr, decl->scope, &decl->proc_lit->ProcLit.where_clauses, false)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -314,7 +314,11 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs)
|
|||||||
|
|
||||||
gbString str = expr_to_string(lhs->expr);
|
gbString str = expr_to_string(lhs->expr);
|
||||||
if (e != nullptr && e->flags & EntityFlag_Param) {
|
if (e != nullptr && e->flags & EntityFlag_Param) {
|
||||||
error(lhs->expr, "Cannot assign to '%s' which is a procedure parameter", str);
|
if (e->flags & EntityFlag_Using) {
|
||||||
|
error(lhs->expr, "Cannot assign to '%s' which is from a 'using' procedure parameter", str);
|
||||||
|
} else {
|
||||||
|
error(lhs->expr, "Cannot assign to '%s' which is a procedure parameter", str);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error(lhs->expr, "Cannot assign to '%s'", str);
|
error(lhs->expr, "Cannot assign to '%s'", str);
|
||||||
}
|
}
|
||||||
@@ -497,6 +501,8 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
|
|||||||
Entity *f = found->elements.entries[i].value;
|
Entity *f = found->elements.entries[i].value;
|
||||||
if (f->kind == Entity_Variable) {
|
if (f->kind == Entity_Variable) {
|
||||||
Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
|
Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
|
||||||
|
if (e->flags & EntityFlag_Value) uvar->flags |= EntityFlag_Value;
|
||||||
|
if (e->flags & EntityFlag_Param) uvar->flags |= EntityFlag_Param;
|
||||||
Entity *prev = scope_insert(ctx->scope, uvar);
|
Entity *prev = scope_insert(ctx->scope, uvar);
|
||||||
if (prev != nullptr) {
|
if (prev != nullptr) {
|
||||||
gbString expr_str = expr_to_string(expr);
|
gbString expr_str = expr_to_string(expr);
|
||||||
|
|||||||
+2
-2
@@ -527,7 +527,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array<
|
|||||||
if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) {
|
if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) {
|
||||||
error(st->where_clauses[0], "'where' clauses can only be used on structures with polymorphic parameters");
|
error(st->where_clauses[0], "'where' clauses can only be used on structures with polymorphic parameters");
|
||||||
} else {
|
} else {
|
||||||
bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &st->where_clauses, true);
|
bool where_clause_ok = evaluate_where_clauses(ctx, node, ctx->scope, &st->where_clauses, true);
|
||||||
}
|
}
|
||||||
check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context);
|
check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context);
|
||||||
}
|
}
|
||||||
@@ -714,7 +714,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op
|
|||||||
if (ut->where_clauses.count > 0 && ut->polymorphic_params == nullptr) {
|
if (ut->where_clauses.count > 0 && ut->polymorphic_params == nullptr) {
|
||||||
error(ut->where_clauses[0], "'where' clauses can only be used on unions with polymorphic parameters");
|
error(ut->where_clauses[0], "'where' clauses can only be used on unions with polymorphic parameters");
|
||||||
} else {
|
} else {
|
||||||
bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &ut->where_clauses, true);
|
bool where_clause_ok = evaluate_where_clauses(ctx, node, ctx->scope, &ut->where_clauses, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user