Skip to content

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Oct 2, 2025

The changes from #84259 caused a regression in which declarations from an outer scope could be shadowed inappropriately by member declarations from a module that has not been imported. This fix addresses the issue by refactoring resolveDeclRefExpr() so that it performs lookups in two passes. First, it attempts to resolve the decl ref using the complete lookup algorithm and standard name lookup options, which will ignore members from modules that haven't been imported if MemberImportVisibility is enabled. Then, if no results were found it re-runs the full lookup algorithm again with NameLookupFlags::IgnoreMissingImports included to find additional results that ought to be diagnosed as unavailable. This insures that the unavailable results are not considered until after the main lookup has already failed.

Resolves rdar://161078015.

@tshortli
Copy link
Contributor Author

tshortli commented Oct 2, 2025

@swift-ci please test

if (result)
return result;

// We didn't find any results. Look for common mistakes to diagnose.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the code below this point just moved but is otherwise unchanged.

@tshortli tshortli enabled auto-merge October 3, 2025 00:08
@tshortli
Copy link
Contributor Author

tshortli commented Oct 3, 2025

@swift-ci please test Linux

@tshortli tshortli force-pushed the member-import-visibility-resolve-decl-ref-expr-fix branch from 436eebe to 4773afa Compare October 3, 2025 05:17
@tshortli
Copy link
Contributor Author

tshortli commented Oct 3, 2025

@swift-ci please test

@tshortli tshortli force-pushed the member-import-visibility-resolve-decl-ref-expr-fix branch from 9bc1f44 to 168f36a Compare October 3, 2025 16:28
@tshortli
Copy link
Contributor Author

tshortli commented Oct 3, 2025

@swift-ci please test

The changes from swiftlang#84259 caused a
regression in which declarations from an outer scope could be shadowed
inappropriately by member declarations from a module that has not been
imported. This fix addresses the issue by refactoring `resolveDeclRefExpr()` so
that it performs lookups in two passes. First, it attempts to resolve the decl
ref using the complete lookup algorithm and standard name lookup options, which
will ignore members from modules that haven't been imported if
`MemberImportVisibility` is enabled. Then, if no results were found it re-runs
the full lookup algorithm again with `NameLookupFlags::IgnoreMissingImports`
included to find additional results that ought to be diagnosed as unavailable.
This insures that the unavailable results are not considered until after the
main lookup has already failed.

Resolves rdar://161078015.
@tshortli tshortli force-pushed the member-import-visibility-resolve-decl-ref-expr-fix branch from 168f36a to 8053120 Compare October 4, 2025 00:34
@tshortli
Copy link
Contributor Author

tshortli commented Oct 4, 2025

@swift-ci please smoke test

@tshortli tshortli merged commit 0fbf70e into swiftlang:main Oct 4, 2025
4 of 5 checks passed
@tshortli tshortli deleted the member-import-visibility-resolve-decl-ref-expr-fix branch October 4, 2025 14:25
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.

2 participants