Span stores the minimum range of byte positions in the file in which a given variable (types.Object) is mentioned. It is lexically defined: it spans from the beginning of its first mention to the end of its last mention. A variable is considered shadowed (if *strictShadowing is off) only if the shadowing variable is declared within the span of the shadowed variable. In other words, if a variable is shadowed but not used after the shadowed variable is declared, it is inconsequential and not worth complaining about. This simple check dramatically reduces the nuisance rate for the shadowing check, at least until something cleverer comes along.

One wrinkle: A "naked return" is a silent use of a variable that the Span will not capture, but the compilers catch naked returns of shadowed variables so we don't need to.

Cases this gets wrong (TODO): - If a for loop's continuation statement mentions a variable redeclared in the block, we should complain about it but don't. - A variable declared inside a function literal can falsely be identified as shadowing a variable in the outer function.

Span is referenced in 1 repository