Skip to content

Commit 2450a79

Browse files
authored
Merge pull request swiftlang#26253 from DougGregor/property-wrappers-sr11149
[Type checker] Substitute into alternate properties when trying to fix wrapped property references
2 parents 0ca9747 + e1b359b commit 2450a79

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

lib/Sema/ConstraintSystem.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,12 @@ class ConstraintSystem {
22662266
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload->Choice.getDecl())) {
22672267
if (decl->hasAttachedPropertyWrapper()) {
22682268
if (auto storageWrapper = decl->getPropertyWrapperStorageWrapper()) {
2269-
return std::make_pair(decl, storageWrapper->getType());
2269+
Type type = storageWrapper->getInterfaceType();
2270+
if (Type baseType = resolvedOverload->Choice.getBaseType()) {
2271+
type = baseType->getTypeOfMember(DC->getParentModule(),
2272+
storageWrapper, type);
2273+
}
2274+
return std::make_pair(decl, type);
22702275
}
22712276
}
22722277
}
@@ -2283,6 +2288,10 @@ class ConstraintSystem {
22832288
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload->Choice.getDecl())) {
22842289
if (decl->hasAttachedPropertyWrapper()) {
22852290
auto wrapperTy = decl->getPropertyWrapperBackingPropertyType();
2291+
if (Type baseType = resolvedOverload->Choice.getBaseType()) {
2292+
wrapperTy = baseType->getTypeOfMember(DC->getParentModule(),
2293+
decl, wrapperTy);
2294+
}
22862295
return std::make_pair(decl, wrapperTy);
22872296
}
22882297
}
@@ -2299,7 +2308,12 @@ class ConstraintSystem {
22992308
if (resolvedOverload->Choice.isDecl()) {
23002309
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload->Choice.getDecl())) {
23012310
if (auto wrapped = decl->getOriginalWrappedProperty()) {
2302-
return std::make_pair(decl, wrapped->getType());
2311+
Type type = wrapped->getInterfaceType();
2312+
if (Type baseType = resolvedOverload->Choice.getBaseType()) {
2313+
type = baseType->getTypeOfMember(DC->getParentModule(),
2314+
wrapped, type);
2315+
}
2316+
return std::make_pair(decl, type);
23032317
}
23042318
}
23052319
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
enum S<Value> {
3+
@propertyWrapper
4+
private struct A {
5+
var s:UInt = 0
6+
var wrappedValue:Value { didSet { } }
7+
8+
init(wrappedValue:Value) { self.wrappedValue = wrappedValue }
9+
}
10+
11+
@propertyWrapper
12+
final class B {
13+
@A
14+
var wrappedValue:Value
15+
16+
var projectedValue:S<Value>.B
17+
{
18+
self
19+
}
20+
21+
init(wrappedValue:Value)
22+
{
23+
self.wrappedValue = wrappedValue
24+
}
25+
}
26+
27+
@propertyWrapper
28+
struct O {
29+
private var s:UInt? = nil
30+
@B private(set) var wrappedValue:Value
31+
32+
var a:Bool
33+
{
34+
self.s.map{ $0 != self.$wrappedValue.wrappedValue.sequence } ?? true
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)