Skip to content

Commit 55fd879

Browse files
committed
[NFC] Lazily Construct ErrorTypes when PatternTypeRequest Fails
Doing this eagerly makes it more difficult to determine when something fails by observing the creation of ErrorTypes
1 parent cbd2916 commit 55fd879

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,12 @@ static Type validateTypedPattern(TypedPattern *TP, TypeResolution resolution) {
732732
Type TypeChecker::typeCheckPattern(ContextualPattern pattern) {
733733
DeclContext *dc = pattern.getDeclContext();
734734
ASTContext &ctx = dc->getASTContext();
735-
return evaluateOrDefault(
736-
ctx.evaluator, PatternTypeRequest{pattern}, ErrorType::get(ctx));
735+
if (auto type = evaluateOrDefault(ctx.evaluator, PatternTypeRequest{pattern},
736+
Type())) {
737+
return type;
738+
}
739+
740+
return ErrorType::get(ctx);
737741
}
738742

739743
/// Apply the contextual pattern's context to the type resolution options.

lib/Sema/TypeCheckType.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,8 @@ static Type diagnoseUnknownType(TypeResolution resolution,
12071207
return I->second;
12081208
}
12091209

1210-
diags.diagnose(L, diag::cannot_find_type_in_scope,
1211-
comp->getNameRef())
1212-
.highlight(R);
1210+
diags.diagnose(L, diag::cannot_find_type_in_scope, comp->getNameRef())
1211+
.highlight(R);
12131212

12141213
return ErrorType::get(ctx);
12151214
}

0 commit comments

Comments
 (0)