Skip to content

Commit 47bf5e6

Browse files
committed
fix: use correct ErrorMessageID for EmptyCatchOrFinallyBlock
Previously we were always assigning this to `EmptyCatchOrFinallyBlockID` but both `EmptyCatchBlock` and `EmptyCatchAndFinallyBlock` both use this class and pass in their corresponding `ErrorMessageID`. This caused the following two code samples to give the same `ErrorMessageID` when they should have been different than they currently are: ```scala try {} ``` ```scala try {} catch {} finally {} ``` The second one gave this as an error: ``` scala> try {} catch {} finally {} -- [E000] Syntax Error: -------------------------------------------------------- 1 |try {} catch {} finally {} | ^^^^^^^^ | The catch block does not contain a valid expression, try | adding a case like - case e: Exception => to the block | | longer explanation available when compiling with `-explain` ``` When the ID should `E001`, `EmptyCatchBlockId`. Now this correctly returns: ``` scala> try {} catch{} finally {} -- [E001] Syntax Error: -------------------------------------------------------- 1 |try {} catch{} finally {} | ^^^^^^^ | The catch block does not contain a valid expression, try | adding a case like - case e: Exception => to the block | | longer explanation available when compiling with `-explain` ``` The first example with the missing catch and finally block should actually be `[E002]`.
1 parent 6f3fe05 commit 47bf5e6

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import transform.SymUtils._
7878
def kind = "Reference"
7979

8080
abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: ErrorMessageID)(using Context)
81-
extends SyntaxMsg(EmptyCatchOrFinallyBlockID) {
81+
extends SyntaxMsg(errNo) {
8282
def explain = {
8383
val tryString = tryBody match {
8484
case Block(Nil, untpd.EmptyTree) => "{}"

compiler/test-resources/repl/i13208.default.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
scala> try 1
22
1 warning found
3-
-- [E000] Syntax Warning: ------------------------------------------------------
3+
-- [E002] Syntax Warning: ------------------------------------------------------
44
1 | try 1
55
| ^^^^^
66
| A try without catch or finally is equivalent to putting

tests/neg-custom-args/nowarn/nowarn-parser-error.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| an identifier expected, but 'def' found
55
|
66
| longer explanation available when compiling with `-explain`
7-
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn-parser-error.scala:2:10 ----------------------------------
7+
-- [E002] Syntax Warning: tests/neg-custom-args/nowarn/nowarn-parser-error.scala:2:10 ----------------------------------
88
2 | def a = try 1 // warn
99
| ^^^^^
1010
| A try without catch or finally is equivalent to putting

0 commit comments

Comments
 (0)