Skip to content

Commit bf25f8d

Browse files
authored
Merge pull request #7771 from jckarter/bogus-noescape-error
Sema: Don't raise bogus escape diagnostics about captures in closures with errors.
2 parents e14b948 + 43f841e commit bf25f8d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ class FindCapturedVars : public ASTWalker {
192192

193193
// If VD is a noescape decl, then the closure we're computing this for
194194
// must also be noescape.
195-
if (VD->hasInterfaceType() &&
195+
if (AFR.hasType() &&
196+
!AFR.getType()->hasError() &&
197+
VD->hasInterfaceType() &&
196198
VD->getInterfaceType()->is<AnyFunctionType>() &&
197199
VD->getInterfaceType()->castTo<AnyFunctionType>()->isNoEscape() &&
198200
!capture.isNoEscape() &&

test/Constraints/closures.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,8 @@ struct S<T> {
266266
// Make sure we cannot infer an () argument from an empty parameter list.
267267
func acceptNothingToInt (_: () -> Int) {}
268268
func testAcceptNothingToInt(ac1: @autoclosure () -> Int) {
269-
// expected-note@-1{{parameter 'ac1' is implicitly non-escaping because it was declared @autoclosure}}
270269
acceptNothingToInt({ac1($0)})
271270
// expected-error@-1{{contextual closure type '() -> Int' expects 0 arguments, but 1 was used in closure body}}
272-
// FIXME: expected-error@-2{{closure use of non-escaping parameter 'ac1' may allow it to escape}}
273271
}
274272

275273
// <rdar://problem/23570873> QoI: Poor error calling map without being able to infer "U" (closure result inference)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s
2+
3+
class C {}
4+
class D {}
5+
6+
func f1(f : (inout Int) -> ()) {}
7+
8+
func f2(f : (inout Any) -> ()) {
9+
// TODO: Error here is still pretty bad...
10+
f1 { f(&$0) } // expected-error{{conversion from 'Int' to 'Any'}}
11+
}

0 commit comments

Comments
 (0)