Skip to content

Commit 40750c0

Browse files
committed
[CS] Use different locators for nested 'wrappedValue' lookups
With the new way of caching overloads in the constraint system, we no longer allow different overloads to be resolved for the same locator in the same scope. Adjust the property wrapper logic so that it appends Member locator elements for nested lookups.
1 parent a97328d commit 40750c0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,26 +2603,25 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
26032603
if (cs) {
26042604
Type valueType = LValueType::get(initType);
26052605
auto dc = wrappedVar->getInnermostDeclContext();
2606-
auto emptyLocator = cs->getConstraintLocator(nullptr);
2606+
auto *loc = cs->getConstraintLocator(initializer);
26072607

26082608
for (unsigned i : indices(wrappedVar->getAttachedPropertyWrappers())) {
26092609
auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo(i);
26102610
if (!wrapperInfo)
26112611
break;
26122612

2613-
Type memberType =
2614-
cs->createTypeVariable(emptyLocator, TVO_CanBindToLValue);
2613+
loc = cs->getConstraintLocator(loc, ConstraintLocator::Member);
2614+
Type memberType = cs->createTypeVariable(loc, TVO_CanBindToLValue);
26152615
cs->addValueMemberConstraint(
26162616
valueType, wrapperInfo.valueVar->getFullName(),
2617-
memberType, dc, FunctionRefKind::Unapplied, { }, emptyLocator);
2617+
memberType, dc, FunctionRefKind::Unapplied, { }, loc);
26182618
valueType = memberType;
26192619
}
26202620

26212621
// Set up an equality constraint to drop the lvalue-ness of the value
26222622
// type we produced.
2623-
Type propertyType = cs->createTypeVariable(emptyLocator, 0);
2624-
cs->addConstraint(ConstraintKind::Equal, propertyType, valueType,
2625-
emptyLocator);
2623+
Type propertyType = cs->createTypeVariable(loc, 0);
2624+
cs->addConstraint(ConstraintKind::Equal, propertyType, valueType, loc);
26262625
return propertyType;
26272626
}
26282627

test/decl/var/property_wrappers.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ struct BadCombinations {
216216
}
217217

218218
struct MultipleWrappers {
219-
@Wrapper(stored: 17)
219+
// FIXME: The diagnostics here aren't great. The problem is that we're
220+
// attempting to splice a 'wrappedValue:' argument into the call to Wrapper's
221+
// init, but it doesn't have a matching init. We're then attempting to access
222+
// the nested 'wrappedValue', but Wrapper's 'wrappedValue' is Int.
223+
@Wrapper(stored: 17) // expected-error{{value of type 'Int' has no member 'wrappedValue'}}
220224
@WrapperWithInitialValue // expected-error{{extra argument 'wrappedValue' in call}}
221225
var x: Int = 17
222226

0 commit comments

Comments
 (0)