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-6561] Multiple Class Types in Protocol Composition not implemented #49111

Open
swift-ci opened this issue Dec 8, 2017 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Dec 8, 2017

Previous ID SR-6561
Radar None
Original Reporter mariomeili (JIRA User)
Type Bug
Environment

4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Xcode 9.2 (9C40b)
macOS 10.13.2

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

md5: 9b62f47869b75395aa0f3a6986c3c380

Issue Description:

According to the proposal SE-0156 (https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md), multiple class types in protocol compositions should be allowed, if:

  • Either, the class types are the same,

  • Or, one class type must be a subtype of the other class type.

However, the exact code example from the proposal differs from the proposal's defined behaviour. See the code below (the expected behaviour is commented behind every line):

protocol P {}
class C {}
class D : C { }
class E : C { }
class F : D, P { }
let t: C & D & P = F() // Okay: F is a subclass of D and conforms to P
let u: D & P = t       // Okay: D & P is equivalent to C & D & P
let v: C & D & P = u   // Okay: C & D & P is equivalent to D & P

In reality, this code does not compile. The compiler error is the following:

  • Protocol-constrained type cannot contain class 'D' because it already contains class 'C'.

My conclusion here is that the compiler does not allow multiple class types in one protocol composition.

A recently started discussion on the swift users mailing list confirms this behaviour of the compiler (https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20171204/006712.html).

@huonw
Copy link
Mannequin

huonw mannequin commented Jun 28, 2018

cc @slavapestov

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

No branches or pull requests

1 participant