fix: use ns::Name as X binds the alias X (closes #43) - #45
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes #43. #44 made a plain
use ns::Namebind bareName; this adds aliases.IR change
The alias is the
Xinuse ns::Name as X;Nonefor a plainuse.Behaviour
use types::Usertypes::User(qualified) and bareUseruse types::User as Accounttypes::User(qualified) andAccount— not bareUseruse types::*/use types::{A, B}Rust-style.
How
resolve_use_declarationtakes the alias and attaches it to the single-symbol / whole-namespaceImportunit.SymbolTablegains a privatebare_imports: HashSet— the alias, or the trailing segment of a plainuse. It's kept out ofsymbolsso it never trips duplicate detection and a real local declaration always shadows it.is_imported_barechecks 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 inincremental.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 theImportunit carriesalias = Some("Account")),test_use_as_does_not_bind_the_original_bare_name.from_sources.rs::cross_schema_use_resolves_across_the_added_schemasnow covers bare / qualified / alias. Full suite green.