mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Definite initialization] Avoid performing DI via nonmutating setters.
Nonmutating setters for properties with attached delegates inside value-semantic types cause SIL verifier errors. Avoid performing DI on them for now.
This commit is contained in:
48
test/SILOptimizer/di-property-delegates-errors.swift
Normal file
48
test/SILOptimizer/di-property-delegates-errors.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
// RUN: %target-swift-frontend -emit-sil -verify %s
|
||||
@propertyDelegate
|
||||
final class ClassWrapper<T> {
|
||||
var value: T {
|
||||
didSet {
|
||||
print(" .. set \(value)")
|
||||
}
|
||||
}
|
||||
|
||||
init(initialValue: T) {
|
||||
print(" .. init \(initialValue)")
|
||||
self.value = initialValue
|
||||
}
|
||||
|
||||
deinit {
|
||||
print(" .. deinit \(value)")
|
||||
}
|
||||
}
|
||||
|
||||
struct IntStructWithClassWrapper {
|
||||
@ClassWrapper var wrapped: Int
|
||||
|
||||
init() {
|
||||
wrapped = 42 // expected-error{{'self' used before all stored properties are initialized}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
} // expected-error{{return from initializer without initializing all stored properties}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
|
||||
init(conditional b: Bool) {
|
||||
if b {
|
||||
self.$wrapped = ClassWrapper(initialValue: 32)
|
||||
} else {
|
||||
wrapped = 42 // expected-error{{'self' used before all stored properties are initialized}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
}
|
||||
} // expected-error{{return from initializer without initializing all stored properties}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
|
||||
init(dynamic b: Bool) {
|
||||
if b {
|
||||
wrapped = 42 // expected-error{{'self' used before all stored properties are initialized}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
}
|
||||
wrapped = 27 // expected-error{{'self' used before all stored properties are initialized}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
} // expected-error{{return from initializer without initializing all stored properties}}
|
||||
// expected-note@-1{{'self.wrapped' not initialized}}
|
||||
}
|
||||
Reference in New Issue
Block a user