Skip to content

Change SyntaxRewriter to disallow type node type conversions for all types that are not ExprSyntax, StmtSyntax … #1003

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 1 commit into from
Oct 22, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 21, 2022

Intuitively, changing the kind of an expression in a rewriter makes sense but for all the other syntax kinds I can’t see any use case for changing their types.

Thus, add some type safety to SyntaxRewriter by requiring that all visit methods for nodes that don’t have a base kind like ExprSyntax return a node of the same type.

rdar://101355004

…types that are not ExprSyntax, StmtSyntax …

Intuitively, changing the kind of an expression in a rewriter makes sense but for all the other syntax kinds I can’t see any use case for changing their types.

Thus, add some type safety to `SyntaxRewriter` by requiring that all `visit` methods for nodes that don’t have a base kind like `ExprSyntax` return a node of the same type.

rdar://101355004
@ahoppen
Copy link
Member Author

ahoppen commented Oct 21, 2022

Here’s the PR to update swift-format. In general it appears to clean things up in there: swiftlang/swift-format#433

@ahoppen
Copy link
Member Author

ahoppen commented Oct 21, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit 2016c7e into swiftlang:main Oct 22, 2022
@ahoppen ahoppen deleted the ahoppen/syntaxrewriter-return-type branch October 22, 2022 12:19
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.

2 participants