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-1283] RawRepresentable extension for Self:NSCoding breaks implicit RawRepresentable implementation for enums #43891

Open
swift-ci opened this issue Apr 21, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-1283
Radar None
Original Reporter josh (JIRA User)
Type Bug
Environment

Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)

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

md5: ebcb1594c186768ea99ccc914c314b25

Issue Description:

Copy + paste attached sample code into a Playground.

import Foundation

enum Status: Int {
    case Good
    case Bad
}

extension RawRepresentable where Self: NSCoding {
    init?(rawValue: NSData) {
        if let instance = NSKeyedUnarchiver.unarchiveObjectWithData(rawValue) as? Self {
            self = instance
        } else {
            return nil
        }
    }
    
    var rawValue: NSData {
        get {
            return NSKeyedArchiver.archivedDataWithRootObject(self)
        }
    }
}
@belkadan
Copy link
Contributor

Ah, cause we find an initializer named init(rawValue:), even though it doesn't match the constraints for this particular type. We should change this lookup to not search extensions, I guess. Can't remember if there's an easy way to do that.

@Dante-Broggi
Copy link
Contributor

Is this resolved, or no longer valid? If either, this should be closed.

@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 itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants