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
When using a key path within property initialization (either as a parameter in a function/initializer for another type or as the property itself) I believe SwiftLint is falsely identifying the key path as referencing a function on NSObject.
finalclassNotActuallyReferencingSelf{// This doesn't actually reference `self` but it shows an error "`self` refers to the unapplied `NSObject.self()`"letkeyPath:Any= \String.self
// This does *not* show an error.letsomeType:Any=String.self
}
The error mentions NSObject, but String is a struct and you can verify this with any type \Foo.self.
Command/Output
$ swiftlint --strict
/Path/to/the/file/NotActuallyReferencingSelf.swift:10:5: error: Self in Property Initialization Violation: self refers to the unapplied NSObject.self() method, which is likely not expected; make the variable lazy to be able to refer to the current instance or use ClassName.self (self_in_property_initialization)
In reference to this case I believe we are using "ClassName.self".
Environment
SwiftLint version: 0.57.0
Xcode version: 16.0.0
Installation method used: Homebrew
Configuration file: default
Are you using nested configurations? If so, paste their
relative paths and respective contents.
No nested config
The text was updated successfully, but these errors were encountered:
New Issue Checklist
Bug Description
When using a key path within property initialization (either as a parameter in a function/initializer for another type or as the property itself) I believe SwiftLint is falsely identifying the key path as referencing a function on
NSObject
.The error mentions
NSObject
, butString
is astruct
and you can verify this with any type\Foo.self
.Command/Output
In reference to this case I believe we are using "
ClassName.self
".Environment
Are you using nested configurations? If so, paste their
relative paths and respective contents.
The text was updated successfully, but these errors were encountered: