Skip to content

Commit f24b16b

Browse files
committed
Fix #3460: Fix semicolon insertion confusion after enum case
After seeing an enum case, the Scanner thought it is in a pattern, and therefore does not do semicolon insertion on newlines. We now get it out of that mode by pretending to be passed the `=>`.
1 parent be50d2c commit f24b16b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,7 @@ object Parsers {
20602060
typeDefOrDcl(start, posMods(start, mods))
20612061
case CASE =>
20622062
enumCase(start, mods)
2063+
.reporting(t => i"case $t, current = ${in.show} / ${in.sepRegions}%, %")
20632064
case _ =>
20642065
tmplDef(start, mods)
20652066
}
@@ -2318,6 +2319,11 @@ object Parsers {
23182319
def enumCase(start: Offset, mods: Modifiers): DefTree = {
23192320
val mods1 = mods.withAddedMod(atPos(in.offset)(Mod.EnumCase())) | Case
23202321
accept(CASE)
2322+
2323+
in.adjustSepRegions(ARROW)
2324+
// Scanner thinks it is in a pattern match after seeing the `case`.
2325+
// We need to get it out of that mode by telling it we are past the `=>`
2326+
23212327
atPos(start, nameStart) {
23222328
val id = termIdent()
23232329
if (in.token == LBRACKET || in.token == LPAREN)

tests/pos/i3460.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum class Ducks
2+
3+
object Ducks {
4+
case Dewey
5+
6+
def wooohoo: Int = 1
7+
}

0 commit comments

Comments
 (0)