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-3833] Properties typed NSSet <NSError *> * cannot be bridged to Set[Error] #46418

Open
swift-ci opened this issue Feb 2, 2017 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 3.0

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 2, 2017

Previous ID SR-3833
Radar None
Original Reporter LucOlivierDBLS (JIRA User)
Type Bug

Attachment: Download

Environment
  • Swift 3.0.2 (Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1) Target: x86_64-apple-macosx10.9)

  • Xcode 8.2.1 (8C1002)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression, ClangImporter
Assignee @belkadan
Priority Medium

md5: b6414ac169273e1fc32c595653db156e

Issue Description:

Our Objective-C codebase contains a class which has a property of type NSSet <NSSError *> *:

@property (copy, readonly) NSSet <NSError *> *errors;

This class is being used both in Objective-C and Swift.

In Swift 2.x, this property's type was bridged to the following:

Set [NSError]

In Swift 3.x, this property's type is bridged to the following:

Set [AnyHashable]

Notes

I've included a sample project (SetError.zip) demonstrating our use case. It's a simplified project demonstrating our use case.

You'll see that in the same class (Operation.h), we use both _NSArray <NSError > _ and NSSet <NSSError *> * variables and
only the NSArray one will get properly typed over the bridge (see MyCustomOperation.swift).

Workaround

You can extend the appropriate class and declare a new property that does the appropriate casting:

    open var nsErrors: Set<NSError> {
        return self.errors as? Set<NSError> ?? Set<NSError>()
    }

I need to cast my property to be of type Set<NSError> because I can't cast it to Set<Error>
From my understanding, NSError conforms to Hashable but not the Error Protocol.

@belkadan
Copy link
Contributor

belkadan commented Feb 2, 2017

Hm. As you say, NSError is bridged to Error, but Error isn't Hashable. Falling back to NSError is probably better than falling back to AnyHashable. @DougGregor, what do you think?

@DougGregor
Copy link
Member

Yes, falling back to `NSError` makes the most sense.

@belkadan
Copy link
Contributor

belkadan commented Feb 3, 2017

Okay, I'll get it to do that in Swift 4 mode. (Unfortunately it would be a source-breaking change for Swift 3 at this point.)

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

No branches or pull requests

4 participants