Skip to content

Commit 16b6eb0

Browse files
authored
Merge pull request #25743 from DougGregor/property-wrappers-sr-10984
2 parents 9a84d01 + 7d0357c commit 16b6eb0

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,12 @@ 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+
assert(var->hasInterfaceType());
1728+
}
1729+
17241730
// Make sure that the property type matches the value of the
17251731
// wrapper type.
17261732
if (!storageInterfaceType->hasError()) {
@@ -1771,9 +1777,6 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
17711777
if (parentPBD->isInitialized(patternNumber) &&
17721778
!parentPBD->isInitializerChecked(patternNumber)) {
17731779
auto &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
1774-
if (!var->hasType())
1775-
tc.validateDecl(var);
1776-
17771780
tc.typeCheckPatternBinding(parentPBD, patternNumber);
17781781
}
17791782

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ PropertyWrapperTypeInfoRequest::evaluate(
265265
.fixItReplace(valueVar->getNameLoc(), "wrappedValue");
266266
}
267267

268+
if (!valueVar->hasInterfaceType())
269+
static_cast<TypeChecker &>(*ctx.getLazyResolver()).validateDecl(valueVar);
270+
268271
PropertyWrapperTypeInfo result;
269272
result.valueVar = valueVar;
270273
result.initialValueInit = findInitialValueInit(ctx, nominal, valueVar);

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)