Skip to content

Parse init accessors. #1731

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

Merged
merged 6 commits into from
Jun 5, 2023
Merged

Parse init accessors. #1731

merged 6 commits into from
Jun 5, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Jun 4, 2023

This is the SwiftSyntax-side change to swiftlang/swift#66283. Add parsing for init accessors:

struct Wrapper<T> {
  var wrappedValue: T
}

struct S {
  private var _value: Wrapper<Int>
  var value: Int {
    init(newValue) initializes(_value) {
      self._value = Wrapper(wrappedValue: newValue)
    }

    get { _value.wrappedValue }
    set { _value.wrappedValue = newValue }
  }
}

@hborla hborla requested a review from ahoppen as a code owner June 4, 2023 18:55
@hborla
Copy link
Member Author

hborla commented Jun 4, 2023

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jun 4, 2023

@swift-ci please test

@hborla
Copy link
Member Author

hborla commented Jun 5, 2023

@swift-ci please test

@xedin
Copy link
Contributor

xedin commented Jun 5, 2023

@swift-ci please test Windows platform

@xedin xedin merged commit c28f994 into swiftlang:main Jun 5, 2023
@xedin xedin mentioned this pull request Jun 6, 2023
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve got a couple of post-merge comments for additional test cases / diagnostics.

The parsing pieces look good to me. I’ve got some opinions of how the node types and children should be named but I’ll try to put together a document around naming guidelines for these and will address my thoughts on the names once that’s finished.

}
}
"""
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case for the following? We should be offering a Fix-It to switch the positions of initializes(x) and accesses(y)

struct S {
  var value: Int {
    init accesses(y) initializes(x) {}
  }
}

Also I think the following tests would be useful

struct S {
  var value: Int {
    get accesses(y) {}
  }
}
struct S {
  var value: Int {
    init throws {}
  }
}

@hborla hborla deleted the init-accessors branch June 12, 2023 18:11
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

Successfully merging this pull request may close these issues.

3 participants