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 program with a global named like a local inside another module's generic method is refused: 'shadowing is not allowed' points into std (enumerate's let i) #3187
fn count(xs: &List[str]) -> i32:
var n = 0
for (k, x) in xs.enumerate():
if x.len() > 0: n = n + k as i32
n
var i = 1
print(f"{count(&["a", "b"])} {i}")
error: shadowing is not allowed for 'i' (bound earlier in this scope)
--> <embedded-std>/std/collections.w:1044:9
1044 | let i = self.idx
Any program with a module-level var i (a global, since the file has a fn) and a use of enumerate() fails, with the error inside the standard library. Same with a user module: lib/helper.w with impl[T] Pair[T]: fn first(): let i = 0 … and a program var i = 1 → the error points at helper.w:4. A plain (non-generic) function of the other module with a local i is fine. The pinned seed fails the same way (not a regression of today's work). Found writing tools/facade_coverage.w (its argv loop is a top-level var i).
Root cause
Sema.scope_put_at refuses a local whose name a visible global holds unless binding_is_unseen_global says the global is another module's: path != self.current_module_path. For a generic instance body, check_generic_instance… (SemaCheck.w ~8037) switches the module with update_fn_source_context(fn_name, fn_node), which finds nothing for a method's instance symbol (no decl index, no fn_decl_source_paths entry), so current_module_path stays the instantiating program's, and the program's global reads as same-module. The template's path is computed two lines later (fn_symbol_source_path(fn_name), for #1766) but not applied to the context.
Fix
Apply the template's source path to the module context when the fn-level lookup found none. Fixture: a program with a global i using a lib module's generic method that binds i, and the std case (enumerate() beside a global i).
Activity
#3187: a callee's environment keeps the script marks of the bindings …
#3187: a callee's environment keeps the script marks of the bindings …
#3187: a callee's environment keeps the script marks of the bindings …