nicklockwood / SwiftFormat

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

Error with conditionalAssignment #1601

Closed shkhaliq closed 9 months ago

shkhaliq commented 9 months ago

I am seeing a ton of errors with conditionalAssignment rules. This is one of them

Screenshot 2023-12-22 at 7 44 17 PM

SwiftFormat Version: 0.52.11 Swift version: 5.9.2 Xcode Version: 15.1.0

I can help provide more examples if needed

nicklockwood commented 9 months ago

@shkhaliq I'm having trouble reproducing this issue. When I try it with default settings the return keywords are removed and it compiles fine. When I try it with redundantReturn disabled, it leaves the code unaltered.

What settings are you using? Can you provide a standlone sample that formats incorrectly with those settings?

calda commented 9 months ago

@shkhaliq, what error do you get? There are some bugs in Swift 5.9 where some otherwise well-formed if/switch expressions unexpectedly fail to compile.

shkhaliq commented 9 months ago

Sorry this was a late night post - and yes @calda I am seeing compiler errors which has nothing to do with SwiftFormat.

I was previously seeing errors but then realized was using an outdated version of SwiftFormat

rogerluan commented 7 months ago

@nicklockwood any chance we can have conditionalAssignment's behavior working even if redundantSelf is disabled? Like, same as OP, but removing those return statements since their presence is what causes compiler errors and they must be removed in all scenarios AFAICT. Tightly coupling 2 rules in order for 1 of them to work feels kinda hacky 😅

Thanks for your help! 🙏

nicklockwood commented 7 months ago

@rogerluan to be clear, you aren't seeing errors, right? It's just that conditionalAssignment isn't being applied to cases like the above unless redundantReturn is also enabled?