Skip to content

Commit df7735e

Browse files
committed
[Property Wrappers] Use the outermost wrapper attribute type as the
contextual type for property wrapper initialization
1 parent 829f258 commit df7735e

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
@@ -4219,6 +4219,7 @@ void SolutionApplicationTarget::maybeApplyPropertyWrapper() {
42194219
// the initializer type later.
42204220
expression.wrappedVar = singleVar;
42214221
expression.expression = backingInitializer;
4222+
expression.convertType = outermostWrapperAttr->getTypeLoc();
42224223
}
42234224

42244225
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)