Issue 0069's resolveForwardIdentifierAliases fixpoint runs at the END of scanDecls, but top-level var_decl globals and typed module constants had their annotations resolved via resolveType(ta) inside the SAME scan loop, before the fixpoint. So a forward identifier alias (`A :: B; B :: s32;`) used as a global's type (`g : A = 7;`) was still absent from type_alias_map: resolveType fabricated an empty-struct stub, and the global got a type mismatching its initializer at LLVM verification (the typed-const path `K : A : 42;` silently mistyped the constant instead). Split scanDecls into two passes: pass 1 registers function/type/alias facts, then resolveForwardIdentifierAliases converges the aliases, then pass 2 registers var_decl globals (registerTopLevelGlobal) and typed module constants (registerTypedModuleConst) against the converged alias map. Globals/typed-consts can't be named in a type position, so deferring them past type/alias registration is order-safe; the untyped module-const branch (no annotation to resolve) stays in pass 1. One incidental IR snapshot reorder (examples/1309: user globals now emit after foreign-class globals — semantically identical, program still exits 0). Regression: examples/0133-types-forward-alias-global.sx (forward-alias global + typed const). Gate: zig build, zig build test, run_examples.sh -> 354/0.
23 lines
752 B
Plaintext
23 lines
752 B
Plaintext
// Forward identifier type alias as a TOP-LEVEL annotation — a global var
|
|
// and a typed module constant whose annotation is a forward alias
|
|
// (`A :: B; B :: s32;`) resolve to the alias target, the same as the
|
|
// ordered form, instead of a fabricated stub.
|
|
// Regression (issue 0070): top-level global / typed-const annotations were
|
|
// resolved inside the scan loop BEFORE the forward-alias fixpoint ran, so
|
|
// `g : A` got a stub type that mismatched its initializer at LLVM
|
|
// verification. Global/const annotation resolution now runs in scan pass 2,
|
|
// after the fixpoint.
|
|
#import "modules/std.sx";
|
|
|
|
A :: B;
|
|
B :: s32;
|
|
|
|
g : A = 7;
|
|
K : A : 35;
|
|
|
|
main :: () -> s32 {
|
|
print("global g: {}\n", g);
|
|
print("const K: {}\n", K);
|
|
return g + K;
|
|
}
|