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-6309] Could not cast value of type '_SwiftValue' to a protocol #48859

Closed
swift-ci opened this issue Nov 6, 2017 · 2 comments
Closed

[SR-6309] Could not cast value of type '_SwiftValue' to a protocol #48859

swift-ci opened this issue Nov 6, 2017 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 6, 2017

Previous ID SR-6309
Radar None
Original Reporter broadway_lamb (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.1 (9B55)
Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)

Target: x86_64-apple-macosx10.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 26d414d55a3bcfef503c6080d6743ae6

duplicates:

  • SR-3871 Protocol passing via objective-c / Any can't be cast back to protocol type

Issue Description:

Here is the code I'm trying to execute in a playground:

import Foundation

protocol P {}

struct S: P {
    let value: Int
}

let a: P = S(value: 13)

NotificationCenter.default
    .addObserver(forName: .init("foo"),
                 object: nil,
                 queue: nil) { note in
                    // CRASH
                    print(note.object as! P)
                 }

NotificationCenter.default.post(name: .init("foo"), object: a)

The program crashes when I'm trying to cast `note.object` to P. Seems like it has something to do with bridging to `id`, because when I just write:

let any: Any = a

print(any as! P)

everything is fine.

@tbkka
Copy link
Contributor

tbkka commented Jan 29, 2020

Verifying: I can reproduce the problem in Xcode 11.1, but not in Swift master

@hujunfeng
Copy link

I can still reproduce this crash in Xcode 11.4.1 playground.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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 crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants