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-14593] Wrong AnyClass conformance for @objc protocol #56945

Open
swift-ci opened this issue May 5, 2021 · 1 comment
Open

[SR-14593] Wrong AnyClass conformance for @objc protocol #56945

swift-ci opened this issue May 5, 2021 · 1 comment
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

swift-ci commented May 5, 2021

Previous ID SR-14593
Radar rdar://problem/77558632
Original Reporter fabi.ionut (JIRA User)
Type Bug
Environment

Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)

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

md5: e00f2ec0e30f3d674d9da15f87bdd086

Issue Description:

Marking a protocol with @objc will trick the compiler into thinking that using .self will yield an AnyClass type. The runtime through will determine otherwise and the usage will cause a crash.

i.e.

@objc protocol X {

var answerToEverything: Int { get }

{{}}}

let bundle = Bundle(for: X.self) -> ``Thread 1: EXC_BAD_ACCESS (code=1,..)

Removing the @objc, however, will result in the following compiler error:

Cannot convert value of type 'X.Protocol' to expected argument type 'AnyClass' (aka 'AnyObject.Type')

which actually gives us a hint into the problem: we're supposed to pass in AnyClass, not protocols, structs, enums or any other types.

I can't begin to assume how this should be fixed: by either not allowing the @objc protocol usage at compile time or by extending the API to allow protocols, structs, enums Types, but I am more than happy to listen to other opinions on this matter. Maybe this is more a feature than a bug.

Observation: making the non @objc protocol conform to either the deprecated class or AnyObject still does not make the compiler allow the usage.

@typesanitizer
Copy link

@swift-ci create

@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
Projects
None yet
Development

No branches or pull requests

2 participants