Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-4414] Implicit type casting from Error to NSError works before other type casting. #46991

Open
swift-ci opened this issue Mar 29, 2017 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4414
Radar None
Original Reporter tarunon (JIRA User)
Type Bug
Environment

Swift 3.1, Xcode 8.3, Playground

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Runtime
Assignee @DougGregor
Priority Medium

md5: 6da17e3a189bae0abaaf29a0dc66b997

Issue Description:

1. Make a protocol `A`.
2. Conform a protocol into `CustomError` and `NSError`.
3. Cast `Error` to `A`, then implicit type cast `Error` to `NSError` work.

Minimum code is here.

import Foundation

protocol MyCustomErrorProtocol {
    var hoge: Int { get }
}

struct MyCustomError: Error, MyCustomErrorProtocol {
    var hoge: Int {
        return 1
    }
}

extension NSError: MyCustomErrorProtocol {
    var hoge: Int {
        return 0
    }
}

let error: Error = MyCustomError()

if let cError = error as? MyCustomErrorProtocol {
    cError.hoge // 0 (If Swift 3.0 then 1)
}
@belkadan
Copy link
Contributor

Ooh, that's tricky. @DougGregor, @jckarter?

@swift-ci
Copy link
Collaborator Author

Comment by Nobuo Saito (JIRA)

Hi, I think this issue was fixed on Swift 4.0.3/Xcode9.2
It was my misunderstanding.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

2 participants