Skip to content

Commit 48b6bcd

Browse files
authored
Merge pull request #31002 from hborla/property-wrapper-contextual-type
[Property Wrappers] Use the outermost wrapper attribute type as the contextual type for property wrapper initialization
2 parents c4b6f89 + df7735e commit 48b6bcd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,6 +4242,7 @@ void SolutionApplicationTarget::maybeApplyPropertyWrapper() {
42424242
// the initializer type later.
42434243
expression.wrappedVar = singleVar;
42444244
expression.expression = backingInitializer;
4245+
expression.convertType = outermostWrapperAttr->getTypeLoc();
42454246
}
42464247

42474248
SolutionApplicationTarget SolutionApplicationTarget::forInitialization(

test/Constraints/requirement_failures_in_contextual_type.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ let _: A<Int>.C = 0
1919
// expected-error@-1 {{'A<Int>.C' (aka 'Int') requires the types 'Int' and 'Int32' be equivalent}}
2020
let _: A<Int>.B.E = 0
2121
// expected-error@-1 {{'A<Int>.B' requires the types 'Int' and 'Int32' be equivalent}}
22+
23+
24+
protocol P {}
25+
26+
@propertyWrapper
27+
struct Wrapper<T: P> { // expected-note {{where 'T' = 'Int'}}
28+
var wrappedValue: T
29+
}
30+
31+
class C {
32+
static let i = 1
33+
34+
@Wrapper // expected-error{{generic struct 'Wrapper' requires that 'Int' conform to 'P'}}
35+
var value = C.i
36+
}

0 commit comments

Comments
 (0)