fix: reject bare import bindings
This commit is contained in:
20
docs/spec.md
20
docs/spec.md
@@ -323,11 +323,25 @@ ImportPath = ident { "." ident } .
|
||||
package declares `package wire;`, the importing file sees its exported names
|
||||
as `wire.Name`; `codec.Name` is not an additional binding. An explicit alias
|
||||
replaces only that visible qualifier: `import stable acme.codec;` exposes
|
||||
`stable.Name`, not `wire.Name` or `codec.Name`. Both kinds of binding are
|
||||
scoped to that source file. A sibling file must declare its own import.
|
||||
`stable.Name`, not `wire.Name` or `codec.Name`. Each effective default or
|
||||
explicit named binding is a file-local package-name object usable only as
|
||||
the left qualifier of a selector. A bare occurrence in a value context is
|
||||
rejected as `use of package BINDING not in selector`; a bare occurrence in
|
||||
a type context is rejected as `BINDING (package name) is not a type`. Such a
|
||||
rejected bare occurrence does not count as use of the import for
|
||||
unused-import accounting. A legal selector does count as use, but does not
|
||||
excuse any separate bare occurrence. Both kinds of named binding are scoped
|
||||
to that source file. A sibling file must declare its own import; without one,
|
||||
its otherwise equal spelling follows ordinary undefined-name or unknown-type
|
||||
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.
|
||||
Neither form exposes an imported declaration as a bare `Name`; ordinary
|
||||
unqualified lookup remains limited to lexical, builtin, and same-package
|
||||
declarations.
|
||||
declarations. A blank import creates no package-name object, an effective
|
||||
`init` import is rejected before installing one, and a missing target fails
|
||||
during import resolution, so none of those cases acquires the bare-package
|
||||
diagnostics or satisfies a named import's unused accounting.
|
||||
- An import whose effective file-local qualifier is `init` is invalid. This
|
||||
includes both `import init acme.codec;` and an unaliased import whose target
|
||||
declares `package init;`. Each resolved occurrence is rejected at its first
|
||||
|
||||
Reference in New Issue
Block a user