@@ -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