mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
As an optimization, there is a fast-cast to non-final classes that just compares isa pointers. If the source of the cast is an Optional<class>, though, it's not allowed to "directly compare the isa-pointer"; because the source might be Optional.none, i.e. null. Add a check for nil when emitting the fast class cast. rdar://108614878
25 lines
395 B
Swift
25 lines
395 B
Swift
// RUN: %target-run-simple-swift | %FileCheck %s
|
|
// REQUIRES: executable_test
|
|
|
|
final class C {}
|
|
|
|
struct S {
|
|
@inline(never)
|
|
func g1<T>(_ componentType: T.Type) -> T? {
|
|
return nil
|
|
}
|
|
@inline(never)
|
|
func g2<T>(_ type: T.Type) -> T? {
|
|
g1(T.self) as? T
|
|
}
|
|
}
|
|
|
|
func run() -> C? {
|
|
var e = S()
|
|
let r = e.g2(C.self)
|
|
return r
|
|
}
|
|
|
|
// CHECK: nil
|
|
print(run())
|