Skip to content

[Diagnostics] Add a fix-it for try instead of throws in function decl… #27647

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 4 commits into from
Oct 16, 2019

Conversation

vguerra
Copy link
Contributor

@vguerra vguerra commented Oct 12, 2019

…s and types.

Sometimes one would misstype throws for try so we provide a fix-it for that.
It might happen in two cases:

In function declarations:

func foo() try {}

In function types:

let f = () try -> Int

Resolves SR-11574.

@theblixguy theblixguy requested a review from rintaro October 12, 2019 15:08
@rintaro rintaro self-assigned this Oct 14, 2019
@CodaFi
Copy link
Contributor

CodaFi commented Oct 15, 2019

@swift-ci please smoke test

@vguerra
Copy link
Contributor Author

vguerra commented Oct 15, 2019

My bad! .. PR was not compiling. I pushed 59e8f20 with the fix.

@CodaFi, could you pls trigger tests again? Thanks!

@theblixguy
Copy link
Collaborator

@swift-ci please smoke test

@rintaro
Copy link
Member

rintaro commented Oct 15, 2019

@vguerra Sorry. The conflict is due to #27675 . Could you update the PR?

@rintaro rintaro removed their assignment Oct 15, 2019
…s and types.

Sometimes one would misstype `throws` for `try` so we provide a fix-it for that.
It might happen in two cases:

In function declarations:
```swift
func foo() try {}
```

In function types:
```swift
let f = () try -> Int
```

Resolves SR-11574.
Had to rebase due to revert of syxtax parsing swiftlang#27675.
@vguerra
Copy link
Contributor Author

vguerra commented Oct 16, 2019

@rintaro no worries. updated.

} else if (Tok.is(tok::kw_try)) {
SourceLoc tryLoc = consumeToken();
diagnose(tryLoc, diag::throw_in_function_type)
.fixItReplace(tryLoc, "throws");
Copy link
Member

@rintaro rintaro Oct 16, 2019

Choose a reason for hiding this comment

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

I think we should pretend that the throws is correctly written. i.e. We should set throwsLoc. Does just modifying the condition of the previous block to if (Tok.isAny(tok::kw_throw, kw_try)) work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, setting throwsLoc does work. I pushed 9656057

@rintaro
Copy link
Member

rintaro commented Oct 16, 2019

@swift-ci Please smoke test

Copy link
Member

@rintaro rintaro 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 Victor!

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.

4 participants