Skip to content

Commit 9cfbea3

Browse files
committed
Sema: Fix local property wrappers on constructor
Fixes rdar://problem/142443421.
1 parent dc21edd commit 9cfbea3

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

include/swift/Sema/ConstraintSystem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -5221,7 +5221,8 @@ class ConstraintSystem {
52215221
/// property wrapper type by applying the property wrapper.
52225222
TypeMatchResult applyPropertyWrapperToParameter(
52235223
Type wrapperType, Type paramType, ParamDecl *param, Identifier argLabel,
5224-
ConstraintKind matchKind, ConstraintLocatorBuilder locator);
5224+
ConstraintKind matchKind, ConstraintLocator *locator,
5225+
ConstraintLocator *calleeLocator);
52255226

52265227
/// Used by applyPropertyWrapperToParameter() to update appliedPropertyWrappers
52275228
/// and record a change in the trail.

lib/Sema/CSGen.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -5057,11 +5057,9 @@ void ConstraintSystem::removePropertyWrapper(Expr *anchor) {
50575057
ConstraintSystem::TypeMatchResult
50585058
ConstraintSystem::applyPropertyWrapperToParameter(
50595059
Type wrapperType, Type paramType, ParamDecl *param, Identifier argLabel,
5060-
ConstraintKind matchKind, ConstraintLocatorBuilder locator) {
5061-
Expr *anchor = getAsExpr(locator.getAnchor());
5062-
if (auto *apply = dyn_cast<ApplyExpr>(anchor)) {
5063-
anchor = apply->getFn();
5064-
}
5060+
ConstraintKind matchKind, ConstraintLocator *locator,
5061+
ConstraintLocator *calleeLocator) {
5062+
Expr *anchor = getAsExpr(calleeLocator->getAnchor());
50655063

50665064
if (argLabel.hasDollarPrefix() && (!param || !param->hasExternalPropertyWrapper())) {
50675065
if (!shouldAttemptFixes())

lib/Sema/CSSimplify.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,9 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
18201820
assert(param);
18211821
if (cs.applyPropertyWrapperToParameter(paramTy, argTy,
18221822
const_cast<ParamDecl *>(param),
1823-
argLabel, subKind, loc)
1823+
argLabel, subKind,
1824+
cs.getConstraintLocator(loc),
1825+
calleeLocator)
18241826
.isFailure()) {
18251827
return cs.getTypeMatchFailure(loc);
18261828
}
@@ -11920,6 +11922,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1192011922
auto result = applyPropertyWrapperToParameter(backingType, param.getParameterType(),
1192111923
paramDecl, paramDecl->getName(),
1192211924
ConstraintKind::Equal,
11925+
getConstraintLocator(closure),
1192311926
getConstraintLocator(closure));
1192411927
if (result.isFailure())
1192511928
return false;

lib/Sema/TypeOfReference.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -741,14 +741,15 @@ unwrapPropertyWrapperParameterTypes(ConstraintSystem &cs, AbstractFunctionDecl *
741741
continue;
742742
}
743743

744-
auto *wrappedType = cs.createTypeVariable(cs.getConstraintLocator(locator), 0);
744+
auto *loc = cs.getConstraintLocator(locator);
745+
auto *wrappedType = cs.createTypeVariable(loc, 0);
745746
auto paramType = paramTypes[i].getParameterType();
746747
auto paramLabel = paramTypes[i].getLabel();
747748
auto paramInternalLabel = paramTypes[i].getInternalLabel();
748749
adjustedParamTypes.push_back(AnyFunctionType::Param(
749750
wrappedType, paramLabel, ParameterTypeFlags(), paramInternalLabel));
750751
cs.applyPropertyWrapperToParameter(paramType, wrappedType, paramDecl, argLabel,
751-
ConstraintKind::Equal, locator);
752+
ConstraintKind::Equal, loc, loc);
752753
}
753754

754755
return FunctionType::get(adjustedParamTypes, functionType->getResult(),

test/Sema/property_wrapper_parameter.swift

+25
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,28 @@ func takesWrapperClosure<T>(_: ProjectionWrapper<[S<T>]>, closure: (ProjectionWr
189189
func testGenericPropertyWrapper<U>(@ProjectionWrapper wrappers: [S<U>]) {
190190
takesWrapperClosure($wrappers) { $wrapper in }
191191
}
192+
193+
@propertyWrapper
194+
struct Binding<Value> {
195+
var wrappedValue: Value
196+
197+
init(wrappedValue: Value) {
198+
self.wrappedValue = wrappedValue
199+
}
200+
201+
public var projectedValue: Binding<Value> {
202+
return self
203+
}
204+
205+
public init(projectedValue: Binding<Value>) {
206+
self = projectedValue
207+
}
208+
}
209+
210+
struct Widget {
211+
init(@ProjectionWrapper w: Int) {}
212+
}
213+
214+
func buildWidget(_ w: ProjectionWrapper<Int>) -> Widget {
215+
Widget($w: w)
216+
}

0 commit comments

Comments
 (0)