-
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.
Description
| Previous ID | SR-12486 |
| Radar | rdar://problem/62201613 |
| Original Reporter | @lilyball |
| Type | Bug |
| Status | Resolved |
| Resolution | Done |
Environment
Swift 5.1.5, Swift 5.2
Additional Detail from JIRA
| Votes | 0 |
| Component/s | |
| Labels | Bug |
| Assignee | @tbkka |
| Priority | Medium |
md5: 868c763c40543f8ea25aec14dbda84d3
Issue Description:
I have some generic code that, in an attempt to check if the generic type is literally Any, evaluates Value.self is Any.Protocol. This used to work correctly up through Swift 5.0.3. Testing in Swift 5.1.5, this code now always evaluates to true, which is a surprise. Testing in Swift 5.2, this code not only evaluates to true, but triggers a compiler warning that erroneously claims it will always evaluate to false.
func isAny<Value>(_ type: Value.Type) -> Bool {
return Value.self is Any.Protocol
}
print(isAny(Int.self))
print(isAny(Any.self))
print(isAny(Any?.self))false
true
false
true
true
true
unnamed.swift:2:21: warning: cast from 'Value.Type' to unrelated type 'Any.Protocol' always fails
return Value.self is Any.Protocol
~~~~~~~~~~ ^ ~~~~~~~~~~~~
true
true
true
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.