Skip to content

[5.5][SILGen] Fix a crash when a wrapped property initial value has a re-abstractable type. #37982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/SILGen/SILGenConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,22 @@ void SILGenFunction::emitMemberInitializers(DeclContext *dc,
// abstraction level. To undo this, we use a converting
// initialization and rely on the peephole that optimizes
// out the redundant conversion.
auto loweredResultTy = getLoweredType(origType, substType);
auto loweredSubstTy = getLoweredType(substType);
SILType loweredResultTy;
SILType loweredSubstTy;

// A converting initialization isn't necessary if the member is
// a property wrapper. Though the initial value can have a
// reabstractable type, the result of the initialization is
// always the property wrapper type, which is never reabstractable.
bool needsConvertingInit = false;
auto *singleVar = varPattern->getSingleVar();
if (!(singleVar && singleVar->getOriginalWrappedProperty())) {
loweredResultTy = getLoweredType(origType, substType);
loweredSubstTy = getLoweredType(substType);
needsConvertingInit = loweredResultTy != loweredSubstTy;
}

if (loweredResultTy != loweredSubstTy) {
if (needsConvertingInit) {
Conversion conversion = Conversion::getSubstToOrig(
origType, substType,
loweredResultTy);
Expand Down
15 changes: 15 additions & 0 deletions test/SILGen/property_wrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -966,3 +966,18 @@ struct TestAutoclosureComposition {

// CHECK-LABEL: sil_vtable [serialized] TestMyWrapper
// CHECK: #TestMyWrapper.$useMyWrapper!getter

@propertyWrapper
struct AutoclosureWrapper<T> {
init(wrappedValue: @autoclosure () -> T) {
self.wrappedValue = wrappedValue()
}
var wrappedValue: T
}

struct TestReabstractableWrappedValue<T1> {
struct S<T2> { }

@AutoclosureWrapper var v: S<T1> = S()
init() where T1 == Int { }
}