Skip to content

Commit 7e07644

Browse files
committed
[CSRanking] Dynamic member look - rank keypath choice higher than string based one
Because keypath based choice provides more type information it should be preferred to string based when both solutions are available.
1 parent 71e8148 commit 7e07644

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,20 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
876876
continue;
877877
}
878878

879+
// Dynamic member lookup through a keypath is better than one using string
880+
// because it carries more type information.
881+
if (choice1.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup &&
882+
choice2.getKind() == OverloadChoiceKind::DynamicMemberLookup) {
883+
score1 += weight;
884+
continue;
885+
}
886+
887+
if (choice1.getKind() == OverloadChoiceKind::DynamicMemberLookup &&
888+
choice2.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
889+
score2 += weight;
890+
continue;
891+
}
892+
879893
continue;
880894
}
881895

0 commit comments

Comments
 (0)