mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 04:50:29 +00:00
Improve error message on using with procedure parameters #568
This commit is contained in:
@@ -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) {
|
||||
// NOTE(bill, 2019-08-31): Don't check the body as the where clauses failed
|
||||
return;
|
||||
|
||||
@@ -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) {
|
||||
for_array(i, *clauses) {
|
||||
Ast *clause = (*clauses)[i];
|
||||
@@ -6308,9 +6308,11 @@ bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *cla
|
||||
check_expr(ctx, &o, clause);
|
||||
if (o.mode != Addressing_Constant) {
|
||||
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;
|
||||
} else if (o.value.kind != ExactValue_Bool) {
|
||||
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;
|
||||
} else if (!o.value.value_bool) {
|
||||
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;
|
||||
}
|
||||
@@ -6617,7 +6620,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type
|
||||
ctx.curr_proc_sig = e->type;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +314,11 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs)
|
||||
|
||||
gbString str = expr_to_string(lhs->expr);
|
||||
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 {
|
||||
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;
|
||||
if (f->kind == Entity_Variable) {
|
||||
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);
|
||||
if (prev != nullptr) {
|
||||
gbString expr_str = expr_to_string(expr);
|
||||
|
||||
@@ -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) {
|
||||
error(st->where_clauses[0], "'where' clauses can only be used on structures with polymorphic parameters");
|
||||
} 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);
|
||||
}
|
||||
@@ -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) {
|
||||
error(ut->where_clauses[0], "'where' clauses can only be used on unions with polymorphic parameters");
|
||||
} 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