Skip to content

Fix a bug where an unfolded SequenceExpr would make it to the pretty-printer. #641

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
Sep 28, 2023

Conversation

allevato
Copy link
Member

Since the UseExplicitNilCheckInConditions rule was using string interpolation based parsing, it returned a SequenceExpr instead of an InfixOperatorExpr. This unfolded expression then made it to the pretty printer, which it didn't expect (because the input is folded before being processed by the rules, but not after that).

In this case, creating the new expression directly as nodes is barely more work than using the string-based parsing and then folding it, so I just did that.

Tests didn't catch this because the sequence expr is valid Swift code when stringified (for comparison in unit tests). To address this, we now do a pretty-printer pass on all the format rule outputs. We don't assert based on the pretty-printed output (that's not really a "unit" test anymore), but it at least causes a test crash if the output wasn't suitable for pretty printing.

Doing so caught a similar latent bug in UseShorthandTypeNames.

…y-printer.

Since the `UseExplicitNilCheckInConditions` rule was using string interpolation
based parsing, it returned a `SequenceExpr` instead of an `InfixOperatorExpr`.
This unfolded expression then made it to the pretty printer, which it didn't
expect (because the input is folded before being processed by the rules, but
not after that).

In this case, creating the new expression directly as nodes is barely more
work than using the string-based parsing and then folding it, so I just did
that.

Tests didn't catch this because the sequence expr is valid Swift code when
stringified (for comparison in unit tests). To address this, we now do a
pretty-printer pass on all the format rule outputs. We don't assert based
on the pretty-printed output (that's not really a "unit" test anymore),
but it at least causes a test crash if the output wasn't suitable for
pretty printing.

Doing so caught a similar latent bug in `UseShorthandTypeNames`.
@allevato
Copy link
Member Author

cc @thomasvl

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.

1 participant