From 7fe209e86b2782f6df78389df7b1aec53b6ca743 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 2 Jan 2018 12:59:33 +0100 Subject: [PATCH 1/3] 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 `=>`. --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 6 ++++++ tests/pos/i3460.scala | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/pos/i3460.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 6adac05db82a..efce96978744 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2055,6 +2055,7 @@ object Parsers { typeDefOrDcl(start, posMods(start, mods)) case CASE => enumCase(start, mods) + .reporting(t => i"case $t, current = ${in.show} / ${in.sepRegions}%, %") case _ => tmplDef(start, mods) } @@ -2313,6 +2314,11 @@ object Parsers { def enumCase(start: Offset, mods: Modifiers): DefTree = { val mods1 = mods.withAddedMod(atPos(in.offset)(Mod.EnumCase())) | Case accept(CASE) + + in.adjustSepRegions(ARROW) + // Scanner thinks it is in a pattern match after seeing the `case`. + // We need to get it out of that mode by telling it we are past the `=>` + atPos(start, nameStart) { val id = termIdent() if (in.token == LBRACKET || in.token == LPAREN) diff --git a/tests/pos/i3460.scala b/tests/pos/i3460.scala new file mode 100644 index 000000000000..5ba4e6021cdf --- /dev/null +++ b/tests/pos/i3460.scala @@ -0,0 +1,7 @@ +enum class Ducks + +object Ducks { + case Dewey + + def wooohoo: Int = 1 +} From 5bc266350a74b64d27e908caa92dc3180ce92efb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 3 Jan 2018 11:05:34 +0100 Subject: [PATCH 2/3] Remove debug statement --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index efce96978744..fdecb3876ac7 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2055,7 +2055,6 @@ object Parsers { typeDefOrDcl(start, posMods(start, mods)) case CASE => enumCase(start, mods) - .reporting(t => i"case $t, current = ${in.show} / ${in.sepRegions}%, %") case _ => tmplDef(start, mods) } From 40a27602bb222123413984920d70796fea22eaf4 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Wed, 3 Jan 2018 18:12:50 +0100 Subject: [PATCH 3/3] Fix #2906: Add test case --- tests/pos/i2906.scala | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/pos/i2906.scala diff --git a/tests/pos/i2906.scala b/tests/pos/i2906.scala new file mode 100644 index 000000000000..1de3937ddb93 --- /dev/null +++ b/tests/pos/i2906.scala @@ -0,0 +1,6 @@ +enum Foo { + case A + private case B + @deprecated("Will be removed") case C + @deprecated("Will be removed") private case D +}