-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementation
Description
Previous ID | SR-10053 |
Radar | rdar://problem/48702830 |
Original Reporter | jbfit (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Duplicate |
Attachment: Download
Environment
Swift compiler 4.2-RELEASE
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, DiagnosticsQoI |
Assignee | None |
Priority | Medium |
md5: 7098f9a0a7e244cda268053f1aa1d117
duplicates:
Issue Description:
class Alpha<T> where T: AnyObject {
private let value: T
init(_ value: T) {
self.value = value
}
}
protocol Beta: AnyObject {}
class Gamma: Beta {}
print(Alpha<Beta>(Gamma()))
Expected:
- 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
Also, this works as expected:
class Alpha<T> where T: AnyObject {
private let value: T
init(_ value: T) {
self.value = value
}
}
class Beta {}
class Gamma: Beta {}
print(Alpha<AnyObject>(Gamma()))
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementation