Skip to content

[Parse] Improve parser diagnostics for keyword-as-identifer errors #6045

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
Dec 14, 2016
Merged

[Parse] Improve parser diagnostics for keyword-as-identifer errors #6045

merged 1 commit into from
Dec 14, 2016

Conversation

robinkunde
Copy link
Contributor

This PR improves the diagnostic output for parser errors where a Swift keyword is being used as an identifier.

Instead of the simple "expected identifier in declaration", the error will now read "keyword '%' cannot be used as an identifier here", and will be accompanied by a note suggesting escaping the keyword with backticks, as well as a fixit.

I started work on this after picking up SR-3167. When SR-3167 was created, Swift 3 was already exhibiting the desired behavior for the given example, so I decided to extent it other types of declarations as well.

@CodaFi
Copy link
Contributor

CodaFi commented Dec 4, 2016

LGTM. This is really a marked improvement.

@swift-ci please smoke test.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Robin, this does look better! One test case comment.

@@ -14,10 +14,6 @@ var bfx : Int, bfy : Int

_ = 10

func _(_ x: Int) {} // expected-error {{keyword '_' cannot be used as an identifier here}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to this test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to test/Parse/identifiers.swift where I added a number of related test cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that at the bottom there. Thanks!

@jrose-apple
Copy link
Contributor

Re-testing just in case.

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit ab415e6 into swiftlang:master Dec 14, 2016
@jrose-apple
Copy link
Contributor

Merged. Thanks, Robin!

@robinkunde robinkunde deleted the diag_keyword_identifier branch December 14, 2016 00:14
@robinkunde robinkunde restored the diag_keyword_identifier branch January 27, 2017 14:57
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.

3 participants