Skip to content

Commit c170443

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

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5148,7 +5148,8 @@ class ConstraintSystem {
51485148
/// property wrapper type by applying the property wrapper.
51495149
TypeMatchResult applyPropertyWrapperToParameter(
51505150
Type wrapperType, Type paramType, ParamDecl *param, Identifier argLabel,
5151-
ConstraintKind matchKind, ConstraintLocatorBuilder locator);
5151+
ConstraintKind matchKind, ConstraintLocator *locator,
5152+
ConstraintLocator *calleeLocator);
51525153

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

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,11 +4301,9 @@ void ConstraintSystem::removePropertyWrapper(Expr *anchor) {
43014301
ConstraintSystem::TypeMatchResult
43024302
ConstraintSystem::applyPropertyWrapperToParameter(
43034303
Type wrapperType, Type paramType, ParamDecl *param, Identifier argLabel,
4304-
ConstraintKind matchKind, ConstraintLocatorBuilder locator) {
4305-
Expr *anchor = getAsExpr(locator.getAnchor());
4306-
if (auto *apply = dyn_cast<ApplyExpr>(anchor)) {
4307-
anchor = apply->getFn();
4308-
}
4304+
ConstraintKind matchKind, ConstraintLocator *locator,
4305+
ConstraintLocator *calleeLocator) {
4306+
Expr *anchor = getAsExpr(calleeLocator->getAnchor());
43094307

43104308
auto recordPropertyWrapperFix = [&](ConstraintFix *fix) -> TypeMatchResult {
43114309
if (!shouldAttemptFixes())

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,9 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
18501850
assert(param);
18511851
if (cs.applyPropertyWrapperToParameter(paramTy, argTy,
18521852
const_cast<ParamDecl *>(param),
1853-
wrapperArgLabel, subKind, loc)
1853+
wrapperArgLabel, subKind,
1854+
cs.getConstraintLocator(loc),
1855+
calleeLocator)
18541856
.isFailure()) {
18551857
return cs.getTypeMatchFailure(loc);
18561858
}
@@ -11912,6 +11914,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1191211914
auto result = applyPropertyWrapperToParameter(backingType, param.getParameterType(),
1191311915
paramDecl, paramDecl->getName(),
1191411916
ConstraintKind::Equal,
11917+
getConstraintLocator(closure),
1191511918
getConstraintLocator(closure));
1191611919
if (result.isFailure())
1191711920
return false;

lib/Sema/TypeOfReference.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,15 @@ unwrapPropertyWrapperParameterTypes(ConstraintSystem &cs, AbstractFunctionDecl *
750750
continue;
751751
}
752752

753-
auto *wrappedType = cs.createTypeVariable(cs.getConstraintLocator(locator), 0);
753+
auto *loc = cs.getConstraintLocator(locator);
754+
auto *wrappedType = cs.createTypeVariable(loc, 0);
754755
auto paramType = paramTypes[i].getParameterType();
755756
auto paramLabel = paramTypes[i].getLabel();
756757
auto paramInternalLabel = paramTypes[i].getInternalLabel();
757758
adjustedParamTypes.push_back(AnyFunctionType::Param(
758759
wrappedType, paramLabel, ParameterTypeFlags(), paramInternalLabel));
759760
cs.applyPropertyWrapperToParameter(paramType, wrappedType, paramDecl, argLabel,
760-
ConstraintKind::Equal, locator);
761+
ConstraintKind::Equal, loc, loc);
761762
}
762763

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

test/Sema/property_wrapper_parameter.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,28 @@ func takesWrapperClosure<T>(_: ProjectionWrapper<[S<T>]>, closure: (ProjectionWr
223223
func testGenericPropertyWrapper<U>(@ProjectionWrapper wrappers: [S<U>]) {
224224
takesWrapperClosure($wrappers) { $wrapper in }
225225
}
226+
227+
@propertyWrapper
228+
struct Binding<Value> {
229+
var wrappedValue: Value
230+
231+
init(wrappedValue: Value) {
232+
self.wrappedValue = wrappedValue
233+
}
234+
235+
public var projectedValue: Binding<Value> {
236+
return self
237+
}
238+
239+
public init(projectedValue: Binding<Value>) {
240+
self = projectedValue
241+
}
242+
}
243+
244+
struct Widget {
245+
init(@ProjectionWrapper w: Int) {}
246+
}
247+
248+
func buildWidget(_ w: ProjectionWrapper<Int>) -> Widget {
249+
Widget($w: w)
250+
}

0 commit comments

Comments
 (0)