You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
protocolP {}
classC {}
classD : C { }
classE : C { }
classF : D, P { }
lett: C & D & P = F() // Okay: F is a subclass of D and conforms to Pletu: D & P = t// Okay: D & P is equivalent to C & D & Pletv: 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.
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
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):
In reality, this code does not compile. The compiler error is the following:
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).
The text was updated successfully, but these errors were encountered: