Skip to content

Implement a few more diagnostics in SwiftParser #1124

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 3 commits into from
Jan 13, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Dec 10, 2022

A few unrelated commits to migrate more diagnostics from the C++ parser to SwiftParser.

@ahoppen ahoppen requested a review from bnbarham December 10, 2022 09:42
@ahoppen
Copy link
Member Author

ahoppen commented Dec 10, 2022

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 10, 2022

@swift-ci Please test

@@ -237,8 +237,7 @@ final class GenericDisambiguationTests: XCTestCase {
func testGenericDisambiguation15() {
AssertParse(
"""
// TODO: parse empty <> list
//A<>.c() // e/xpected-error{{xxx}}
A<>.c()
Copy link
Contributor

Choose a reason for hiding this comment

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

What tree does this produce?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for checking. It parses <> as an operator. I’ll leave this TODO in for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to keep a TODO here (or did you open a bug?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder where I lost that change to keep the TODO. It’s in again now.

@@ -22,10 +22,7 @@ final class HashbangLibraryTests: XCTestCase {
class Foo {}
// Check that we diagnose and skip the hashbang at the beginning of the file
// when compiling in library mode.
""",
diagnostics: [
// TODO: Old parser expected error on line 1: hashbang line is allowed only in the main file
Copy link
Contributor

Choose a reason for hiding this comment

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

No diagnostic... what tree do we produce here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We parse the shebang as trivia. I would like to parse it as part of the source file at some point (rdar://98309158) but the current implementation isn’t too bad.

Added a substructure test.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW you don't need all those nil's any more. Maybe we should update the dump to not add them either 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, the PR is so old it still required the nils when I created it. I removed them.

func testStructNamedAny() {
AssertParse(
"""
struct any {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the point of this test to check a keyword or to check Any for anyKeyword?

Copy link
Member Author

Choose a reason for hiding this comment

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

Damn, I hate that we have capital any and lowercase any. I also added a test case for capital Any. It’s behaving correctly as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh :) All the more reason to merge keywords!

@@ -150,7 +150,7 @@ extension Parser {
introucerHandle: RecoveryConsumptionHandle
) -> T where T: NominalTypeDeclarationTrait {
let (unexpectedBeforeIntroducerKeyword, introducerKeyword) = self.eat(introucerHandle)
let (unexpectedBeforeName, name) = self.expectIdentifier(keywordRecovery: true)
let (unexpectedBeforeName, name) = self.expectIdentifier(allowIdentifierLikeKeywords: false, keywordRecovery: true)
Copy link
Contributor

Choose a reason for hiding this comment

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

When we do the keyword merging it would be nice to have sets for all the different "keyword" tokens we can have.

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey we can totally do this now :D. But fine not to for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe in a follow-up PR.

@ahoppen
Copy link
Member Author

ahoppen commented Dec 13, 2022

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 13, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/more-diags branch from f5c61fa to 922c27a Compare January 12, 2023 10:14
@ahoppen
Copy link
Member Author

ahoppen commented Jan 12, 2023

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/more-diags branch from 922c27a to 8ad44fb Compare January 12, 2023 10:21
@ahoppen
Copy link
Member Author

ahoppen commented Jan 12, 2023

@swift-ci Please test

@@ -237,8 +237,7 @@ final class GenericDisambiguationTests: XCTestCase {
func testGenericDisambiguation15() {
AssertParse(
"""
// TODO: parse empty <> list
//A<>.c() // e/xpected-error{{xxx}}
A<>.c()
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to keep a TODO here (or did you open a bug?)

@@ -150,7 +150,7 @@ extension Parser {
introucerHandle: RecoveryConsumptionHandle
) -> T where T: NominalTypeDeclarationTrait {
let (unexpectedBeforeIntroducerKeyword, introducerKeyword) = self.eat(introucerHandle)
let (unexpectedBeforeName, name) = self.expectIdentifier(keywordRecovery: true)
let (unexpectedBeforeName, name) = self.expectIdentifier(allowIdentifierLikeKeywords: false, keywordRecovery: true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey we can totally do this now :D. But fine not to for this PR.

@@ -22,10 +22,7 @@ final class HashbangLibraryTests: XCTestCase {
class Foo {}
// Check that we diagnose and skip the hashbang at the beginning of the file
// when compiling in library mode.
""",
diagnostics: [
// TODO: Old parser expected error on line 1: hashbang line is allowed only in the main file
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW you don't need all those nil's any more. Maybe we should update the dump to not add them either 🤔

@ahoppen ahoppen force-pushed the ahoppen/more-diags branch from 8ad44fb to 71ef7bf Compare January 13, 2023 07:19
@ahoppen
Copy link
Member Author

ahoppen commented Jan 13, 2023

@swift-ci Please test

@ahoppen ahoppen merged commit 1e61cc3 into swiftlang:main Jan 13, 2023
@ahoppen ahoppen deleted the ahoppen/more-diags branch January 13, 2023 15:04
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