Files
swift-mirror/validation-test/IRGen/rdar108614878.swift
Nate Chandler 70cfa6a05c [IRGen] Check for nil in final class cast opt.
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
2023-05-03 18:39:08 -07:00

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())