File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -2073,12 +2073,14 @@ namespace {
2073
2073
2074
2074
return resolveTypeReferenceInExpression (
2075
2075
closure->getExplicitResultTypeRepr (),
2076
- TypeResolverContext::InExpression, nullptr );
2076
+ TypeResolverContext::InExpression,
2077
+ // Introduce type variables for unbound generics.
2078
+ OpenUnboundGenericType (
2079
+ CS, CS.getConstraintLocator (closure,
2080
+ ConstraintLocator::ClosureResult)));
2077
2081
};
2078
2082
2079
2083
Type resultTy;
2080
- auto *resultLoc =
2081
- CS.getConstraintLocator (closure, ConstraintLocator::ClosureResult);
2082
2084
if (auto explicityTy = getExplicitResultType ()) {
2083
2085
resultTy = explicityTy;
2084
2086
} else {
@@ -2099,9 +2101,11 @@ namespace {
2099
2101
// If this is a multi-statement closure, let's mark result
2100
2102
// as potential hole right away.
2101
2103
resultTy = CS.createTypeVariable (
2102
- resultLoc,
2104
+ CS.getConstraintLocator (closure,
2105
+ ConstraintLocator::ClosureResult),
2103
2106
shouldTypeCheckInEnclosingExpression (closure)
2104
- ? 0 : TVO_CanBindToHole);
2107
+ ? 0
2108
+ : TVO_CanBindToHole);
2105
2109
}
2106
2110
}
2107
2111
Original file line number Diff line number Diff line change @@ -1030,3 +1030,15 @@ func sr12815() {
1030
1030
. doesntExist2 ( ) { $0 }
1031
1031
}
1032
1032
}
1033
+
1034
+ // Make sure we can infer generic arguments in an explicit result type.
1035
+ let explicitUnboundResult1 = { ( ) -> Array in [ 0 ] }
1036
+ let explicitUnboundResult2 : ( Array < Bool > ) -> Array < Int > = {
1037
+ ( arr: Array ) -> Array in [ 0 ]
1038
+ }
1039
+ // FIXME: Should we prioritize the contextual result type and infer Array<Int>
1040
+ // rather than using a type variable in these cases?
1041
+ // expected-error@+1 {{unable to infer closure type in the current context}}
1042
+ let explicitUnboundResult3 : ( Array < Bool > ) -> Array < Int > = {
1043
+ ( arr: Array ) -> Array in [ true ]
1044
+ }
You can’t perform that action at this time.
0 commit comments