Local shadows top-level binding
a local name that hides a top-level let
let n = 5
fn f() -> Int:
let n = 10
n
print(f())let n = 5
fn f() -> Int:
let k = 10
k + n
print(f())Why
A parameter or local variable inside a function has the same name as a top-level let binding, which can hide an unintended reference to global input.
The practice it serves
Spelling that hides what the code means. Family: R. Redundancy and dead code.
Not flagged
A near miss: close to the pattern, but not it.
let n = 5
fn f(m: Int) -> Int:
let k = m * 2
k
print(f(n))Turn it off
For one block, wrap it in with lint(shadows_top_level: allow):. For a project, add shadows_top_level = "allow" under [lints] in cp.toml.
Generated from spec/lints/shadows_top_level, the same record the linter is built from.