S1854 FP on Swift 5.7 syntax

Hey Colin (I can’t @ you yet it seems). Just hit a time where it’s happened again. Example code below:

Task {
    do {
        let myThing = try await doMyOptionalAsyncThing()
        DispatchQueue.main.async {
            guard let myThing else { return }
    } catch {
        // handle error

On the 3rd line we get error swift:S1854 that myThing is not used, which to me is incorrect as we’re correctly using it in the guard on line 7 with the new Swift 5.7 syntax.

Thanks in advance for the help. :slightly_smiling_face:

Hey there.

There’s a distinction to be drawn between “analysis doesn’t fail encountering new syntax” and “false-positives as a result of using new syntax”. It sounds like yours falls into the latter.

I’ve split this thread and put your report in Report False-positive / False-negative... - Sonar Community and flagged some experts. Thanks for your report!

1 Like


Thanks for bringing this to our attention. I created a ticket to fix this False-Positive. The rule considers incorrectly that myThing is not used because its reference is now implicit with the new shorthand syntax.

Ticket: [SONARSWIFT-534] - Jira


1 Like

Amazing, thank you. Do you know when GitHub - SonarSource/sonar-scanner-vsts: SonarQube TFS/VSTS Marketplace Extension might be updated with v4.8 with this fix?

It’s the SonarQube server that needs to be updated, the fix is part of SonarQube 9.8