Skip to content

[Type checker] Fix multi-file crasher for property wrapper backing storage #25743

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 2 commits into from
Jun 25, 2019
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
9 changes: 6 additions & 3 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,12 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
Type storageInterfaceType = wrapperType;
Type storageType = dc->mapTypeIntoContext(storageInterfaceType);

if (!var->hasInterfaceType()) {
auto &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
tc.validateDecl(var);
assert(var->hasInterfaceType());
}

// Make sure that the property type matches the value of the
// wrapper type.
if (!storageInterfaceType->hasError()) {
Expand Down Expand Up @@ -1771,9 +1777,6 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
if (parentPBD->isInitialized(patternNumber) &&
!parentPBD->isInitializerChecked(patternNumber)) {
auto &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
if (!var->hasType())
tc.validateDecl(var);

tc.typeCheckPatternBinding(parentPBD, patternNumber);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckPropertyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ PropertyWrapperTypeInfoRequest::evaluate(
.fixItReplace(valueVar->getNameLoc(), "wrappedValue");
}

if (!valueVar->hasInterfaceType())
static_cast<TypeChecker &>(*ctx.getLazyResolver()).validateDecl(valueVar);

PropertyWrapperTypeInfo result;
result.valueVar = valueVar;
result.initialValueInit = findInitialValueInit(ctx, nominal, valueVar);
Expand Down
14 changes: 14 additions & 0 deletions test/multifile/Inputs/sr10933a.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@propertyWrapper
class Wrapper<T> {
private var _value: T

var wrappedValue: T {
get { _value }
set { _value = newValue }
}

init(defaultValue: T) {
self._value = defaultValue
}

}
8 changes: 8 additions & 0 deletions test/multifile/Inputs/sr10933b.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@propertyWrapper
final class IntWrapper: Wrapper<Int> {
override var value: Int {
get { super.value }
set { super.value = newValue }
}
}

10 changes: 10 additions & 0 deletions test/multifile/property-wrappers-sr10933.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/sr10933a.swift %S/Inputs/sr10933b.swift

// SR-10933: crash involving multiple files
class Holder {
@IntWrapper(defaultValue: 100) var int: Int
}

func main() {
let h = Holder()
}