Skip to content

Commit 54a9ed7

Browse files
committed
fix: use correct ErrorMessageID for EmptyCatchOrFinallyBlock
Previously we were always assigning this to `EmptyCatchOrFinallyBlockID` but both `EmptyCatchBlock` and `EmptyCatchOrFinallyBlock` 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: ```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` ```
1 parent 6f3fe05 commit 54a9ed7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
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) => "{}"

0 commit comments

Comments
 (0)