You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A generic fn cannot read its own module's globals: undefined variable at instantiation (pub or private, let or const) #1743
Spec: §18.1/§18.3 — a module's declarations are visible to that module's own code; §9.1c globals.
Repro (two files, base = branch gen-push-impl d06b5bc, release binary; installed main behaves the same):
own.w
pub let K: i32 = 5
pub fn g[T](a: T) -> i32: K
main.w
use own
fn main:
print(f"{g(1)}")
Actual:error: undefined variable --> own.w:2:27 ... K (help: did you mean 'a'?). The same with let K (private) or const K. A private fn called from the generic body resolves (fn helper() -> i32: 2 / pub fn g[T](a: T) -> i32: helper() prints 2), so the instantiation sees the module's fns but not its values.
Expected:5 — the generic body's module-level names are its module's, wherever it is instantiated.
Found while testing per-module global identity (#1703) on branch ruled-fixes; not caused by it (base reproduces). Workaround: none needed there — the fixture's generic reads no global.
Activity
Sema, codegen: a generic body reads its own module's globals (#1743)
Type checker: D74 entry sources and chain moves, field-view bindings (w…