Skip to content

Commit f3bb3d9

Browse files
committed
Sema: Don't allow closure return type to contain noescape types
1 parent 663fa09 commit f3bb3d9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ namespace {
24042404
CS.getConstraintLocator(expr, ConstraintLocator::ClosureResult);
24052405

24062406
if (expr->hasEmptyBody()) {
2407-
resultTy = CS.createTypeVariable(locator, TVO_CanBindToNoEscape);
2407+
resultTy = CS.createTypeVariable(locator, 0);
24082408

24092409
// Closures with empty bodies should be inferred to return
24102410
// ().
@@ -2416,7 +2416,7 @@ namespace {
24162416
} else {
24172417
// If no return type was specified, create a fresh type
24182418
// variable for it.
2419-
resultTy = CS.createTypeVariable(locator, TVO_CanBindToNoEscape);
2419+
resultTy = CS.createTypeVariable(locator, 0);
24202420

24212421
if (closureHasNoResult(expr)) {
24222422
// Allow it to default to () if there are no return statements.

test/Constraints/closures.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,10 @@ do {
899899
}
900900
}
901901
}
902+
903+
// Don't allow result type of a closure to end up as a noescape type
904+
905+
// The funny error is because we infer the type of badResult as () -> ()
906+
// via the 'T -> U => T -> ()' implicit conversion.
907+
let badResult = { (fn: () -> ()) in fn }
908+
// expected-error@-1 {{expression resolves to an unused function}}

0 commit comments

Comments
 (0)