Sema: Let .foo patterns fall back to being ExprPatterns if they don't match an enum case.

This lets you match `case .foo` when `foo` resolves to any static member, instead of only a `case`, albeit without the exhaustiveness checking and subpattern capabilities of proper cases. While we're here, adjust the type system we set up for unresolved patterns embedded in expressions so that we give better signal in the error messages too.
This commit is contained in:
Joe Groff
2017-02-28 21:51:39 -08:00
parent 17da6b38de
commit fc16cb5dda
10 changed files with 123 additions and 25 deletions

View File

@@ -3495,11 +3495,13 @@ namespace {
Expr *visitUnresolvedPatternExpr(UnresolvedPatternExpr *expr) {
// If we end up here, we should have diagnosed somewhere else
// already.
if (!SuppressDiagnostics) {
cs.TC.diagnose(expr->getLoc(), diag::pattern_in_expr,
Expr *simplified = simplifyExprType(expr);
if (!SuppressDiagnostics
&& !simplified->getType()->is<UnresolvedType>()) {
cs.TC.diagnose(simplified->getLoc(), diag::pattern_in_expr,
expr->getSubPattern()->getKind());
}
return expr;
return simplified;
}
Expr *visitBindOptionalExpr(BindOptionalExpr *expr) {