Skip to content

Commit 7fe209e

Browse files
oderskyallanrenucci
authored andcommitted
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 c917cf8 commit 7fe209e

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
@@ -2055,6 +2055,7 @@ object Parsers {
20552055
typeDefOrDcl(start, posMods(start, mods))
20562056
case CASE =>
20572057
enumCase(start, mods)
2058+
.reporting(t => i"case $t, current = ${in.show} / ${in.sepRegions}%, %")
20582059
case _ =>
20592060
tmplDef(start, mods)
20602061
}
@@ -2313,6 +2314,11 @@ object Parsers {
23132314
def enumCase(start: Offset, mods: Modifiers): DefTree = {
23142315
val mods1 = mods.withAddedMod(atPos(in.offset)(Mod.EnumCase())) | Case
23152316
accept(CASE)
2317+
2318+
in.adjustSepRegions(ARROW)
2319+
// Scanner thinks it is in a pattern match after seeing the `case`.
2320+
// We need to get it out of that mode by telling it we are past the `=>`
2321+
23162322
atPos(start, nameStart) {
23172323
val id = termIdent()
23182324
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)