mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user