Enforce explicit context definition for procedure calls

This commit is contained in:
gingerBill
2020-05-14 13:44:28 +01:00
parent cd4403be0c
commit e0a242e9a1
9 changed files with 68 additions and 40 deletions
+6
View File
@@ -7411,6 +7411,12 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Type *t
Type *pt = base_type(proc_type);
if (pt->kind == Type_Proc && pt->Proc.calling_convention == ProcCC_Odin) {
if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
error(call, "'context' has not been defined within this scope, but is required for this procedure call");
}
}
#if 0
if (pt->kind == Type_Proc && pt->Proc.calling_convention == ProcCC_Odin) {
init_core_context(c->checker);
+2
View File
@@ -2512,6 +2512,8 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
GB_ASSERT(cc > 0);
if (cc == ProcCC_Odin) {
c->scope->flags |= ScopeFlag_ContextDefined;
} else {
c->scope->flags &= ~ScopeFlag_ContextDefined;
}
bool variadic = false;
+1
View File
@@ -281,6 +281,7 @@ Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) {
if (s->flags & (ScopeFlag_Init|ScopeFlag_Global)) {
s->flags |= ScopeFlag_HasBeenImported;
}
s->flags |= ScopeFlag_ContextDefined;
return s;
}