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-7432] Can't see through boxed _SwiftValue when casting from @objc Type #49975

Closed
tkrajacic opened this issue Apr 13, 2018 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself runtime The Swift Runtime

Comments

@tkrajacic
Copy link

Previous ID SR-7432
Radar rdar://problem/39415812
Original Reporter @tkrajacic
Type Bug
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Runtime
Assignee None
Priority Medium

md5: be79066c5a2ee131780c4b6bfd8678cb

Issue Description:

When conforming to an @objc protocol, the check using `is` can't get the original type information.

In the Playground, uncomment the @objc in front of the protocol and suddenly the check at the end doesn't pick up on the fact that the passed type is in fact a `User.Type`

import Foundation

//@objc(Exporter)
protocol Exporter: NSObjectProtocol {
var type: Any { get }
func export(item: Any)
}

struct User { var name: String }

final class UserExporter: NSObject, Exporter {
var type: Any { return User.self }
func export(item: Any) {
guard let u = item as? User else {
return print("That's not a user")
}
print("Got user: \(u.name)")
}
}

let user = User(name: "Kermit")
let exporter: Exporter = UserExporter()

if exporter.type is User.Type {
print("Correct exporter")
}
exporter.export(item: user)
@belkadan
Copy link
Contributor

@swift-ci create

@tkrajacic
Copy link
Author

Tested in Xcode 10 and Swift 4.2 and this problem still exists.

@tkrajacic
Copy link
Author

This problem is still present in Xcode 10.2 and Swift 5!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis
Copy link
Collaborator

Fixed by #33561 (test here).

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 itself runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

3 participants