Skip to content

Commit 8ee83fd

Browse files
roopDougGregor
authored andcommitted
[Property wrappers] Avoid assign_by_wrapper when autoclosure is involved
When assigning to a wrapped variable in 'init()', if the property wrapper's 'wrappedValue:' parameter is an escaping autoclosure, the initializer and setter have incompatible types -- the setter takes a value, and initializer takes a closure returning that value. An assign_by_wrapper with incompatible types causes SIL verification to fail. This commit makes the SIL not use assign_by_wrapper in such cases, and use the setter directly, resulting in a definitive initialization (DI) error instead. struct S { @lazy var n: Int // Lazy.init(wrappedValue: @autoclosure ... ) init() { n = 1 // error: 'self' used before all stored properties are initialized } }
1 parent 9c2dca7 commit 8ee83fd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,13 @@ namespace {
13211321
return false;
13221322
}
13231323

1324+
// If this property wrapper uses autoclosure in it's initializer,
1325+
// the argument types of the setter and initializer shall be
1326+
// different, so we don't rewrite an assignment into an
1327+
// initialization.
1328+
if (VD->isInnermostPropertyWrapperInitUsesEscapingAutoClosure())
1329+
return false;
1330+
13241331
return true;
13251332
}
13261333

0 commit comments

Comments
 (0)