Skip to content

Commit 0b06834

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents f2f105e + 4eca7aa commit 0b06834

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,9 @@ namespace {
13841384
VarDecl *field = dyn_cast<VarDecl>(Storage);
13851385
VarDecl *backingVar = field->getPropertyWrapperBackingProperty();
13861386
assert(backingVar);
1387-
CanType ValType = backingVar->getType()->getCanonicalType();
1387+
CanType ValType =
1388+
SGF.F.mapTypeIntoContext(backingVar->getInterfaceType())
1389+
->getCanonicalType();
13881390
SILType varStorageType =
13891391
SGF.SGM.Types.getSubstitutedStorageType(backingVar, ValType);
13901392
auto typeData =
@@ -1407,7 +1409,7 @@ namespace {
14071409
assert(field->getAttachedPropertyWrappers().size() == 1);
14081410
auto wrapperInfo = field->getAttachedPropertyWrapperTypeInfo(0);
14091411
auto ctor = wrapperInfo.wrappedValueInit;
1410-
SubstitutionMap subs = backingVar->getType()->getMemberSubstitutionMap(
1412+
SubstitutionMap subs = ValType->getMemberSubstitutionMap(
14111413
SGF.getModule().getSwiftModule(), ctor);
14121414

14131415
Type ity = ctor->getInterfaceType();
@@ -1418,8 +1420,8 @@ namespace {
14181420
.asForeign(requiresForeignEntryPoint(ctor));
14191421
RValue initFuncRV =
14201422
SGF.emitApplyPropertyWrapperAllocator(loc, subs,initRef,
1421-
backingVar->getType(),
1422-
CanAnyFunctionType(substIty));
1423+
ValType,
1424+
CanAnyFunctionType(substIty));
14231425
ManagedValue initFn = std::move(initFuncRV).getAsSingleValue(SGF, loc);
14241426

14251427
// Create the allocating setter function. It captures the base address.

test/SILGen/property_wrappers.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,20 @@ public class Container {
447447
}
448448
}
449449

450+
// SR-11303 / rdar://problem/54311335 - crash due to wrong archetype used in generated SIL
451+
public protocol TestProtocol {}
452+
public class TestClass<T> {
453+
@WrapperWithInitialValue var value: T
454+
455+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers9TestClassC5value8protocolACyxGx_qd__tcAA0C8ProtocolRd__lufc
456+
// CHECK: metatype $@thin WrapperWithInitialValue<T>.Type
457+
// CHECK: function_ref @$s17property_wrappers23WrapperWithInitialValueV07wrappedF0ACyxGx_tcfCTc
458+
init<U: TestProtocol>(value: T, protocol: U) {
459+
self.value = value
460+
}
461+
}
462+
463+
450464
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
451465
// CHECK-NEXT: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter
452466
// CHECK-NEXT: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s17property_wrappers17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter

0 commit comments

Comments
 (0)