You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppress warning about #require(nonOptional) in some cases. (#947)
When using `try #require()` to unwrap an optional value, we emit a
compile-time warning if the value is not actually optional. However,
there is a bug in the type checker
(swiftlang/swift#79202) that triggers a false
positive when downcasting an object (of `class` type), e.g.:
```swift
class Animal {}
class Duck: Animal {}
let beast: Animal = Duck()
let definitelyADuck = try #require(beast as? Duck)
// ⚠️ '#require(_:_:)' is redundant because 'beast as? Duck' never equals 'nil'
```
This change suppresses the warning we emit if the expression contains
certain syntax tokens (namely `?`, `nil`, or `Optional`) on the
assumption that their presence means the test author is expecting an
optional value and we've hit a false positive.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
0 commit comments