-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Previous ID | SR-8151 |
Radar | None |
Original Reporter | @hamishknight |
Type | Bug |
Environment
Apple Swift version 4.2-dev (LLVM 9d4565013d, Clang f12d22bf9f, Swift 6982d65)
Target: x86_64-apple-darwin17.6.0
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: ee8dafed896ec4393455a7ad1df822bc
relates to:
- SR-7405 Protocol compositions: improve composing diagnostics
Issue Description:
In SE-0156, the following rule is given:
To improve readability and reduce confusion, a class conforming to a typealias which contains a class type constraint does not implicitly inherit the class type: inheritance should stay explicit. Here are a few examples to remind what the current rules are and to make the previous sentence clearer:
The proposal does not change the rule which forbids using the protocol composition syntax in the inheritance clause:
protocol P1 {} protocol P2 {} class C {} class D : P1 & P2 {} // Compiler error class E : C & P1 {} // Compiler errorClass D in the previous example does not inherit a base class so it can be expressed using the inheritance/conformance syntax or through a typealias:
class D : P1, P2 {} // Valid typealias P12 = P1 & P2 class D : P12 {} // ValidClass E above inherits a base class. The inheritance must be explicitly declared in the inheritance clause and can't be implicitly derived from a typealias:
class E : C, P1 {} // Valid typealias CP1 = C & P1 class E : CP1 {} // Compiler error: class 'E' does not inherit from class 'C' class E : C, CP1 {} // Valid: the inheritance is explicitly declared
However this rule doesn't appear to match the current implementation. The following doesn't yield a compiler error, despite the proposal saying the inheritance must be spelled explicitly:
protocol P1 {}
protocol P2 {}
class C {}
typealias CP1 = C & P1
class E : CP1 {}
and the following doesn't compile, despite the proposal saying that it should:
protocol P1 {}
protocol P2 {}
class C {}
typealias CP1 = C & P1
class E : C, CP1 {} // error: Multiple inheritance from classes 'C' and 'C'