Open rgoldberg opened 1 week ago
I see this as a shortcoming in the Swift compiler. It should check if a certain statement referencing deprecated declarations is actually reachable in the relevant context.
In your example, whether the else
block is there or not doesn't make a semantical difference. Do you agree?
While I agree that it's a shortcoming in the compiler, I think that it might make sense to add a switch to ignore else
clauses if #available
or other similar directives are in any chained if
condition.
People might not be able to upgrade their compiler to versions that receive a fix (due to macOS version requirements for new Xcode versions, or otherwise) but might be able to upgrade their SwiftLint.
Fair point. So let's treat this as a bug and update the behavior when/if the compiler received this feature depending on the Swift version in use.
New Issue Checklist
Bug Description
superfluous_else
outputs a false positive when usingif #available(…) else
to avoid deprecation warning:The
else
is necessary to avoid 2 deprecation warnings fromDispatchQueue.global(priority: .high).async {}
.That isn't my real use case; the deprecated function I use require arguments to be initialized & configured, so I just chose a very simple deprecated function at random as a much simpler example of the problem.
Presumably the same problem applies to
#unavailable
or other similar directives (i.e.if #<something> {} else {}
.Environment