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-3442] Non-escaping closure can't capture mutating self #46030

Closed
rxwei opened this issue Dec 16, 2016 · 4 comments
Closed

[SR-3442] Non-escaping closure can't capture mutating self #46030

rxwei opened this issue Dec 16, 2016 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 3.0

Comments

@rxwei
Copy link
Member

rxwei commented Dec 16, 2016

Previous ID SR-3442
Radar None
Original Reporter @rxwei
Type Bug
Status Closed
Resolution Invalid
Environment

Swift 3.0.2, all platforms

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression
Assignee @rxwei
Priority Medium

md5: 966044ecbecdd175db286ad7ecbd7511

Issue Description:

Non-escaping closure can't capture mutating self in Swift 3.0.2. Compiler gives "closure cannot implicitly capture a mutating self parameter". This broke a lot of code of mine.

    let blockSize = min(512, count)
    let blockCount = (count+blockSize-1)/blockSize
    device.sync { // Launch CUDA kernel
        try! fill<<<(blockSize, blockCount)>>>[
            .pointer(to: &self), .value(value), .value(Int64(count))
        ]
    }
@belkadan
Copy link
Contributor

Can you include a self-contained example? The simple one works for me.

func test(callback: () -> Void) {
  callback()
}

func use(_ ptr: UnsafeMutableRawPointer) {}

struct Foo {
  var x: Int = 0
  mutating func bar() {
    test {
      x += 1
      use(&self)
    }
  }
}

var foo = Foo()
foo.bar()
print(foo)

@rxwei
Copy link
Member Author

rxwei commented Dec 16, 2016

It's a bit tricky to reproduce. Lemme see..
It's not a self-capturing problem. Turns out the factory method .value in my original code went missing. Compiler didn't give useful diagnosis.

@rxwei
Copy link
Member Author

rxwei commented Dec 17, 2016

It's a source problem. Diagnosis was misleading

@belkadan
Copy link
Contributor

If you can come up with a self-contained example of the issue with the bad diagnostic, that would also be useful. :-)

@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 regression swift 3.0
Projects
None yet
Development

No branches or pull requests

3 participants