Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3277] Incorrect error generated when capturing non-escaping block in a locally-defined fuction #45865

Closed
swift-ci opened this issue Nov 26, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3277
Radar None
Original Reporter kelan (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: ecdf828d7ae0134e758d4be40b6d319a

duplicates:

  • SR-2274 Nested functions should allow escaping attributes, be @NoEscape by default

Issue Description:

This code has a locally-defined function that captures a non-escaping block in its closure:

func outer(block: () -> Void) {
    func inner() {
        block()   // <--- error here
    }
    inner()
}

The compiler generates an error that "declaration closing over non-escaping parameter 'block' may allow it to escape". However, since the inner() func can only be called from within outer(), I don't think that warning is true.

You could do something else in the inner function that captures the block in an escpaing way, but the error should only be generated if you do that.

I expect this to be valid code (unless I'm missing something else).

@belkadan
Copy link
Contributor

belkadan commented Dec 9, 2016

The compiler currently isn't smart enough to know that inner doesn't escape, and so it assumes the worst.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants