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-8261] Generics don't identify Protocol with class requirement properly #50792

Closed
swift-ci opened this issue Jul 16, 2018 · 1 comment
Closed

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jul 16, 2018

Previous ID SR-8261
Radar None
Original Reporter drumnkyle (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.4.1 production on Swift 4.1.

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

md5: 58c4e0a8cae1656677208c2eb3fd58f4

duplicates:

  • SR-55 non-@objc protocol existentials do not conform to their own protocol type

Issue Description:

When you make a generic that requires that the generic type inherit from AnyObject (be a class), it is not satisfied if you use a protocol that is constrained to only class type. Here is example code.

class WeakReference<T: AnyObject> {
    private(set) weak var value: T?

    init(_ value: T?) {
        self.value = value
    }
}

public protocol TempoSetter: class {
    var currentTempo: Int { get set }
}

class ABC {
    var tempoSetters: Set<WeakReference<TempoSetter>> = []
    init() {}
}

Expected🙁

This compiles

Actual:

error: 'WeakReference' requires that 'TempoSetter' be a class type
    var tempoSetters: Set<WeakReference<TempoSetter>> = []
@belkadan
Copy link
Contributor

@belkadan belkadan commented Jul 16, 2018

This is unfortunately somewhat correct behavior, since a protocol value has to carry both the class reference and a pointer to the information about how the class implements the protocol. See SR-55 and its dups for more details.

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

No branches or pull requests

2 participants