mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
*NOTE* DefiniteInit is still running /after/ ownership is stripped. This is just making sure that the code we are producing can actually pass the verifier. rdar://31521023
56 lines
888 B
Swift
56 lines
888 B
Swift
// RUN: %target-swift-frontend -emit-sil -enable-sil-ownership %s -o /dev/null
|
|
|
|
class SomeClass {}
|
|
|
|
// These are tests for values that are only initialized on some path through the
|
|
// CFG.
|
|
func partialInit() {
|
|
|
|
// Value of trivial type.
|
|
func trivial(ni : Int) {
|
|
var n = ni
|
|
while (n > 0) {
|
|
n -= 1
|
|
var x : Int
|
|
if (n > 2) { continue }
|
|
x = 1
|
|
_ = x
|
|
}
|
|
}
|
|
|
|
// Tuple with only some elements specified.
|
|
func trivial_tuple() {
|
|
var a : (Int, Int)
|
|
a.1 = 1
|
|
_ = a.1
|
|
}
|
|
|
|
|
|
func tuple_test(cond : Bool) {
|
|
var x : (SomeClass, SomeClass)
|
|
|
|
if cond {
|
|
x.0 = SomeClass()
|
|
} else {
|
|
x.1 = SomeClass()
|
|
_ = x.1
|
|
}
|
|
}
|
|
}
|
|
|
|
func tuple_test() -> Int {
|
|
var t : (Int, Int)
|
|
|
|
t.1 = 4
|
|
|
|
for _ in 0..<45 {
|
|
}
|
|
|
|
t.0 = 1
|
|
|
|
for _ in 0..<45 {
|
|
}
|
|
|
|
return t.1+t.0 // No diagnostic, everything is fully initialized.
|
|
}
|