Skip to content

Fix a crash in diagnostic generation if a primary associated type is not ended with a > #1110

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 2 commits into from
Dec 6, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Dec 5, 2022

In the new test case, we were parsing : as a right angle, which caused a crash when we were retrieving the token’s kind in diagnostic generation.

This allows us to reduce cases in which the parser is crashing during diagnostic generation.
@ahoppen ahoppen requested a review from bnbarham December 5, 2022 16:10
@ahoppen
Copy link
Member Author

ahoppen commented Dec 5, 2022

@swift-ci Please test

@@ -258,7 +258,12 @@ extension Parser {
arena: self.arena))
} while keepGoing != nil && loopProgress.evaluate(currentToken)
}
let rangle = self.consumeAnyToken(remapping: .rightAngle)
let rangle: RawTokenSyntax
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the precedence of : compared to >? Could we use expect here instead?

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 don’t think we currently have a way to expect the > as a token prefix. The problem here is that sometimes the > can be part of a bigger token.

DiagnosticSpec(locationMarker: "1️⃣", message: "expected identifier in protocol"),
DiagnosticSpec(locationMarker: "2️⃣", message: "expected name in primary associated type clause"),
DiagnosticSpec(locationMarker: "2️⃣", message: "expected '>' to end primary associated type clause"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected type in type"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to my PR - expected type in type is uh... not great 😅. I'm fine if you just want to add a TODO here

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I think I would just not expect this particular diagnostic, the rest seem fine. If we ate the : we'd get an "unexpected :" instead which might make more sense.

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 adjusted a name and now it’s expected type in inherited type. I think that makes sense.

…not ended with a `>`

In the new test case, we were parsing `:` as a right angle, which caused a crash when we were retrieving the token’s kind in diagnostic generation.
@ahoppen ahoppen force-pushed the ahoppen/fix-parser-crash branch from 5a069e8 to 9dc574b Compare December 6, 2022 09:55
@ahoppen
Copy link
Member Author

ahoppen commented Dec 6, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit cdbdcba into swiftlang:main Dec 6, 2022
@ahoppen ahoppen deleted the ahoppen/fix-parser-crash branch December 6, 2022 13:14
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