Skip to content

Commit c237f09

Browse files
committed
[NFC] Sema: Have 'validateTypedPattern' encapsulate TypeResolution construction
1 parent 588603f commit c237f09

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -714,15 +714,19 @@ Pattern *TypeChecker::resolvePattern(Pattern *P, DeclContext *DC,
714714
return P;
715715
}
716716

717-
static Type validateTypedPattern(TypedPattern *TP, TypeResolution resolution) {
717+
static Type
718+
validateTypedPattern(TypedPattern *TP, DeclContext *dc,
719+
TypeResolutionOptions options,
720+
OpenUnboundGenericTypeFn unboundTyOpener,
721+
HandlePlaceholderTypeReprFn placeholderHandler) {
718722
if (TP->hasType()) {
719723
return TP->getType();
720724
}
721725

722726
// If the pattern declares an opaque type, and applies to a single
723727
// variable binding, then we can bind the opaque return type from the
724728
// property definition.
725-
auto &Context = resolution.getASTContext();
729+
auto &Context = dc->getASTContext();
726730
auto *Repr = TP->getTypeRepr();
727731
if (Repr && Repr->hasOpaque()) {
728732
auto named = dyn_cast<NamedPattern>(
@@ -747,7 +751,9 @@ static Type validateTypedPattern(TypedPattern *TP, TypeResolution resolution) {
747751
return named->getDecl()->getDeclContext()->mapTypeIntoContext(opaqueTy);
748752
}
749753

750-
auto ty = resolution.resolveType(Repr);
754+
auto ty = TypeResolution::forContextual(dc, options, unboundTyOpener,
755+
placeholderHandler)
756+
.resolveType(Repr);
751757
if (ty->hasError()) {
752758
return ErrorType::get(Context);
753759
}
@@ -828,10 +834,8 @@ Type PatternTypeRequest::evaluate(Evaluator &evaluator,
828834
// For now, just return the placeholder type.
829835
placeholderHandler = PlaceholderType::get;
830836
}
831-
return validateTypedPattern(
832-
cast<TypedPattern>(P),
833-
TypeResolution::forContextual(dc, options, unboundTyOpener,
834-
placeholderHandler));
837+
return validateTypedPattern(cast<TypedPattern>(P), dc, options,
838+
unboundTyOpener, placeholderHandler);
835839
}
836840

837841
// A wildcard or name pattern cannot appear by itself in a context
@@ -896,11 +900,12 @@ Type PatternTypeRequest::evaluate(Evaluator &evaluator,
896900
// For now, just return the placeholder type.
897901
placeholderHandler = PlaceholderType::get;
898902
}
899-
TypedPattern *TP = cast<TypedPattern>(somePat->getSubPattern());
900-
const auto type = validateTypedPattern(
901-
TP, TypeResolution::forContextual(dc, options, unboundTyOpener,
902-
placeholderHandler));
903-
if (type && !type->hasError()) {
903+
904+
const auto type =
905+
validateTypedPattern(cast<TypedPattern>(somePat->getSubPattern()), dc,
906+
options, unboundTyOpener, placeholderHandler);
907+
908+
if (!type->hasError()) {
904909
return OptionalType::get(type);
905910
}
906911
}
@@ -1085,9 +1090,8 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
10851090
TP->setType(type);
10861091
// If the pattern type has a placeholder, we need to resolve it here.
10871092
if (patternType->hasPlaceholder()) {
1088-
validateTypedPattern(
1089-
cast<TypedPattern>(TP),
1090-
TypeResolution::forContextual(dc, options, nullptr, nullptr));
1093+
validateTypedPattern(cast<TypedPattern>(TP), dc, options, nullptr,
1094+
nullptr);
10911095
}
10921096
} else {
10931097
diags.diagnose(P->getLoc(), diag::pattern_type_mismatch_context,

0 commit comments

Comments
 (0)