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-2274] Nested functions should allow escaping attributes, be @noescape by default #44881

Closed
karwa opened this issue Aug 4, 2016 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@karwa
Copy link
Contributor

karwa commented Aug 4, 2016

Previous ID SR-2274
Radar None
Original Reporter @karwa
Type Bug
Status Resolved
Resolution Done
Environment

Swift 6f743db

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee @slavapestov
Priority Medium

md5: 201464737036e6362607328dd3c439c0

is duplicated by:

  • SR-3277 Incorrect error generated when capturing non-escaping block in a locally-defined fuction

relates to:

  • SR-2362 Compiler doesn't ask for explicit self in local function passed as @escaping

Issue Description:

The following code fails to compile, as the reference to 'callback' in 'nestedFunc()' is considered possibly-escaping.

func doSomething(callback: (Bool)->()) {
    
    func nestedFunc() {
        callback(true)
    }
    nestedFunc()
}
/Users/karl/Desktop/test.swift:4:3: error: declaration closing over non-escaping parameter 'callback' may allow it to escape
                callback(true)
                ^
/Users/karl/Desktop/test.swift:1:18: note: parameter 'callback' is implicitly non-escaping
func doSomething(callback: (Bool)->()) {
@belkadan
Copy link
Contributor

belkadan commented Aug 4, 2016

Hm. It's probably too late to change this behavor. @milseman, tanadeau (JIRA User), @DougGregor?

@milseman
Copy link
Mannequin

milseman mannequin commented Aug 4, 2016

The escaping 'analysis' is done in Sema and is very simplistic (and thus excludes many otherwise valid programs). We can make it smarter without breaking source, and that's worth pursuing some. I don't know if we will make it in time for 3.0, but that would be a good stretch goal.

@swift-ci
Copy link
Collaborator

Comment by Raphael (JIRA)

I think this is the same as that: http://stackoverflow.com/q/41162775/539599 (with use-case). Definitely annoying and breaking good (imho) designs.

@slavapestov
Copy link
Member

Instead of changing local functions to have an 'escapingness', we can fix this in a source compatible way by extending the analysis to look at transitive closure formation.

@slavapestov
Copy link
Member

#23923

@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

4 participants