Skip to content
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

[Diagnostics] Add a fix-it for misplaced throws in function types #25306

Merged
merged 3 commits into from Jun 8, 2019

Conversation

tapthaker
Copy link
Contributor

Adds a diagnostic error for misplaced throws in function types. For e.g:

let fn: () -> throws Void  // expected-error{{'throws' may only occur before '->'}} {{12-12=throws }} {{15-22=}}

Resolves SR-10703.

@tapthaker
Copy link
Contributor Author

@brentdax: This fixes the bug that you reported. Thanks

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.

Thank you for picking this up! This implementation looks good but I do have a few notes.

@@ -417,6 +417,12 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
if (Tok.is(tok::arrow)) {
// Handle type-function if we have an arrow.
SourceLoc arrowLoc = consumeToken();
if(Tok.is(tok::kw_throws)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Please put a space before the open-paren.

if(Tok.is(tok::kw_throws)) {
Diag<> DiagID = diag::throws_in_wrong_position;
diagnose(Tok.getLoc(), DiagID).fixItInsert(arrowLoc, "throws ")
.fixItRemove(Tok.getLoc());
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a tab snuck in here.

Diag<> DiagID = diag::throws_in_wrong_position;
diagnose(Tok.getLoc(), DiagID).fixItInsert(arrowLoc, "throws ")
.fixItRemove(Tok.getLoc());
consumeToken();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good, but I think we can probably recover as if the user wrote throws in the correct place by setting throwsLoc.

@beccadax
Copy link
Contributor

beccadax commented Jun 7, 2019

@swift-ci please smoke test

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@beccadax beccadax merged commit 07e6940 into apple:master Jun 8, 2019
@tapthaker tapthaker deleted the SR-10703-fix-misplaced-throws branch June 8, 2019 15:06
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.

None yet

3 participants