Sitelet https://github.com/starkware-libs/cairo/pull/10209
Skip to content

fix(semantic): report a glob name collision of non-visible items as not-visible, not ambiguous - #10209

Merged
orizi merged 1 commit into
mainfrom
orizi/07-18-fix_semantic_report_a_glob_name_collision_of_non-visible_items_as_not-visible_not_ambiguous
Jul 18, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/07-18-fix_semantic_report_a_glob_name_collision_of_non-visible_items_as_not-visible_not_ambiguous

Conversation

@orizi

@orizi orizi commented Jul 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When resolving identifiers through use * (glob) imports, multiple distinct items from different modules can share the same name. Previously, the ItemNotVisible diagnostic variant required a concrete ModuleItemId, which forced the resolver to pick a single item even when multiple non-visible candidates existed. This PR changes ItemNotVisible to hold Option<ModuleItemId> so that ambiguous invisible candidates can be reported without pointing to a specific item.

The resolver now tracks non-visible candidates separately (non_pub_module_items_found) and uses exactly_one() to determine whether a single invisible item or multiple invisible items were found. When exactly one non-visible item exists, it is reported by name. When multiple non-visible items share the name, the diagnostic omits the item name and reports "Item is not visible in this context through any of the modules: ..." instead of "Item \...` is not visible..."`.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

When two glob imports (use a::*; use b::*;) both bring in a name that is not publicly visible, the old code would attempt to resolve the item in each non-visible module sequentially and report whichever it found first. This could produce a misleading diagnostic naming one specific item when in fact multiple invisible candidates existed. The fix correctly handles the ambiguous-invisible case.


What was the behavior or documentation before?

When multiple non-visible items shared the same name via glob imports, the diagnostic would arbitrarily name one of them: Item \some::path` is not visible in this context...`.


What is the behavior or documentation after?

When multiple non-visible items share the same name via glob imports, the diagnostic now reads: Item is not visible in this context through any of the modules: \test::a`, `test::b`.` — omitting the specific item path since no single item can be unambiguously identified.


Related issue or discussion (if any)

N/A


Additional context

A new test case (Testing use star with only invisible candidates) was added to diagnostic_test_data/tests to cover the scenario where all glob-imported candidates for a name are non-visible.

…ot-visible, not ambiguous

When resolving an identifier through `use *` with no visible candidate,
`resolve_path_using_use_star` folded the non-pub candidates back into
`module_items_found` and hit its `len() > 1` check, reporting E2087
("Ambiguous path") — but nothing is visible, so the user can't
disambiguate it. This is a visibility error.

Report E2099 (not visible) instead. Since several distinct non-visible
items may share only the name, `ItemNotVisible`'s item becomes
`Option<ModuleItemId>`: a lone candidate is still named, while multiple
candidates are reported without a specific item (just the modules).
Single/direct imports keep their exact message via `Some`.
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

@orizi
orizi marked this pull request as ready for review July 17, 2026 22:44
@cursor

cursor Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Localized semantic resolver and E2099 diagnostic changes with a targeted test; no runtime or security surface.

Overview
Glob (use *) resolution no longer treats multiple non-visible items with the same name as ambiguous or picks one arbitrarily. ItemNotVisible now carries Option<ModuleItemId>, and resolve_path_using_use_star collects invisible candidates in one pass, then uses exactly_one(): one candidate keeps a named message, several yield a generic "Item is not visible..." listing the source modules.

Diagnostic formatting was updated to omit a concrete item path when None. A regression test covers use a::*; use b::* when both modules define the same private name.

Reviewed by Cursor Bugbot for commit 04b5ed3. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 04b5ed3. Configure here.

Comment thread crates/cairo-lang-semantic/src/resolve/mod.rs

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware and orizi).

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orizi made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware).

Comment thread crates/cairo-lang-semantic/src/resolve/mod.rs
@orizi
orizi added this pull request to the merge queue Jul 18, 2026
Merged via the queue into main with commit daff9bc Jul 18, 2026
55 checks passed
@orizi
orizi deleted the orizi/07-18-fix_semantic_report_a_glob_name_collision_of_non-visible_items_as_not-visible_not_ambiguous branch July 18, 2026 11:36
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.

3 participants