fix: allow lexical import shadowing
This commit is contained in:
15
docs/spec.md
15
docs/spec.md
@@ -336,6 +336,21 @@ ImportPath = ident { "." ident } .
|
||||
lookup rather than package-name diagnostics. Builtin spelling does not alter
|
||||
the object: an import bound as `len`, `size`, `align`, or another builtin name
|
||||
remains a selector-only package-name object.
|
||||
An ordinary lexical binding may shadow that file-local package-name object.
|
||||
Lookup at each occurrence chooses the nearest enclosing binding: a selector
|
||||
before a later local declaration can use and count the import, while the
|
||||
same spelling after that declaration denotes the local. Parameters bind for
|
||||
their whole function body; local `let` bindings begin after their declared
|
||||
type and initializer have been checked; tuple bindings begin after their
|
||||
right-hand side and declared types; and loop, range, and match-arm bindings
|
||||
begin only after their respective initializer/iterable or pattern/type has
|
||||
been checked. Nested blocks and loop scopes restore the imported package-name
|
||||
object on exit. These declaration-point rules apply equally to default,
|
||||
explicit, and builtin-spelled qualifiers. A selector counts as an import use
|
||||
only when its receiver resolves to that package-name object; a selector on a
|
||||
closer local, including a field or pseudo-field selector, does not.
|
||||
Go has no range-loop `else` clause; that WW-only extension is not assigned a
|
||||
Go-derived scope rule by this paragraph.
|
||||
Neither form exposes an imported declaration as a bare `Name`; ordinary
|
||||
unqualified lookup remains limited to lexical, builtin, and same-package
|
||||
declarations. A blank import creates no package-name object, an effective
|
||||
|
||||
Reference in New Issue
Block a user