@@ -2062,52 +2062,38 @@ namespace {
2062
2062
// parameter or return type is omitted, a fresh type variable is used to
2063
2063
// stand in for that parameter or return type, allowing it to be inferred
2064
2064
// from context.
2065
- auto getExplicitResultType = [&]() -> Type {
2066
- if (!closure->hasExplicitResultType ()) {
2067
- return Type ();
2068
- }
2065
+ Type resultTy = [&] {
2066
+ if (closure->hasExplicitResultType ()) {
2067
+ if (auto declaredTy = closure->getExplicitResultType ()) {
2068
+ return declaredTy;
2069
+ }
2069
2070
2070
- if (auto declaredTy = closure->getExplicitResultType ()) {
2071
- return declaredTy;
2071
+ const auto resolvedTy = resolveTypeReferenceInExpression (
2072
+ closure->getExplicitResultTypeRepr (),
2073
+ TypeResolverContext::InExpression,
2074
+ // Introduce type variables for unbound generics.
2075
+ OpenUnboundGenericType (
2076
+ CS, CS.getConstraintLocator (
2077
+ closure, ConstraintLocator::ClosureResult)));
2078
+ if (resolvedTy)
2079
+ return resolvedTy;
2072
2080
}
2073
2081
2074
- return resolveTypeReferenceInExpression (
2075
- closure->getExplicitResultTypeRepr (),
2076
- TypeResolverContext::InExpression,
2077
- // Introduce type variables for unbound generics.
2078
- OpenUnboundGenericType (
2079
- CS, CS.getConstraintLocator (closure,
2080
- ConstraintLocator::ClosureResult)));
2081
- };
2082
-
2083
- Type resultTy;
2084
- if (auto explicityTy = getExplicitResultType ()) {
2085
- resultTy = explicityTy;
2086
- } else {
2087
- auto getContextualResultType = [&]() -> Type {
2088
- if (auto contextualType = CS.getContextualType (closure)) {
2089
- if (auto fnType = contextualType->getAs <FunctionType>())
2090
- return fnType->getResult ();
2091
- }
2092
- return Type ();
2093
- };
2094
-
2095
- if (auto contextualResultTy = getContextualResultType ()) {
2096
- resultTy = contextualResultTy;
2097
- } else {
2098
- // If no return type was specified, create a fresh type
2099
- // variable for it and mark it as possible hole.
2100
- //
2101
- // If this is a multi-statement closure, let's mark result
2102
- // as potential hole right away.
2103
- resultTy = CS.createTypeVariable (
2104
- CS.getConstraintLocator (closure,
2105
- ConstraintLocator::ClosureResult),
2106
- shouldTypeCheckInEnclosingExpression (closure)
2107
- ? 0
2108
- : TVO_CanBindToHole);
2082
+ if (auto contextualType = CS.getContextualType (closure)) {
2083
+ if (auto fnType = contextualType->getAs <FunctionType>())
2084
+ return fnType->getResult ();
2109
2085
}
2110
- }
2086
+
2087
+ // If no return type was specified, create a fresh type
2088
+ // variable for it and mark it as possible hole.
2089
+ //
2090
+ // If this is a multi-statement closure, let's mark result
2091
+ // as potential hole right away.
2092
+ return Type (CS.createTypeVariable (
2093
+ CS.getConstraintLocator (closure, ConstraintLocator::ClosureResult),
2094
+ shouldTypeCheckInEnclosingExpression (closure) ? 0
2095
+ : TVO_CanBindToHole));
2096
+ }();
2111
2097
2112
2098
return FunctionType::get (closureParams, resultTy, extInfo);
2113
2099
}
0 commit comments