Skip to content

[Property Wrappers] Use the outermost wrapper attribute type as the contextual type for property wrapper initialization #31002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,7 @@ void SolutionApplicationTarget::maybeApplyPropertyWrapper() {
// the initializer type later.
expression.wrappedVar = singleVar;
expression.expression = backingInitializer;
expression.convertType = outermostWrapperAttr->getTypeLoc();
}

SolutionApplicationTarget SolutionApplicationTarget::forInitialization(
Expand Down
15 changes: 15 additions & 0 deletions test/Constraints/requirement_failures_in_contextual_type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@ let _: A<Int>.C = 0
// expected-error@-1 {{'A<Int>.C' (aka 'Int') requires the types 'Int' and 'Int32' be equivalent}}
let _: A<Int>.B.E = 0
// expected-error@-1 {{'A<Int>.B' requires the types 'Int' and 'Int32' be equivalent}}


protocol P {}

@propertyWrapper
struct Wrapper<T: P> { // expected-note {{where 'T' = 'Int'}}
var wrappedValue: T
}

class C {
static let i = 1

@Wrapper // expected-error{{generic struct 'Wrapper' requires that 'Int' conform to 'P'}}
var value = C.i
}