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-8651] Protocol test on _SwiftValue returned from Obj-C doesn't work #51166

Closed
lilyball mannequin opened this issue Aug 27, 2018 · 3 comments
Closed

[SR-8651] Protocol test on _SwiftValue returned from Obj-C doesn't work #51166

lilyball mannequin opened this issue Aug 27, 2018 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Aug 27, 2018

Previous ID SR-8651
Radar None
Original Reporter @lilyball
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44)

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

md5: cc005abe69a65b2a9f6a9c3b53716373

duplicates:

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

Issue Description:

If I have a struct that conforms to a protocol and I pass it into Obj-C and get it back out again, I end up with a _SwiftValue stored in an Any. This by itself seems problematic, because it should only need the _SwiftValue wrapper when stored in an AnyObject, but casting back to the source type works. However, casting to a protocol breaks. If I first cast the value to AnyObject, then casting to a protocol works.

Example:

import Foundation

protocol Foo {
    func bar()
}

struct MyStruct: Foo {
    func bar() {}
}

let ary = NSMutableArray()
ary.add(MyStruct())
let x = ary.firstObject!
print(type(of: x)) // prints _SwiftValue
print(x is Foo) // prints false
print(x as AnyObject is Foo) // prints true
print((x as AnyObject) as Any is Foo) // prints false
@belkadan
Copy link
Contributor

:-(

@tbkka
Copy link
Contributor

tbkka commented Jan 29, 2020

Verifying: This seems to be fixed in master.

@tbkka
Copy link
Contributor

tbkka commented Jan 29, 2020

I can verify in Xcode 11.1, so it's been fixed since then.

@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

2 participants