swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.02k stars 10.32k forks source link

[SR-8536] Warn on member assignments capturing self #51055

Open CodaFi opened 5 years ago

CodaFi commented 5 years ago
Previous ID SR-8536
Radar None
Original Reporter @CodaFi
Type Improvement
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 2 | |Component/s | Compiler | |Labels | Improvement, StarterBug, TypeChecker | |Assignee | tt (JIRA) | |Priority | Medium | md5: cb331d15432b248f57b7b7bce4d077f7

Issue Description:

class Foo {
  let bar: () -> ()

  func baz() {}

  init() {
    self.bar = baz // We oughta warn about capturing 'self' implicitly.
  }
}

In the example above, we should warn about capturing `self` implicitly and, rather than suggest the user make it explicit, probably offer a fixit that provides a closure with a weak or unowned capture.

belkadan commented 4 years ago

Resetting assignees on all Starter Bugs that haven't been touched since 2018.

swift-ci commented 3 years ago

Comment by Tapan Thaker (JIRA)

Implementing this in PR 35473