Files
swift-mirror/test/SILGen/optional_to_optional.swift
Joe Groff c1fa06ea54 SILGen: Avoid useless bitcasts when IUO-to-Optional conversion happens.
In SIL, the distinction between IUO and Optional is now lowered away, so there's no reason to emit any SIL at all when an IUO is converted to Optional formally in the AST. (Eventually this distinction ought to go away at the type system level too…) Memory promotion didn't understand initializations through unchecked_*_casts and would incorrectly flag them as improper captures, causing rdar://problem/26899492.
2017-01-18 15:56:07 -08:00

33 lines
744 B
Swift

// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
protocol P {}
class Foo {
var x: Foo!
var p: P!
// CHECK-LABEL: {{.*3Foo.*3foo.*}}
// CHECK-NOT: unchecked_{{.*}}cast {{.*}} Optional{{.*}} to Optional
func foo() -> Foo? {
return x
}
// CHECK-LABEL: {{.*3Foo.*3poo.*}}
// CHECK-NOT: unchecked_{{.*}}cast {{.*}} Optional{{.*}} to Optional
func poo() -> P? {
return p
}
// CHECK-LABEL: {{.*3Foo.*3bar.*}}
// CHECK-NOT: unchecked_{{.*}}cast {{.*}} Optional{{.*}} to Optional
func bar() -> Foo? {
var x2 = x
}
// CHECK-LABEL: {{.*3Foo.*3par.*}}
// CHECK-NOT: unchecked_{{.*}}cast {{.*}} Optional{{.*}} to Optional
func par(p3: P) -> P? {
var p2 = p
p2! = p3
p2? = p3
}
}