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-7068] Casting concrete class to protocol with type constraint triggers runtime exception #49616

Closed
swift-ci opened this issue Feb 23, 2018 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

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

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

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

md5: 820a2bceac80da79f61ab0926f8a97cf

duplicates:

  • SR-6816 Let protocols inherit from class types

relates to:

  • SR-6816 Let protocols inherit from class types

Issue Description:

import Foundation

protocol SomeProtocol where Self: NSObject {
    func doSomething()
}
class SomeClass: NSObject, SomeProtocol {
    func doSomething() {
        print("did something!")
    }
}

let originalObject = SomeClass()
originalObject.doSomething()

let protocolCast: SomeProtocol = originalObject
protocolCast.doSomething()

The first call to doSomething() works but the second call will crash. Code compiles without error but throws a unrecognized selector exception at runtime. Removing the where clause on the protocol or adding @objc to the protocol fixes the issue.

@hamishknight
Copy link
Collaborator

Looks like a dupe of https://bugs.swift.org/browse/SR-6816

@belkadan
Copy link
Contributor

Probably yes.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

3 participants