The above code should compile: The requirement on generic `T` is that is that it extends from `AnyObject`. Since protocol `Beta` also extends from `AnyObject` it holds that any class `Foo` that implements protocol `Beta` will also extend from `AnyObject`
Actual:
Code does not compile. Error message is error: "'Alpha' requires that 'Beta' be a class type"
Note: `class` and `AnyObject` are type-aliased to the same thing, so changing to `Beta: class` produces the same error
This is unfortunately correct behavior, because a protocol value isn't just a reference to the object; it also tracks information about how the type conforms to the protocol. See SR-55 and its dups for more discussion.
Attachment: Download
Environment
Swift compiler 4.2-RELEASE
Additional Detail from JIRA
md5: 7098f9a0a7e244cda268053f1aa1d117
duplicates:
Issue Description:
Expected:
Actual:
Note: `class` and `AnyObject` are type-aliased to the same thing, so changing to `Beta: class` produces the same error
Also, this works as expected:
The text was updated successfully, but these errors were encountered: