aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-08-10 12:47:15 +0100
committerGitHub <noreply@github.com>2025-08-10 12:47:15 +0100
commita0ff05e63307f533b384820717bb582e1ff47c39 (patch)
treed9adfd28090dc72044003fed211383a63bdb3587 /src
parentdbc338248e8693994f232d02f1aff9536f204add (diff)
parent14ca1c8c89dd219dd52d061649d4db7778df2e64 (diff)
Merge pull request #5558 from odin-lang/bill/init-fini-changes
`@(init)` & `@(finit)` Changes.
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp6
-rw-r--r--src/check_expr.cpp8
-rw-r--r--src/checker.cpp9
3 files changed, 21 insertions, 2 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index af46ee40e..ee7906e5e 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1851,6 +1851,12 @@ gb_internal void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d,
c.scope = d->scope;
c.decl = d;
c.type_level = 0;
+ c.curr_proc_calling_convention = ProcCC_Contextless;
+
+ auto prev_flags = c.scope->flags;
+ defer (c.scope->flags = prev_flags);
+ c.scope->flags &= ~ScopeFlag_ContextDefined;
+
e->parent_proc_decl = c.curr_proc_decl;
e->state = EntityState_InProgress;
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 6a50b553e..db82a60ce 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -8169,8 +8169,12 @@ gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *c
if (pt->kind == Type_Proc && pt->Proc.calling_convention == ProcCC_Odin) {
if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
ERROR_BLOCK();
- error(call, "'context' has not been defined within this scope, but is required for this procedure call");
- error_line("\tSuggestion: 'context = runtime.default_context()'");
+ if (c->scope->flags & ScopeFlag_File) {
+ error(call, "Procedures requiring a 'context' cannot be called at the global scope");
+ } else {
+ error(call, "'context' has not been defined within this scope, but is required for this procedure call");
+ error_line("\tSuggestion: 'context = runtime.default_context()'");
+ }
}
}
diff --git a/src/checker.cpp b/src/checker.cpp
index a13290750..f631a1412 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -2675,6 +2675,10 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
is_init = false;
}
+ if (t->Proc.calling_convention != ProcCC_Contextless) {
+ error(e->token, "@(init) procedures must be declared as \"contextless\"");
+ }
+
if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
error(e->token, "@(init) procedures must be declared at the file scope");
is_init = false;
@@ -2689,6 +2693,7 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
error(e->token, "An @(init) procedure must not use a blank identifier as its name");
}
+
if (is_init) {
add_dependency_to_set(c, e);
array_add(&c->info.init_procedures, e);
@@ -2706,6 +2711,10 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
is_fini = false;
}
+ if (t->Proc.calling_convention != ProcCC_Contextless) {
+ error(e->token, "@(fini) procedures must be declared as \"contextless\"");
+ }
+
if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
error(e->token, "@(fini) procedures must be declared at the file scope");
is_fini = false;