[SR-14322] Bridging to NSError fails for instances of a class #56681
Labels
bridging
Feature → casting: type bridging
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
casting
Feature: explicit casting (is, as, as? and as!)
compiler
The Swift compiler in itself
objective-c interop
Feature: Interoperability with Objective-C
swift 5.9
type checker
Area → compiler: Semantic analysis
unexpected error
Bug: Unexpected error
Additional Detail from JIRA
md5: d0169e4ca27e6cfd3360b31001ed01d0
Issue Description:
(Also posted in the Swift forum: Bridging to NSError fails for instances of a class.)
According to SE-0112, every type that conforms to the
Error
protocol is implicitly bridged toNSError
. This does not work with reference types, the last line in the following example does not compile:Inserting an “intermediate cast” to
Error
makes it compile and run as expected:That problem occurs only if the custom error type is a class, not with a struct or an enum.
The text was updated successfully, but these errors were encountered: