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

Grammar missing optional mutation-modifier in willSet/didSet-clause #298

Open
sarahcantohyatt opened this issue Apr 24, 2024 · 0 comments
Open

Comments

@sarahcantohyatt
Copy link
Contributor

Location

https://github.com/apple/swift-book/blob/main/TSPL.docc/ReferenceManual/Declarations.md?plain=1#L568

Description

Below is a subsection of a program pulled from the swift test suite.

@propertyWrapper
struct State {
  var wrappedValue: Int {
    get { 0 }
    nonmutating set {}
  }
}

struct MutatingDidSet {
  @State private var value: Int {
    mutating didSet {}
  }

  mutating func test() {
    value = 10
  }

}
struct MutatingWillSet {
  @State private var value: Int {
    mutating willSet {}
  }

  mutating func test() {
    value = 10
  }
}

The important things to look at in this program are:

@State private var value: Int {
    mutating didSet {}
  }

and

  @State private var value: Int {
    mutating willSet {}
  }

More specifically, the mutating keyword in front of the respective didSet/willSet.
This is not derivable in the current grammar due to mutation-modifier missing from the willSet/didSet-clause productions respectively.

Current grammar:

willSet-clause → attributes? willSet setter-name? code-block
didSet-clause → attributes? didSet setter-name? code-block

Correction

Proposed change:

willSet-clause → attributes? mutation-modifier? willSet setter-name? code-block
didSet-clause → attributes? mutation-modifier? didSet setter-name? code-block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant