Skip to content

Commit 516e616

Browse files
authored
Merge pull request #63149 from Vespen/fix-non-api-wrapper-parameter
[Sema] Fix for non-API level property wrappers with closure.
2 parents b1707ef + 73922d3 commit 516e616

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ namespace {
10871087
locator);
10881088

10891089
auto *const calleeParamDecl = calleeParamList->get(idx);
1090-
if (calleeParamDecl->hasAttachedPropertyWrapper()) {
1090+
if (calleeParamDecl->hasExternalPropertyWrapper()) {
10911091
// Rewrite the parameter ref to the backing wrapper initialization
10921092
// expression.
10931093
auto &appliedWrapper = appliedPropertyWrappers[appliedWrapperIndex++];

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,7 +4771,6 @@ ConstraintSystem::applyPropertyWrapperToParameter(
47714771
return getTypeMatchSuccess();
47724772
}
47734773

4774-
PropertyWrapperInitKind initKind;
47754774
if (argLabel.hasDollarPrefix()) {
47764775
Type projectionType = computeProjectedValueType(param, wrapperType);
47774776
addConstraint(matchKind, paramType, projectionType, locator);
@@ -4782,15 +4781,17 @@ ConstraintSystem::applyPropertyWrapperToParameter(
47824781
setType(param->getPropertyWrapperProjectionVar(), projectionType);
47834782
}
47844783

4785-
initKind = PropertyWrapperInitKind::ProjectedValue;
4786-
} else {
4784+
appliedPropertyWrappers[anchor].push_back({ wrapperType, PropertyWrapperInitKind::ProjectedValue });
4785+
} else if (param->hasExternalPropertyWrapper()) {
47874786
Type wrappedValueType = computeWrappedValueType(param, wrapperType);
47884787
addConstraint(matchKind, paramType, wrappedValueType, locator);
4789-
initKind = PropertyWrapperInitKind::WrappedValue;
47904788
setType(param->getPropertyWrapperWrappedValueVar(), wrappedValueType);
4789+
4790+
appliedPropertyWrappers[anchor].push_back({ wrapperType, PropertyWrapperInitKind::WrappedValue });
4791+
} else {
4792+
return getTypeMatchFailure(locator);
47914793
}
47924794

4793-
appliedPropertyWrappers[anchor].push_back({ wrapperType, initKind });
47944795
return getTypeMatchSuccess();
47954796
}
47964797

test/Sema/property_wrapper_parameter.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ struct Wrapper<T> {
2121
}
2222
}
2323

24+
@propertyWrapper
25+
struct ImplementationDetailWrapper<T> {
26+
var wrappedValue: T
27+
28+
init(wrappedValue: T) {
29+
self.wrappedValue = wrappedValue
30+
}
31+
}
32+
2433
func globalFunc(@Wrapper arg: Int) {
2534
let _: Int = arg
2635
let _: Projection<Int> = $arg
@@ -36,6 +45,17 @@ func testGlobalFunc(value: Int, projection: Projection<Int>) {
3645
let _: (Projection<Int>) -> Void = globalFunc($arg:)
3746
}
3847

48+
func globalFuncWithImplementationDetailWrapper(@ImplementationDetailWrapper arg: Int) {
49+
let _: Int = arg
50+
let _: ImplementationDetailWrapper<Int> = _arg
51+
}
52+
53+
func testGlobalFuncWithImplementationDetailWrapper(value: Int) {
54+
globalFuncWithImplementationDetailWrapper(arg: value)
55+
56+
let _: (Int) -> Void = globalFuncWithImplementationDetailWrapper
57+
let _: (Int) -> Void = globalFuncWithImplementationDetailWrapper(arg:)
58+
}
3959

4060
struct S<Value> {
4161
func method(@Wrapper arg: Value) {
@@ -44,11 +64,21 @@ struct S<Value> {
4464
let _: Wrapper<Value> = _arg
4565
}
4666

67+
func methodWithImplementationDetailWrapper(@ImplementationDetailWrapper arg: Value) {
68+
let _: Value = arg
69+
let _: ImplementationDetailWrapper<Value> = _arg
70+
}
71+
4772
static func staticMethod(@Wrapper arg: Value) {
4873
let _: Value = arg
4974
let _: Projection<Value> = $arg
5075
let _: Wrapper<Value> = _arg
5176
}
77+
78+
static func staticMethodWithImplementationDetailWrapper(@ImplementationDetailWrapper arg: Value) {
79+
let _: Value = arg
80+
let _: ImplementationDetailWrapper<Value> = _arg
81+
}
5282
}
5383

5484
func testMethods(instance: S<String>, Metatype: S<String>.Type,
@@ -76,6 +106,22 @@ func testMethods(instance: S<String>, Metatype: S<String>.Type,
76106
let _: (S) -> (Projection<String>) -> Void = Metatype.method($arg:)
77107
}
78108

109+
func testMethodsWithImplementationDetailWrapper(instance: S<String>, Metatype: S<String>.Type,
110+
@ImplementationDetailWrapper value: String) {
111+
Metatype.staticMethodWithImplementationDetailWrapper(arg: value)
112+
113+
instance.methodWithImplementationDetailWrapper(arg: value)
114+
115+
let _: (String) -> Void = Metatype.staticMethodWithImplementationDetailWrapper
116+
let _: (String) -> Void = Metatype.staticMethodWithImplementationDetailWrapper(arg:)
117+
118+
let _: (String) -> Void = instance.methodWithImplementationDetailWrapper
119+
let _: (String) -> Void = instance.methodWithImplementationDetailWrapper(arg:)
120+
121+
let _: (S) -> (String) -> Void = Metatype.methodWithImplementationDetailWrapper
122+
let _: (S) -> (String) -> Void = Metatype.methodWithImplementationDetailWrapper(arg:)
123+
}
124+
79125
func testClosures() {
80126
typealias PropertyWrapperTuple = (Wrapper<Int>, Int, Projection<Int>)
81127

@@ -88,6 +134,12 @@ func testClosures() {
88134
}
89135
}
90136

137+
func testClosuresWithImplementationDetailWrapper() {
138+
let _: (Int) -> (ImplementationDetailWrapper<Int>, Int) = { (@ImplementationDetailWrapper value) in
139+
(_value, value)
140+
}
141+
}
142+
91143
func projectionPlaceholder<T>(@Wrapper _ value: T) {}
92144

93145
func testOmittedProjectionLabel(value: Int) {

0 commit comments

Comments
 (0)