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

Open
Jeehut opened this issue Mar 26, 2019 · 5 comments
Open

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

Jeehut opened this issue Mar 26, 2019 · 5 comments
Labels
bug

Comments

@Jeehut
Copy link
Contributor

@Jeehut 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

@belkadan belkadan commented Mar 26, 2019

@Jeehut
Copy link
Contributor Author

@Jeehut 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

@nkcsgexi nkcsgexi commented Mar 26, 2019

@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

@nkcsgexi nkcsgexi commented Mar 26, 2019

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug
Projects
None yet
Development

No branches or pull requests

4 participants