Skip to content

Actually improve recovery when parsing bogus expressions #6319

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 16, 2016

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Dec 16, 2016

The crashes fixed appeared at first to be related to IfConfigStmt
parsing, but are in reality symptoms of being too lax in what we accept
when parsing of sub-expressions fails.

Optional type annotation parsing used to propagate failures before it
was patched to ‘recover’ with an AnyPattern. Instead, we’ll just hit
the error path for parsing in the main expressions because what is here
now isn’t a reasonable thing to return.

#selector parsing assumed that the current token it was at after
consuming up to a right-brace wasn’t bogus. Instead, if we’ve got
here, we may as well just return a loc we know is valid: PreviousLoc.

The crashes fixed appeared at first to be related to IfConfigStmt
parsing, but are in reality symptoms of being too lax in what we accept
when parsing of sub-expressions fail.

Optional type annotation parsing used to propagate failures before it
was patched to ‘recover’ with an AnyPattern.  Instead, we’ll just hit
the error path for parsing in the main expressions because what is here
now isn’t a reasonable thing to return.

#selector parsing assumed that the current token it was at after
consuming up to a right-brace wasn’t bogus.  Instead, if we’ve got
here, we may as well just return a loc we know is valid: PreviousLoc.
@CodaFi
Copy link
Contributor Author

CodaFi commented Dec 16, 2016

@slavapestov How's it look?

@swift-ci please smoke test.

@@ -661,7 +661,7 @@ ParserResult<Expr> Parser::parseExprSelector() {
if (Tok.is(tok::r_paren))
rParenLoc = consumeToken();
else
rParenLoc = Tok.getLoc();
rParenLoc = PreviousLoc;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a touch controversial. In each case, the Verifier was smacking up against Tok.getLoc() here also being the starting location of the next declaration that got parsed since it's using a strict "x comes before y" check instead of <=. But considering nothing important uses this SourceLoc I think it should fly.

@slavapestov
Copy link
Contributor

Looks great, thanks!

@slavapestov slavapestov merged commit 4c06e45 into swiftlang:master Dec 16, 2016
@CodaFi CodaFi deleted the crashendo-decrashendo branch December 16, 2016 18:25
CodaFi added a commit to CodaFi/swift that referenced this pull request Jan 4, 2017
Crashers fixed are minor logic errors:

Patterns: Crash occurred when requesting the range of a created
Pattern.  Validity of the range should be checked before returning it
to keep the entire range valid or invalid but never both.

ParseExpr/ParsePattern: The same fixes as the ones provided in swiftlang#6319

CSDiag: The generic visitor needn’t look through TypeVarTypes either.
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