@@ -866,7 +866,7 @@ Type PatternTypeRequest::evaluate(Evaluator &evaluator,
866
866
// If we're type checking this pattern in a context that can provide type
867
867
// information, then the lack of type information is not an error.
868
868
if (options & TypeResolutionFlags::AllowUnspecifiedTypes)
869
- return Context. TheUnresolvedType ;
869
+ return PlaceholderType::get ( Context, P) ;
870
870
871
871
Context.Diags .diagnose (P->getLoc (), diag::cannot_infer_type_for_pattern);
872
872
if (auto named = dyn_cast<NamedPattern>(P)) {
@@ -946,7 +946,7 @@ Type PatternTypeRequest::evaluate(Evaluator &evaluator,
946
946
return ErrorType::get (Context);
947
947
}
948
948
949
- return Context. TheUnresolvedType ;
949
+ return PlaceholderType::get ( Context, P) ;
950
950
}
951
951
llvm_unreachable (" bad pattern kind!" );
952
952
}
@@ -1736,41 +1736,18 @@ Pattern *TypeChecker::coercePatternToType(
1736
1736
// / contextual type.
1737
1737
void TypeChecker::coerceParameterListToType (ParameterList *P,
1738
1738
AnyFunctionType *FN) {
1739
-
1740
- // Local function to check if the given type is valid e.g. doesn't have
1741
- // errors, type variables or unresolved types related to it.
1742
- auto isValidType = [](Type type) -> bool {
1743
- return !(type->hasError () || type->hasUnresolvedType ());
1744
- };
1745
-
1746
- // Local function to check whether type of given parameter
1747
- // should be coerced to a given contextual type or not.
1748
- auto shouldOverwriteParam = [&](ParamDecl *param) -> bool {
1749
- return !isValidType (param->getTypeInContext ());
1750
- };
1751
-
1752
- auto handleParameter = [&](ParamDecl *param, Type ty, bool forceMutable) {
1753
- if (forceMutable)
1754
- param->setSpecifier (ParamDecl::Specifier::InOut);
1755
-
1756
- // If contextual type is invalid and we have a valid argument type
1757
- // trying to coerce argument to contextual type would mean erasing
1758
- // valuable diagnostic information.
1759
- if (isValidType (ty) || shouldOverwriteParam (param)) {
1760
- param->setInterfaceType (ty->mapTypeOutOfContext ());
1761
- }
1762
- };
1763
-
1764
1739
// Coerce each parameter to the respective type.
1765
1740
ArrayRef<AnyFunctionType::Param> params = FN->getParams ();
1766
1741
for (unsigned i = 0 , e = P->size (); i != e; ++i) {
1767
1742
auto ¶m = P->get (i);
1768
1743
assert (param->getArgumentName ().empty () &&
1769
1744
" Closures cannot have API names" );
1770
-
1771
- handleParameter (param,
1772
- params[i].getParameterType (),
1773
- params[i].isInOut ());
1774
1745
assert (!param->isDefaultArgument () && " Closures cannot have default args" );
1746
+
1747
+ if (params[i].isInOut ())
1748
+ param->setSpecifier (ParamDecl::Specifier::InOut);
1749
+
1750
+ param->setInterfaceType (
1751
+ params[i].getParameterType ()->mapTypeOutOfContext ());
1775
1752
}
1776
1753
}
0 commit comments