nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.62k stars 623 forks source link

Don't add `self` in `@storageRestrictions` #1710

Closed MahdiBM closed 3 weeks ago

MahdiBM commented 1 month ago

@storageRestrictions(initializes: self.__myVar) in init-accessors is rejected by the compiler, but @storageRestrictions(initializes: __myVar) is accepted. I expect the compiler to be fine with the explicit self so I also filed this issue. This is not the current behavior so it still causes SwiftFormat make the code un-buildable when --self insert is present in the SwiftFormat configuration file.

Example that works:

struct MyStruct {
    private var __myVar: String
    var myVar: String {
        @storageRestrictions(initializes: __myVar)
        init {
            self.__myVar = newValue /// Original code makes some adjustments here
        }
        set {
            self.__myVar = newValue /// Original code makes some adjustments here
        }
        get {
            self.__myVar
        }
    }
}

This doesn't work:

-        @storageRestrictions(initializes: __myVar)
+        @storageRestrictions(initializes: self.__myVar)

So SwiftFormat should not add selfs in @storageRestrictions.

nicklockwood commented 3 weeks ago

@MahdiBM fixed in 0.54.0