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
protocol ParentError: Error {}
struct ChildError1: ParentError {}
struct ChildError2: ParentError {}
func foo<SomeError: ParentError>(_ mockResult: Result<String, ChildError1>, _: Result<String, SomeError>) {
if let castedResult = mockResult as? Result<String, SomeError> {
print("The warning is wrong: \(castedResult)")
} else {
fatalError("If the warning is true it should crash here")
}
}
foo(.success("mock"), Result<String, ChildError1>.success("ignored"))
// foo(.success("mock"), Result<String, ChildError2>.success("ignored")) // This case does crash
Compiled with Swift 5.2.4 from Xcode 11.5, you get this output:
foo.swift:7:38: warning: cast from 'Result<String, ChildError1>' to unrelated type 'Result<String, SomeError>' always fails
if let castedResult = mockResult as? Result<String, SomeError> {
~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
The warning is wrong: success("mock")
If you uncomment the last line you hit the fatalError branch, so it's can fail, but doesn't always.
Additional Detail from JIRA
md5: 094b37b824821e575c778391062eb070
Parent-Task:
Issue Description:
With this code:
Compiled with Swift 5.2.4 from Xcode 11.5, you get this output:
If you uncomment the last line you hit the fatalError branch, so it's can fail, but doesn't always.
Potentially related https://bugs.swift.org/browse/SR-13025 https://bugs.swift.org/browse/SR-12321
The text was updated successfully, but these errors were encountered: