Skip to content

Commit 6c71b0c

Browse files
authored
Merge pull request swiftlang#37982 from hborla/5.5-reabstractable-wrapped-value
[5.5][SILGen] Fix a crash when a wrapped property initial value has a re-abstractable type.
2 parents eaa6f5e + f9afa5a commit 6c71b0c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,10 +1117,22 @@ void SILGenFunction::emitMemberInitializers(DeclContext *dc,
11171117
// abstraction level. To undo this, we use a converting
11181118
// initialization and rely on the peephole that optimizes
11191119
// out the redundant conversion.
1120-
auto loweredResultTy = getLoweredType(origType, substType);
1121-
auto loweredSubstTy = getLoweredType(substType);
1120+
SILType loweredResultTy;
1121+
SILType loweredSubstTy;
1122+
1123+
// A converting initialization isn't necessary if the member is
1124+
// a property wrapper. Though the initial value can have a
1125+
// reabstractable type, the result of the initialization is
1126+
// always the property wrapper type, which is never reabstractable.
1127+
bool needsConvertingInit = false;
1128+
auto *singleVar = varPattern->getSingleVar();
1129+
if (!(singleVar && singleVar->getOriginalWrappedProperty())) {
1130+
loweredResultTy = getLoweredType(origType, substType);
1131+
loweredSubstTy = getLoweredType(substType);
1132+
needsConvertingInit = loweredResultTy != loweredSubstTy;
1133+
}
11221134

1123-
if (loweredResultTy != loweredSubstTy) {
1135+
if (needsConvertingInit) {
11241136
Conversion conversion = Conversion::getSubstToOrig(
11251137
origType, substType,
11261138
loweredResultTy);

test/SILGen/property_wrappers.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,3 +966,18 @@ struct TestAutoclosureComposition {
966966

967967
// CHECK-LABEL: sil_vtable [serialized] TestMyWrapper
968968
// CHECK: #TestMyWrapper.$useMyWrapper!getter
969+
970+
@propertyWrapper
971+
struct AutoclosureWrapper<T> {
972+
init(wrappedValue: @autoclosure () -> T) {
973+
self.wrappedValue = wrappedValue()
974+
}
975+
var wrappedValue: T
976+
}
977+
978+
struct TestReabstractableWrappedValue<T1> {
979+
struct S<T2> { }
980+
981+
@AutoclosureWrapper var v: S<T1> = S()
982+
init() where T1 == Int { }
983+
}

0 commit comments

Comments
 (0)