Skip to content

Commit 2a2b5b0

Browse files
authored
Merge pull request #26254 from DougGregor/property-wrappers-sr11149-5.1
[5.1] [Type checker] Substitute into alternate properties when trying to fix property references
2 parents 26ae22b + cd70554 commit 2a2b5b0

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
@@ -2216,7 +2216,12 @@ class ConstraintSystem {
22162216
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload->Choice.getDecl())) {
22172217
if (decl->hasAttachedPropertyWrapper()) {
22182218
if (auto storageWrapper = decl->getPropertyWrapperStorageWrapper()) {
2219-
return std::make_pair(decl, storageWrapper->getType());
2219+
Type type = storageWrapper->getInterfaceType();
2220+
if (Type baseType = resolvedOverload->Choice.getBaseType()) {
2221+
type = baseType->getTypeOfMember(DC->getParentModule(),
2222+
storageWrapper, type);
2223+
}
2224+
return std::make_pair(decl, type);
22202225
}
22212226
}
22222227
}
@@ -2233,6 +2238,10 @@ class ConstraintSystem {
22332238
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload->Choice.getDecl())) {
22342239
if (decl->hasAttachedPropertyWrapper()) {
22352240
auto wrapperTy = decl->getPropertyWrapperBackingPropertyType();
2241+
if (Type baseType = resolvedOverload->Choice.getBaseType()) {
2242+
wrapperTy = baseType->getTypeOfMember(DC->getParentModule(),
2243+
decl, wrapperTy);
2244+
}
22362245
return std::make_pair(decl, wrapperTy);
22372246
}
22382247
}
@@ -2249,7 +2258,12 @@ class ConstraintSystem {
22492258
if (resolvedOverload->Choice.isDecl()) {
22502259
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload->Choice.getDecl())) {
22512260
if (auto wrapped = decl->getOriginalWrappedProperty()) {
2252-
return std::make_pair(decl, wrapped->getType());
2261+
Type type = wrapped->getInterfaceType();
2262+
if (Type baseType = resolvedOverload->Choice.getBaseType()) {
2263+
type = baseType->getTypeOfMember(DC->getParentModule(),
2264+
wrapped, type);
2265+
}
2266+
return std::make_pair(decl, type);
22532267
}
22542268
}
22552269
}
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)