Skip to content

Commit 63d63d8

Browse files
committed
[CS] Bail from conjunction for non-zero SK_Hole
Previously we would only do this for `SK_Fix`, do the same for `SK_Hole` since otherwise the score clearing logic for the conjunction could result in losing the hole score.
1 parent be1f82e commit 63d63d8

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/Sema/CSStep.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -887,23 +887,24 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
887887
if (Solutions.size() > 1)
888888
filterSolutions(Solutions, /*minimize=*/true);
889889

890-
// In diagnostic mode we need to stop a conjunction
891-
// but consider it successful if there are:
890+
// In diagnostic mode we need to stop a conjunction but consider it
891+
// successful if there are:
892892
//
893-
// - More than one solution for this element. Ambiguity
894-
// needs to get propagated back to the outer context
895-
// to be diagnosed.
896-
// - A single solution that requires one or more fixes,
897-
// continuing would result in more errors associated
898-
// with the failed element.
893+
// - More than one solution for this element. Ambiguity needs to get
894+
// propagated back to the outer context to be diagnosed.
895+
// - A single solution that requires one or more fixes or holes, since
896+
// continuing would result in more errors associated with the failed
897+
// element, and we don't preserve scores across elements.
899898
if (CS.shouldAttemptFixes()) {
900899
if (Solutions.size() > 1)
901900
Producer.markExhausted();
902901

903902
if (Solutions.size() == 1) {
904903
auto score = Solutions.front().getFixedScore();
905-
if (score.Data[SK_Fix] > 0 && !CS.isForCodeCompletion())
906-
Producer.markExhausted();
904+
if (!CS.isForCodeCompletion()) {
905+
if (score.Data[SK_Fix] > 0 || score.Data[SK_Hole] > 0)
906+
Producer.markExhausted();
907+
}
907908
}
908909
} else if (Solutions.size() != 1) {
909910
return failConjunction();
@@ -1053,7 +1054,7 @@ void ConjunctionStep::SolverSnapshot::replaySolution(const Solution &solution) {
10531054

10541055
// If inference succeeded, we are done.
10551056
auto score = solution.getFixedScore();
1056-
if (score.Data[SK_Fix] == 0)
1057+
if (score.Data[SK_Fix] == 0 && score.Data[SK_Hole] == 0)
10571058
return;
10581059

10591060
// If this conjunction represents a closure and inference
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","signature":"(anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*)","signatureAssert":"Assertion failed: (Ptr && \"Cannot dereference a null Type!\"), function operator->"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
func a {
44
{
55
\ b() a

0 commit comments

Comments
 (0)