mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Since the only user of `@_compilerInitialized` is distributed actors, I decided to make DI's diagnostics saying that such a var was not initialized a second-tier note. If there is some other var associated with the same Memory that is _not_ compiler initialized AND is also _not_ initialized, then we suppress the suggestion to initialize the @_compilerInitialized thing, because something else is problematic. Only when there are @_compilerInitialized things that are still not initialized, do we emit a note talking about that.
79 lines
1.7 KiB
Swift
79 lines
1.7 KiB
Swift
// RUN: %target-swift-frontend -emit-sil -verify %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.
|
|
}
|
|
|
|
class CheckCompilerInitAttr {
|
|
@_compilerInitialized let poster: Int
|
|
var whatever: Int // expected-note {{'self.whatever' not initialized}}
|
|
|
|
init(v1: Void) {
|
|
whatever = 0
|
|
poster = 10 // expected-error {{illegal assignment to '@_compilerInitialized' storage}}
|
|
}
|
|
|
|
// NB: this case is testing whether we only get a note for `whatever` and not `poster`
|
|
init(v2: Void) {} // expected-error {{return from initializer without initializing all stored properties}}
|
|
}
|
|
|
|
class AgainCheckCompilerInitAttr {
|
|
@_compilerInitialized let cleanup: Int // expected-note {{'self.cleanup' not initialized}}
|
|
var whenever: Int
|
|
|
|
// NB: this case ensures we still get a note for `cleanup` because no other properties are uninitialized
|
|
init() {
|
|
whenever = 0
|
|
} // expected-error {{return from initializer without initializing all stored properties}}
|
|
}
|