Skip to content

Ignore module-selected types in prefer_self_in_static_references - #6930

Open
SwastikTripathi wants to merge 1 commit into
realm:mainfrom
SwastikTripathi:fix-prefer-self-module-selector
Open

SwastikTripathi wants to merge 1 commit into
realm:mainfrom
SwastikTripathi:fix-prefer-self-module-selector

Conversation

@SwastikTripathi

Copy link
Copy Markdown

Fixes #6924.

prefer_self_in_static_references compared only the type name, so Foundation::TimeInterval inside enum TimeInterval was reported, and --fix would have rewritten it to Foundation::Self. With a module selector the name refers to a type from that module, so the rule now skips IdentifierTypeSyntax and DeclReferenceExprSyntax nodes that have a moduleSelector. Unqualified references (TimeInterval, Date.reference) are reported as before.

I added two non-triggering examples covering a return type, a property type and a static member access through Foundation::. Both fail on main and pass with the change. swift test passes in full, and running the built binary on the snippet from the issue now reports only the unqualified Date.reference reference.

I only looked at this rule. The issue says others may be affected too, but I haven't audited them here.

🤖 Generated with Claude Code

A type written with a module selector (`Foundation::TimeInterval`) names a
type from that module, so it shouldn't be reported (or corrected to
`Self`) just because its name matches the surrounding type.

Fixes realm#6924.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Swift 6.3 module selectors lead to false positives

1 participant