[Type checker] Introduce "contextual patterns".

Contextual pattern describes a particular pattern with enough
contextual information to determine its type. Use this to simplify
TypeChecker::typeCheckPattern()'s interface in a manner that will
admit request'ification.
This commit is contained in:
Doug Gregor
2020-01-03 14:42:35 -08:00
parent 9c8351b206
commit 033f9c7927
7 changed files with 149 additions and 31 deletions

View File

@@ -2159,9 +2159,9 @@ namespace {
case PatternKind::Typed: {
// FIXME: Need a better locator for a pattern as a base.
TypeResolutionOptions options(TypeResolverContext::InExpression);
options |= TypeResolutionFlags::AllowUnboundGenerics;
Type type = TypeChecker::typeCheckPattern(pattern, CurDC, options);
auto contextualPattern =
ContextualPattern::forRawPattern(pattern, CurDC);
Type type = TypeChecker::typeCheckPattern(contextualPattern);
Type openedType = CS.openUnboundGenericType(type, locator);
// For a typed pattern, simply return the opened type of the pattern.