05.2 Name resolution
Scope-first lookup, import precedence, and ambiguity errors."
Name resolution
Name resolution is the compiler answering which declaration did you mean? When the answer is “more than one,” you get an ambiguity error—this is a feature.
Expression lookup order
Section titled “Expression lookup order”- Local scope (parameters,
letbindings) - Enclosing scopes
- Imports (including aliases)
- Module scope
flowchart TD
N[Name reference] --> L{Local binding?}
L -->|yes| OK[Use local]
L -->|no| E[Enclosing scopes]
E --> I[Imports]
I --> M[Module scope]
Ambiguity
Section titled “Ambiguity”If two imports provide the same unaliased name, the compiler errors. Fix with as aliases—do not rely on import order to “win.”
Imports do not override locals
Section titled “Imports do not override locals”Assuming use Foo; lets you shadow a local Foo is a fast path to embarrassment. Locals win.
Cross-module paths
Section titled “Cross-module paths”Fully qualified paths follow module nesting declared by files and mod statements. When lost, beskid analyze with a one-file repro beats staring at folders.