Skip to content

Commit 592887c

Browse files
committed
[Type checker] Fix multi-file crasher for property wrapper backing storage.
Fixes rdar://problem/51810057
1 parent 9a84d01 commit 592887c

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,11 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
17211721
Type storageInterfaceType = wrapperType;
17221722
Type storageType = dc->mapTypeIntoContext(storageInterfaceType);
17231723

1724+
if (!var->hasInterfaceType()) {
1725+
auto &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
1726+
tc.validateDecl(var);
1727+
}
1728+
17241729
// Make sure that the property type matches the value of the
17251730
// wrapper type.
17261731
if (!storageInterfaceType->hasError()) {
@@ -1771,9 +1776,6 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
17711776
if (parentPBD->isInitialized(patternNumber) &&
17721777
!parentPBD->isInitializerChecked(patternNumber)) {
17731778
auto &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
1774-
if (!var->hasType())
1775-
tc.validateDecl(var);
1776-
17771779
tc.typeCheckPatternBinding(parentPBD, patternNumber);
17781780
}
17791781

test/multifile/Inputs/sr10933a.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@propertyWrapper
2+
class Wrapper<T> {
3+
private var _value: T
4+
5+
var wrappedValue: T {
6+
get { _value }
7+
set { _value = newValue }
8+
}
9+
10+
init(defaultValue: T) {
11+
self._value = defaultValue
12+
}
13+
14+
}

test/multifile/Inputs/sr10933b.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@propertyWrapper
2+
final class IntWrapper: Wrapper<Int> {
3+
override var value: Int {
4+
get { super.value }
5+
set { super.value = newValue }
6+
}
7+
}
8+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/sr10933a.swift %S/Inputs/sr10933b.swift
2+
3+
// SR-10933: crash involving multiple files
4+
class Holder {
5+
@IntWrapper(defaultValue: 100) var int: Int
6+
}
7+
8+
func main() {
9+
let h = Holder()
10+
}

0 commit comments

Comments
 (0)