Skip to content

Produce meaningful diagnostic for '#else if' typo #1302

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
Feb 17, 2023

Conversation

TiagoMaiaL
Copy link
Contributor

@TiagoMaiaL TiagoMaiaL commented Feb 1, 2023

The purpose of this PR is to fix the first part of issue #1221: produce a meaningful diagnostic for the common #else if typo.

I've followed the tips given by @bnbarham and the ones from the fixingBugs document. Here's what I did so far:

  1. Added a test inside ifconfigExprTests (it's currently failing because the diagnostics include more errors than the one I'm expecting, I must be doing something wrong)
  2. Generated an unexpected token for the #else if typo, and a missing one for #elseif, in parsePoundIfDirective, inside Directives.swift (I'm not sure if I'm using the right methods)
  3. Added code to generate correct diagnostics for IfConfigDeclSyntax, in ParseDiagnosticsGenerator.swift

Any tip or help to get this right is really appreciated. Thank you in advance.

@TiagoMaiaL TiagoMaiaL requested a review from ahoppen as a code owner February 1, 2023 12:59
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.

Hey @TiagoMaiaL,

thanks for working on this. I just took a look at your changes and noticed a few things to which I put comments inline. Can you take a look whether they make sense to you. If they don’t, feel free to reach out again.

@TiagoMaiaL TiagoMaiaL requested a review from ahoppen February 7, 2023 01:55
@TiagoMaiaL
Copy link
Contributor Author

@swift-ci please test

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.

Thanks. This is looking great now. I’ve got two more minor comments inline. After you addressed those, we can ship this.

And in case you’re wondering why your test request didn’t trigger anything: Only people with Commit Access can trigger CI testing.

@TiagoMaiaL TiagoMaiaL requested a review from ahoppen February 9, 2023 12:09
@ahoppen
Copy link
Member

ahoppen commented Feb 9, 2023

@swift-ci Please test

@TiagoMaiaL TiagoMaiaL requested a review from ahoppen February 9, 2023 23:39
@ahoppen
Copy link
Member

ahoppen commented Feb 10, 2023

Oh, one last request: Could you rebase and squash your commits on top of main? It just makes for a nicer git history.

@TiagoMaiaL TiagoMaiaL force-pushed the fix-else_if-diagnostic branch from 7745f36 to 1c8845d Compare February 17, 2023 03:44
@ahoppen
Copy link
Member

ahoppen commented Feb 17, 2023

Thanks for squashing the commits. Let’s 🚢it.

@swift-ci Please test

Generate unexpected and missing tokens for #else if typo

Add diagnostics for poundElseSpaceIf typo

Fix #else_if parsing test

Add StaticParserError.unexpectedPoundSpaceIf for `#else if` diagnostic

Start using `ReplaceTokensFixIt` in diagnostic for `IfConfigDeclSyntax`

Fix generation of unexpected nodes for `#else if` typo

Fix diagnostic generation for `#else if` typo

Rename `StaticParserError.unexpectedPoundSpaceIf` to `unexpectedPoundElseSpaceIf`

Fix `#else if` parsing and diagnostic test

Adjust `#else if` FixIt to only replace unexpected tokens

Remove `diagnosticSpec`s for handled nodes in `#else if` parsing test

Add `fixedSource` assertion to `#else if` diagnostic test

Fix `leadingTrivia` for `#else if` FixIt

Assert for correct FixIt message in `#else if` diagnostic test

Use new TokenConsumer.consume API for invalid if in `#else if`

Fix formatting for code related to `#else if` diagnostic generation
@TiagoMaiaL TiagoMaiaL force-pushed the fix-else_if-diagnostic branch from 1c8845d to 1ee6a45 Compare February 17, 2023 12:34
@TiagoMaiaL
Copy link
Contributor Author

TiagoMaiaL commented Feb 17, 2023

@ahoppen I've fixed the formatting issues in the code by running format.py. The tests are passing.
I'm not sure if formatting was the only issue in CI.

@ahoppen
Copy link
Member

ahoppen commented Feb 17, 2023

Let’s run CI again and see. If it got to checking the formatting, everything should be good.

@swift-ci Please test

@ahoppen ahoppen merged commit ef12dea into swiftlang:main Feb 17, 2023
@TiagoMaiaL
Copy link
Contributor Author

Thank you for your help, @ahoppen

@TiagoMaiaL TiagoMaiaL deleted the fix-else_if-diagnostic branch February 17, 2023 19: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