Skip to content

fix: use ns::Name as X binds the alias X (closes #43) - #45

Merged
Kinflou merged 1 commit into
masterfrom
fix/use-alias
Aug 31, 2026
Merged

fix: use ns::Name as X binds the alias X (closes #43)#45
Kinflou merged 1 commit into
masterfrom
fix/use-alias

Conversation

@Kinflou

@Kinflou Kinflou commented Aug 31, 2026

Copy link
Copy Markdown
Member

Completes #43. #44 made a plain use ns::Name bind bare Name; this adds aliases.

IR change

Import(String, (usize, usize))
// ->
Import(String, Option<String>, (usize, usize))   // (resolved path, local alias, span)

The alias is the X in use ns::Name as X; None for a plain use.

Behaviour

declaration binds
use types::User types::User (qualified) and bare User
use types::User as Account types::User (qualified) and Accountnot bare User
use types::* / use types::{A, B} per-symbol qualified + bare (alias meaningless, ignored)

Rust-style.

How

  • resolve_use_declaration takes the alias and attaches it to the single-symbol / whole-namespace Import unit.
  • SymbolTable gains a private bare_imports: HashSet — the alias, or the trailing segment of a plain use. It's kept out of symbols so it never trips duplicate detection and a real local declaration always shadows it. is_imported_bare checks that set (replacing the fix: use ns::Name binds the bare name Name in validation (#43) #44 scan).

Churn

~10 mechanical Import(x, y)Import(x, None, y) construction sites in incremental.rs; Import(p, _)Import(p, _, _) in 3 test files. CAS/serde handle the extra field transparently.

Tests

imports.rs: test_use_binds_the_bare_name, test_use_as_binds_the_alias (also asserts the Import unit carries alias = Some("Account")), test_use_as_does_not_bind_the_original_bare_name. from_sources.rs::cross_schema_use_resolves_across_the_added_schemas now covers bare / qualified / alias. Full suite green.

`FrozenUnit::Import(String, (usize,usize))` -> `Import(String,
Option<String>, (usize,usize))` — the second field is the local alias
from `use ns::Name as X` (`None` for a plain `use`).

- `resolve_use_declaration` takes the alias and attaches it to the
  single-symbol / whole-namespace import unit; glob and multi imports
  ignore it (meaningless there).
- Validation: `SymbolTable` gains a `bare_imports` set — the alias, or
  else the trailing segment of a plain `use`. Kept out of `symbols` so it
  never trips duplicate detection and a real local declaration always
  shadows it. `is_imported_bare` now checks that set.
- A plain `use ns::Name` still binds bare `Name` (from #44); an aliased
  `use ns::Name as X` binds `X` but NOT bare `Name`, Rust-style.

~10 mechanical `Import(x, y)` -> `Import(x, None, y)` construction sites,
and `Import(p, _)` -> `Import(p, _, _)` in the tests.

Tests: `imports.rs` gains `test_use_binds_the_bare_name`,
`test_use_as_binds_the_alias`, `test_use_as_does_not_bind_the_original_bare_name`;
`from_sources.rs` covers bare / qualified / alias. Full suite green.
@Kinflou
Kinflou merged commit aa84d97 into master Aug 31, 2026
6 checks passed
@Kinflou
Kinflou deleted the fix/use-alias branch September 2, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant