-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomersimprovementparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parser
Description
Previous ID | SR-11574 |
Radar | None |
Original Reporter | @beccadax |
Type | Improvement |
Status | Closed |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Improvement, DiagnosticsQoI, Parser, StarterBug |
Assignee | @vguerra |
Priority | Medium |
md5: 4b1deee143c591cfa05263856f246b0c
Issue Description:
Suppose you absentmindedly type try
in a function declaration when you meant to type throws
. Swift's diagnostic in this situation is not very good:
Welcome to Apple Swift version 5.1.1 (swiftlang-1100.0.274.1 clang-1100.0.33.9).
Type :help for assistance.
1> func foo() try {}
error: repl.swift:1:11: error: consecutive statements on a line must be separated by ';'
func foo() try {}
^
;
A message along the lines of "expected throwing specifier; did you mean throws?" with a fix-it would provide a much nicer experience.
To implement this, you would find the place(s) in the parser where we parse the "throws" keyword and attempt to parse the "try" keyword there if "throws" fails. If you parse it, you should emit the diagnostic and then have the compiler pretend that it parsed "throws" to recover from the error. We're already doing this for "throw", so you might just be able to add "try" to the same code path.
Metadata
Metadata
Assignees
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomersimprovementparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parser