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
Importing Foundation makes it so all instances of Error become implicitly castable to CustomStringConvertible by way of converting to NSError first. Explicitly checking if an instance conforms to CustomStringConvertible fails as expected though if the original type doesn't conform. However, the compiler emits an incorrect diagnostics stating that such tests will always succeed.
import Foundation
enumNonConfirmingError:Error{case blah
}letnonConformingError:Error=NonConfirmingError.blah
if case let castError as CustomStringConvertible= nonConformingError {// warning: 'if' condition is always trueprint(castError)// will not be executed}
if nonConformingError is CustomStringConvertible{// warning: 'if' condition is always trueprint(nonConformingError)// will not be executed}
The text was updated successfully, but these errors were encountered:
Robin: I'm curious how you stumbled across this. We don't expect folks to use `CustomStringConvertible` directly, so I'm curious whether you have a real need for that or whether you encountered this with some other protocol?
@tbkka IIRC, I was doing some spelunking to figure out how the string representation of Decodable errors is generated and how implicit bridging to NSError works. Stumbled across some code like this either in the standard library or the corelibs foundation. I noticed the odd behavior while using it in a playground.
I added some conformances to CustomStringConvertable to some types to generate better human-readable error messages, but I don't use any code like the above. Does that help?
Environment
Swift 5.1.3
Additional Detail from JIRA
md5: 0e269daa78868ba77486d440d86397a4
Issue Description:
Importing Foundation makes it so all instances of
Error
become implicitly castable toCustomStringConvertible
by way of converting toNSError
first. Explicitly checking if an instance conforms toCustomStringConvertible
fails as expected though if the original type doesn't conform. However, the compiler emits an incorrect diagnostics stating that such tests will always succeed.The text was updated successfully, but these errors were encountered: