You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive for prefer_self_in_static_references when an inner struct has the same name as its owner #5917
prefer_self_in_static_references will report a violation at var s = S1(), but S1 here refers to the inner struct, not the outer one, so var s= Self() would be different, and would fail if the inner S1 has different properties to the outer one.
As a workaround,
structS1{structS1{}vars=Self.S1()}
Has the same effect, but does not trigger prefer_self_in_static_references.
Activity
mildm8nnered commentedon Dec 27, 2024
I couldn't see any easy way to fix this :-(
SimplyDanny commentedon Dec 27, 2024
Would
Selfnot refer to the inner struct?Edit: Seems like the compiler wouldn't even allow it: https://swiftfiddle.com/iclkmj5lbbd4xew7g42r7l4vo4
mildm8nnered commentedon Dec 29, 2024
🤦 - I messed up with my example - corrected above.
Here is an example that shows it more clearly I hope
This compiles fine, but
swiftlint --only-rule prefer_self_in_static_references t.swiftproduceswarning: Prefer Self in Static References Violation: UseSelfto refer to the surrounding type name (prefer_self_in_static_references)SimplyDanny commentedon Dec 29, 2024
Got it.
This is nothing we can reliably avoid due to missing type information.theamodhshetty commentedon Mar 25, 2026
Opened #6552 to skip this rule when a nested type shadows the enclosing type name, and added an example to lock the case in.