Skip to content

Commit 6a7878b

Browse files
committed
[CS] Perform limited exhaustiveness checking if we couldn't apply the solution
Currently ExprPatterns are type-checked during CSApply. As such, they can cause solution application to fail with a pattern that isn't well-formed. I'm planning on moving their type-checking into the solver, but until then, lets only do limited exhaustiveness checking for the switch if there was an error. rdar://105781521
1 parent e770bbe commit 6a7878b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,11 @@ class SyntacticElementSolutionApplication
17461746
}
17471747
}
17481748

1749+
// Note we perform a limited exhaustiveness check if we weren't able to
1750+
// apply the solution, as the subject and patterns may not be well-formed.
17491751
TypeChecker::checkSwitchExhaustiveness(
1750-
switchStmt, context.getAsDeclContext(), limitExhaustivityChecks);
1752+
switchStmt, context.getAsDeclContext(),
1753+
/*limited*/ limitExhaustivityChecks || hadError);
17511754

17521755
return switchStmt;
17531756
}

test/Constraints/rdar105781521.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// rdar://105781521
4+
enum MyEnum {
5+
case first(String)
6+
}
7+
8+
func takeClosure(_ x: () -> Void) {}
9+
10+
func test(value: MyEnum) {
11+
takeClosure {
12+
switch value {
13+
case .first(true):
14+
// expected-error@-1 {{expression pattern of type 'Bool' cannot match values of type 'String'}}
15+
// expected-note@-2 {{overloads for '~=' exist with these partially matching parameter lists: (Substring, String)}}
16+
break
17+
default:
18+
break
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)