Skip to content

Commit f1c6c1b

Browse files
committed
[Sema] Fix for non-API level property wrappers with closure.
[Sema] Added parameter tests for non-API-level wrappers. [Sema] Added solution for non-API level property wrappers with closure.
1 parent 721e3e9 commit f1c6c1b

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-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->hasAttachedPropertyWrapper() && 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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4768,7 +4768,6 @@ ConstraintSystem::applyPropertyWrapperToParameter(
47684768
return getTypeMatchSuccess();
47694769
}
47704770

4771-
PropertyWrapperInitKind initKind;
47724771
if (argLabel.hasDollarPrefix()) {
47734772
Type projectionType = computeProjectedValueType(param, wrapperType);
47744773
addConstraint(matchKind, paramType, projectionType, locator);
@@ -4779,15 +4778,15 @@ ConstraintSystem::applyPropertyWrapperToParameter(
47794778
setType(param->getPropertyWrapperProjectionVar(), projectionType);
47804779
}
47814780

4782-
initKind = PropertyWrapperInitKind::ProjectedValue;
4783-
} else {
4781+
appliedPropertyWrappers[anchor].push_back({ wrapperType, PropertyWrapperInitKind::ProjectedValue });
4782+
} else if (param->hasExternalPropertyWrapper()) {
47844783
Type wrappedValueType = computeWrappedValueType(param, wrapperType);
47854784
addConstraint(matchKind, paramType, wrappedValueType, locator);
4786-
initKind = PropertyWrapperInitKind::WrappedValue;
47874785
setType(param->getPropertyWrapperWrappedValueVar(), wrappedValueType);
4786+
4787+
appliedPropertyWrappers[anchor].push_back({ wrapperType, PropertyWrapperInitKind::WrappedValue });
47884788
}
47894789

4790-
appliedPropertyWrappers[anchor].push_back({ wrapperType, initKind });
47914790
return getTypeMatchSuccess();
47924791
}
47934792

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)