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-10174] Childen of a MemberDeclListSyntax are no longer typed #420

Closed
Jeehut opened this issue Mar 26, 2019 · 6 comments
Closed

[SR-10174] Childen of a MemberDeclListSyntax are no longer typed #420

Jeehut opened this issue Mar 26, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@Jeehut
Copy link
Contributor

Jeehut commented Mar 26, 2019

Previous ID SR-10174
Radar None
Original Reporter @Jeehut
Type Bug
Environment

Xcode 10.2, macOS 10.14.3.

Additional Detail from JIRA
Votes 0
Component/s SwiftSyntax
Labels Bug
Assignee None
Priority Medium

md5: 308b17bfa083679803f5f2d92c489f53

Issue Description:

In the Swift 4.2 release, childen of a `MemberDeclListSyntax` type were typed, thus the following code was working:

let enumCaseDeclarations: [EnumCaseDeclSyntax] = enumDeclaration.members.members.children.compactMap { $0 as? EnumCaseDeclSyntax }

But after updating to Xcode 10.2 today, which includes the Swift 5.0 release, all `children` members are of type `Syntax` and casting to `EnumCaseDeclSyntax` fails, although that's the type I'm expecting here. You can find an example Swift file being parsed here.

Why was this API changed to be less informative? And how am I supposed to cast it to the appropriate type going forward with the 5.0 release?

It would be great to get feedback soon, so I can make a Xcode 10.2 compatible release of my tool BartyCrouch. See also the appropriate line here.

Thank you for your help in advance!

@belkadan
Copy link

cc @nkcsgexi

@Jeehut
Copy link
Contributor Author

Jeehut commented Mar 26, 2019

Please note that I found a way around this change, so it's not a pressing issue for me, but I would still expect something like the above being possible. Alternatively better documentation with more example uses would be great that covers stuff like this. Currently the project isn't particularly easy to use. But I'm sure you're aware of that.

@nkcsgexi
Copy link
Member

@Jeehut We have this change because the items in a MemberDeclList consist not decls but another layer of structure called MemberDeclListItem . We need to unwrap MemberDeclListItem to get all the enum cases back.

More specifically, this is the code snippet you could use to replace the 4.2 version:

        cases.append(contentsOf: node.members.members.compactMap {
          ($0 as MemberDeclListItemSyntax).decl as? EnumCaseDeclSyntax
        })

@nkcsgexi
Copy link
Member

For other parts of migrations for the new swift 5 tag, please refer to the changes swift-format has made here: google/swift@62d5af4

@Jeehut
Copy link
Contributor Author

Jeehut commented Mar 26, 2019

Thank you for the answer. I still think better documentation would be great for SwiftFormat with examples that are updated on new versions (instead of just linking to some examples usages that become out of date the moment a new version is released, like now).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@ahoppen
Copy link
Collaborator

ahoppen commented Jun 21, 2022

Closing this issue because the issue appears to be fixed. If you don’t agree, please re-open the issue.

@ahoppen ahoppen closed this as completed Jun 21, 2022
adevress pushed a commit to adevress/swift-syntax that referenced this issue Jan 14, 2024
Add a quick workaround for keypaths starting with `\.?.`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants