Skip to content

Commit 5b55ea1

Browse files
committed
[CSGen] Use new UnresolvedMemberChainBase constraint
1 parent 497d42d commit 5b55ea1

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
10041004
// Don't allow a protocol type to get propagated from the base to the result
10051005
// type of a chain, Result should always be a concrete type which conforms
10061006
// to the protocol inferred for the base.
1007-
if (locator->isLastElement<LocatorPathElt::UnresolvedMemberChainResult>() &&
1008-
kind == AllowedBindingKind::Supertypes && type->is<ProtocolType>())
1007+
if (constraint->getKind() == ConstraintKind::UnresolvedMemberChainBase &&
1008+
kind == AllowedBindingKind::Subtypes && type->is<ProtocolType>())
10091009
return None;
10101010
}
10111011

@@ -1103,7 +1103,8 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
11031103

11041104
case ConstraintKind::Bind:
11051105
case ConstraintKind::BindParam:
1106-
case ConstraintKind::Equal: {
1106+
case ConstraintKind::Equal:
1107+
case ConstraintKind::UnresolvedMemberChainBase: {
11071108
EquivalentTo.insert({bindingTypeVar, constraint});
11081109
break;
11091110
}

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,8 +1446,8 @@ namespace {
14461446
// whole chain, and the type of the whole chain must be equal to the base.
14471447
CS.addConstraint(ConstraintKind::Conversion, memberTy, chainResultTy,
14481448
locator);
1449-
CS.addConstraint(ConstraintKind::Equal, chainBaseTy, chainResultTy,
1450-
locator);
1449+
CS.addConstraint(ConstraintKind::UnresolvedMemberChainBase, chainResultTy,
1450+
chainBaseTy, locator);
14511451

14521452
return chainResultTy;
14531453
}

test/expr/delayed-ident/member_chains.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ let _: ImplicitMembers = .implicit[optional: ()] // expected-error {{value of op
149149
let _: ImplicitMembers = .implicit[funcOptional: ()]() // expected-error {{value of optional type 'ImplicitMembers?' must be unwrapped to a value of type 'ImplicitMembers'}} expected-note {{coalesce using '??' to provide a default when the optional value contains 'nil'}} {{55-55= ?? <#default value#>}} expected-note {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{55-55=!}}
150150

151151
// FIXME: Improve these diagnostics (should probably offer unwrapping, as above)
152-
let _: ImplicitMembers = .implicit.anotherOptional?.another // expected-error{{type of expression is ambiguous without more context}}
153-
let _: ImplicitMembers = .implicit[optionalFunc: ()]?() // expected-error{{type of expression is ambiguous without more context}}
152+
let _: ImplicitMembers = .implicit.anotherOptional?.another // expected-error{{cannot convert value of type 'Optional<_>' to specified type 'ImplicitMembers'}}
153+
let _: ImplicitMembers = .implicit[optionalFunc: ()]?() // expected-error{{cannot convert value of type 'Optional<_>' to specified type 'ImplicitMembers'}}
154154

155155

156156
let _: ImplicitMembers = .other.implicit

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ TEST_F(SemaTest, TestComplexTransitiveProtocolInference) {
270270
// T2 <: T3, T2 <: T1, T3 == T1
271271
cs.addConstraint(ConstraintKind::Subtype, typeVar2, typeVar3, nilLocator);
272272
cs.addConstraint(ConstraintKind::Conversion, typeVar2, typeVar1, nilLocator);
273-
cs.addConstraint(ConstraintKind::Equal, typeVar3, typeVar1, nilLocator);
273+
cs.addConstraint(ConstraintKind::UnresolvedMemberChainBase, typeVar3,
274+
typeVar1, nilLocator);
274275
// T1 == T5, T <: T6
275276
cs.addConstraint(ConstraintKind::Equal, typeVar1, typeVar5, nilLocator);
276277
cs.addConstraint(ConstraintKind::Conversion, typeVar5, typeVar6, nilLocator);

0 commit comments

Comments
 (0)