Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

strongifiedSelf strips some necessary backticks #1670

Closed
heiberg opened this issue Apr 11, 2024 · 5 comments
Closed

strongifiedSelf strips some necessary backticks #1670

heiberg opened this issue Apr 11, 2024 · 5 comments
Labels

Comments

@heiberg
Copy link

heiberg commented Apr 11, 2024

Description

Swift 5.10 (Xcode 15.3) introduced the nonisolated(unsafe) keyword.

In the following line the backticks are required:

nonisolated(unsafe) let `self` = self

The strongifiedSelf rule strips these, which results in the error

馃敶 Keyword 'self' cannot be used as an identifier here

Note that the example here is not strongifying a weak self, but rather declaring a non-isolated version of self (useful in certain test cases) .

Environment

  • Xcode 15.3
  • Swift 5.10
  • SwiftFormat 0.53.5
@heiberg heiberg changed the title strongifiedSelf strips some necessary backticks strongifiedSelf strips some necessary backticks Apr 11, 2024
@nicklockwood
Copy link
Owner

@heiberg I've not been able to reproduce this in 0.53.5 or 0.53.6. It's possible that the bug depends on some surrounding context - could you provide the whole method? (or whatever minimal code is needed to reproduce the problem in isolation)

@heiberg
Copy link
Author

heiberg commented Apr 26, 2024

Sure! Sorry for the delay, I missed the notification here.

Input

class Hello {
    func foo() {
        nonisolated(unsafe) let `self` = self
    }
}

Command

swiftformat --swiftversion 5.10 Input.swift

Expected Output

Unchanged.

Observed Output

class Hello {
    func foo() {
        nonisolated(unsafe) let self = self
    }
}

Unexpected change:

class Hello {
    func foo() {
-        nonisolated(unsafe) let `self` = self
+        nonisolated(unsafe) let self = self
    }
}

Environment

SwiftFormat 0.53.5

@heiberg
Copy link
Author

heiberg commented May 14, 2024

@nicklockwood Was this issue reproducible given the above?

@nicklockwood
Copy link
Owner

nicklockwood commented May 18, 2024

@heiberg sorry, I also missed this update. I believe the issue was that the issue only arises when --swiftversion is set to 4.2 or above, so it wasn't showing up in my test case. I should have a fix shortly.

@nicklockwood
Copy link
Owner

@heiberg fixed in 0.53.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants