@@ -714,15 +714,19 @@ Pattern *TypeChecker::resolvePattern(Pattern *P, DeclContext *DC,
714
714
return P;
715
715
}
716
716
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) {
718
722
if (TP->hasType ()) {
719
723
return TP->getType ();
720
724
}
721
725
722
726
// If the pattern declares an opaque type, and applies to a single
723
727
// variable binding, then we can bind the opaque return type from the
724
728
// property definition.
725
- auto &Context = resolution. getASTContext ();
729
+ auto &Context = dc-> getASTContext ();
726
730
auto *Repr = TP->getTypeRepr ();
727
731
if (Repr && Repr->hasOpaque ()) {
728
732
auto named = dyn_cast<NamedPattern>(
@@ -747,7 +751,9 @@ static Type validateTypedPattern(TypedPattern *TP, TypeResolution resolution) {
747
751
return named->getDecl ()->getDeclContext ()->mapTypeIntoContext (opaqueTy);
748
752
}
749
753
750
- auto ty = resolution.resolveType (Repr);
754
+ auto ty = TypeResolution::forContextual (dc, options, unboundTyOpener,
755
+ placeholderHandler)
756
+ .resolveType (Repr);
751
757
if (ty->hasError ()) {
752
758
return ErrorType::get (Context);
753
759
}
@@ -828,10 +834,8 @@ Type PatternTypeRequest::evaluate(Evaluator &evaluator,
828
834
// For now, just return the placeholder type.
829
835
placeholderHandler = PlaceholderType::get;
830
836
}
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);
835
839
}
836
840
837
841
// A wildcard or name pattern cannot appear by itself in a context
@@ -896,11 +900,12 @@ Type PatternTypeRequest::evaluate(Evaluator &evaluator,
896
900
// For now, just return the placeholder type.
897
901
placeholderHandler = PlaceholderType::get;
898
902
}
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 ()) {
904
909
return OptionalType::get (type);
905
910
}
906
911
}
@@ -1085,9 +1090,8 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
1085
1090
TP->setType (type);
1086
1091
// If the pattern type has a placeholder, we need to resolve it here.
1087
1092
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 );
1091
1095
}
1092
1096
} else {
1093
1097
diags.diagnose (P->getLoc (), diag::pattern_type_mismatch_context,
0 commit comments