Skip to content

Commit 4a85892

Browse files
authored
Merge pull request #25351 from DougGregor/property-wrappers-merge-modules
2 parents 7ff22f5 + f5ab62a commit 4a85892

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

lib/AST/Decl.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5444,9 +5444,6 @@ PropertyWrapperTypeInfo VarDecl::getAttachedPropertyWrapperTypeInfo() const {
54445444

54455445
Type VarDecl::getAttachedPropertyWrapperType() const {
54465446
auto &ctx = getASTContext();
5447-
if (!ctx.getLazyResolver())
5448-
return nullptr;
5449-
54505447
auto mutableThis = const_cast<VarDecl *>(this);
54515448
return evaluateOrDefault(ctx.evaluator,
54525449
AttachedPropertyWrapperTypeRequest{mutableThis},
@@ -5455,9 +5452,6 @@ Type VarDecl::getAttachedPropertyWrapperType() const {
54555452

54565453
Type VarDecl::getPropertyWrapperBackingPropertyType() const {
54575454
ASTContext &ctx = getASTContext();
5458-
if (!ctx.getLazyResolver())
5459-
return nullptr;
5460-
54615455
auto mutableThis = const_cast<VarDecl *>(this);
54625456
return evaluateOrDefault(
54635457
ctx.evaluator, PropertyWrapperBackingPropertyTypeRequest{mutableThis},
@@ -5467,9 +5461,6 @@ Type VarDecl::getPropertyWrapperBackingPropertyType() const {
54675461
PropertyWrapperBackingPropertyInfo
54685462
VarDecl::getPropertyWrapperBackingPropertyInfo() const {
54695463
auto &ctx = getASTContext();
5470-
if (!ctx.getLazyResolver())
5471-
return PropertyWrapperBackingPropertyInfo();
5472-
54735464
auto mutableThis = const_cast<VarDecl *>(this);
54745465
return evaluateOrDefault(
54755466
ctx.evaluator,

lib/AST/TypeCheckRequests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ void PropertyWrapperBackingPropertyTypeRequest::noteCycleStep(
648648
DiagnosticEngine &diags) const {
649649
std::get<0>(getStorage())->diagnose(diag::circular_reference_through);
650650
}
651+
651652
bool PropertyWrapperBackingPropertyInfoRequest::isCached() const {
652653
auto var = std::get<0>(getStorage());
653654
return !var->getAttrs().isEmpty();

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,15 @@ AttachedPropertyWrapperTypeRequest::evaluate(Evaluator &evaluator,
371371
if (!customAttr)
372372
return Type();
373373

374+
ASTContext &ctx = var->getASTContext();
375+
if (!ctx.getLazyResolver())
376+
return nullptr;
377+
374378
auto resolution =
375379
TypeResolution::forContextual(var->getDeclContext());
376380
TypeResolutionOptions options(TypeResolverContext::PatternBindingDecl);
377381
options |= TypeResolutionFlags::AllowUnboundGenerics;
378382

379-
ASTContext &ctx = var->getASTContext();
380383
auto &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
381384
if (tc.validateType(customAttr->getTypeLoc(), resolution, options))
382385
return ErrorType::get(ctx);
@@ -409,10 +412,13 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
409412
if (!binding)
410413
return Type();
411414

415+
ASTContext &ctx = var->getASTContext();
416+
if (!ctx.getLazyResolver())
417+
return Type();
418+
412419
// If there's an initializer of some sort, checking it will determine the
413420
// property wrapper type.
414421
unsigned index = binding->getPatternEntryIndexForVarDecl(var);
415-
ASTContext &ctx = var->getASTContext();
416422
TypeChecker &tc = *static_cast<TypeChecker *>(ctx.getLazyResolver());
417423
if (binding->isInitialized(index)) {
418424
tc.validateDecl(var);

test/Serialization/Inputs/def_property_wrappers.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,32 @@ public struct SomeWrapper<T> {
1010
public struct HasWrappers {
1111
@SomeWrapper public var x: Int = 17
1212
}
13+
14+
// SR-10844
15+
@_propertyWrapper
16+
class A<T: Equatable> {
17+
18+
private var _value: T
19+
20+
var value: T {
21+
get { _value }
22+
set { _value = newValue }
23+
}
24+
25+
init(initialValue: T) {
26+
_value = initialValue
27+
}
28+
}
29+
30+
@_propertyWrapper
31+
class B: A<Double> {
32+
override var value: Double {
33+
get { super.value }
34+
set { super.value = newValue }
35+
}
36+
}
37+
38+
class Holder {
39+
// @A var b = 10.0 // ok
40+
@B var b = 10.0 // crash in test target
41+
}

test/Serialization/property_wrappers.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_property_wrappers.swift
2+
// RUN: %empty-directory(%t-scratch)
3+
// RUN: %target-swift-frontend -emit-module -o %t-scratch/def_property_wrappers~partial.swiftmodule -primary-file %S/Inputs/def_property_wrappers.swift -module-name def_property_wrappers -enable-testing
4+
// RUN: %target-swift-frontend -merge-modules -emit-module -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -enable-testing %t-scratch/def_property_wrappers~partial.swiftmodule -module-name def_property_wrappers -o %t/def_property_wrappers.swiftmodule
35
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown
46

5-
import def_property_wrappers
7+
@testable import def_property_wrappers
8+
9+
// SR-10844
10+
func testSR10844() {
11+
let holder = Holder()
12+
holder.b = 100
13+
}
614

715
func useWrappers(hd: HasWrappers) {
816
// Access the original properties

0 commit comments

Comments
 (0)