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-16123] Non-escaping closure capturing inout wrongly assessed as escaping => error #58382

Open
dabrahams opened this issue Apr 18, 2022 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself

Comments

@dabrahams
Copy link
Contributor

Previous ID SR-16123
Radar None
Original Reporter @dabrahams
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 131508c8606cf9082245704a5b9fd7a9

Issue Description:

func f(a: inout Int) {
  let change: ()->Void = {
    a += 1
  }
  _ = change()
}

Diagnostics:

x.swift:2:26: error: escaping closure captures 'inout' parameter 'a'
  let change: ()->Void = {
                         ^
x.swift:1:8: note: parameter 'a' is declared 'inout'
func f(a: inout Int) {
       ^
x.swift:3:5: note: captured here
    a += 1
    ^

Yet somehow, the compiler knows that g doesn't escape in:

func call(_ f: ()->Void) {
  let g = f
  _ = g
}

func f(a: inout Int) {
  call {
    a += 1
  }
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@benlangmuir
Copy link
Contributor

@dabrahams should this be reopened? I see it was marked "resolved" on bugs.swift.org by another user within a couple hours of you filing it, and there is no comment indicating why.

@dabrahams
Copy link
Contributor Author

🤷 Test it with the latest source I guess. I don't know why it would have been resolved.

@benlangmuir
Copy link
Contributor

Still reproduces with latest compiler, reopening.

@benlangmuir benlangmuir reopened this Apr 28, 2022
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 itself
Projects
None yet
Development

No branches or pull requests

2 participants