swiftlang/swift

Invalid fix-it on unused optional binding when multiple conditions

Open

#89.131 aberto em 14 de mai. de 2026

Ver no GitHub
 (2 comments) (0 reactions) (1 assignee)Swift (10.719 forks)batch import
compilerdiagnostics qualityfix-itsgood first issuestatementsswift 6.4type checker

Métricas do repositório

Stars
 (69.989 stars)
Métricas de merge de PR
 (Mesclagem média 7d 6h) (556 fundiu PRs em 30d)

Description

Description

No response

Reproduction

func sync() -> Int? {}
func async() async -> Int? {}
do {
  if let x = sync(), true {} // bad fix-it
  if let x = sync() {}      // good fix-it

  if let x = await async(), true {} // bad fix-it
  if let x = await async() {}     // good fix-it
}
warning: immutable value 'x' was never used; consider replacing with '_' or removing it [#NoUsage]
  if let x = sync(), true {}
     ~~~~^
     _
warning: value 'x' was defined but never used; consider replacing with boolean test [#NoUsage]
  if let x = sync() {}
     ~~~~^~~~
                    != nil
warning: immutable value 'x' was never used; consider replacing with '_' or removing it [#NoUsage]
  if let x = await async(), true {}
     ~~~~^
     _
warning: value 'x' was defined but never used; consider replacing with boolean test [#NoUsage]
  if let x = await async() {}
     ~~~~^~~~
     (                    ) != nil

Expected behavior

Fix-it should match the one we emit when the condition is single.

Environment

f0d8239caeefc8b

Additional information

Please add tests for both if let x = sync(), true and if true, let x = sync().

Guia do colaborador