Description
Previous ID | SR-8153 |
Radar | None |
Original Reporter | @hamishknight |
Type | Bug |
Status | Reopened |
Resolution |
Environment
Apple Swift version 3.1-dev (LLVM 9cb6a3ccee, Clang f38438fc01, Swift b5b79f8)
Target: x86_64-apple-macosx10.9
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, 4.0Regression, TypeChecker |
Assignee | None |
Priority | Medium |
md5: 8a66f8482ae9d01a49d646d0c08030b5
Issue Description:
In Swift 3.1, it was possible to inherit from a protocol composition containing AnyObject through a type alias:
protocol P {}
typealias X = protocol<P, AnyObject>
class C : X {} // okay
However in Swift 4, both the above example in Swift 3 mode and the equivalent Swift 4 spelling no longer compile (presumably due to the fact that AnyObject is no longer an actual protocol):
protocol P {}
typealias X = protocol<P, AnyObject>
class C : X {} // error: Inheritance from non-protocol, non-class type 'X' (aka 'P & AnyObject')
protocol P {}
typealias X = P & AnyObject
class C : X {} // error: Inheritance from non-protocol, non-class type 'X' (aka 'P & AnyObject')
I would argue that this is a useful feature to have – being able to have a list of protocol constraints in a typealias along with the requirement of being a class, and then being able to directly conform a class to this typealias.
Especially given the fact that this is legal:
class A {}
typealias X = A & AnyObject
class C : X {} // okay