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-10031] Constraints involving a Class & Protocol constraint don't type check correctly #52434

Closed
tjw opened this issue Mar 1, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@tjw
Copy link
Contributor

tjw commented Mar 1, 2019

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

Xcode 10.2b3

macOS 10.14.3

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

md5: 1806abf12b1c5a5c1e2a1eb6d9bd8796

duplicates:

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

Issue Description:

protocol P {}
func f<C: Collection>(objects: C) where C.Element : NSObject & P {}
let objects: [NSObject & P] = []
_ = f(objects: objects)

results in:

class-and-protocol-constraint.swift:24:5: error: global function 'f(objects:)' requires that 'NSObject' conform to 'P'
_ = f(objects: objects)
    ^
class-and-protocol-constraint.swift:21:6: note: where 'C.Element' = 'NSObject'
func f<C: Collection>(objects: C) where C.Element : NSObject & P {}
     ^

This also fails in Xcode 10.1, but with a different and stranger error message.

@belkadan
Copy link
Contributor

belkadan commented Mar 4, 2019

This is correct behavior; the elements of the collection are not a particular concrete type conforming to P, which means static and initializer requirements of P are not available.

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

No branches or pull requests

2 participants