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

@@ -2670,8 +2670,13 @@ namespace {
Type visitUnresolvedPatternExpr(UnresolvedPatternExpr *expr) {
// If there are UnresolvedPatterns floating around after name binding,
// they are pattern productions in invalid positions.
return ErrorType::get(CS.getASTContext());
// they are pattern productions in invalid positions. However, we will
// diagnose that condition elsewhere; to avoid unnecessary noise errors,
// just plop an open type variable here.
auto locator = CS.getConstraintLocator(expr);
auto typeVar = CS.createTypeVariable(locator, TVO_CanBindToLValue);
return typeVar;
}
/// Get the type T?