Skip to content

Commit 71eb43a

Browse files
committed
[CSRanking] Handle mismatching curry levels
While it's currently not possible for `isDeclAsSpecializedAs` to compare decls that differ by having a curried self or having a parameter list, tweak the logic slightly so it could handle that case if it needed to. If one decl has a parameter list and the other doesn't, then just compare their self types. If one decl is curried and the other isn't, then add a curried self to the other and compare as normal.
1 parent b49f02c commit 71eb43a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,11 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
472472
Type type2 = decl2->getInterfaceType();
473473

474474
// Add curried 'self' types if necessary.
475-
if (!decl1->hasCurriedSelf()) {
475+
if (!decl1->hasCurriedSelf())
476476
type1 = type1->addCurriedSelfType(outerDC1);
477+
478+
if (!decl2->hasCurriedSelf())
477479
type2 = type2->addCurriedSelfType(outerDC2);
478-
}
479480

480481
// Construct a constraint system to compare the two declarations.
481482
ConstraintSystem cs(tc, dc, ConstraintSystemOptions());
@@ -594,14 +595,14 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
594595
}
595596

596597
bool fewerEffectiveParameters = false;
597-
if (!decl1->hasParameterList()) {
598-
// If the decl doesn't have a parameter list, simply check whether the
599-
// first type is a subtype of the second.
598+
if (!decl1->hasParameterList() && !decl2->hasParameterList()) {
599+
// If neither decl has a parameter list, simply check whether the first
600+
// type is a subtype of the second.
600601
cs.addConstraint(ConstraintKind::Subtype,
601602
openedType1,
602603
openedType2,
603604
locator);
604-
} else {
605+
} else if (decl1->hasParameterList() && decl2->hasParameterList()) {
605606
// Otherwise, check whether the first function type's input is a subtype
606607
// of the second type's inputs, i.e., can we forward the arguments?
607608
auto funcTy1 = openedType1->castTo<FunctionType>();

0 commit comments

Comments
 (0)