Details
-
Type:
Bug
-
Status: Resolved
-
Priority:
Medium
-
Resolution: Duplicate
-
Component/s: Compiler
-
Labels:
Description
- The following code gives different results depending on whether optimization is turned on:
protocol P { }
class C: P { }
struct S<T> {
init(val: T) {
print(type(of: val))
print(type(of: val) is AnyObject.Type)
}
}
_ = S<P>(val: C())
With an unoptimized build, it prints:
C
true
However, in an optimized build (release configuration in Xcode), it prints:
P
false
The optimization discrepancy is definitely a bug. I think the unoptimized output is the correct one — type(of:) should always return a concrete type, never a protocol … right?
(Apologies if this is a duplicate. I found it a difficult one to search for.)