From 1785f36f2252d68f15b3cecc4db659cf173540d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Marks?= Date: Thu, 4 Mar 2021 18:01:00 +0100 Subject: [PATCH] Skip empty statements around end markers --- .../dotty/tools/dotc/parsing/Parsers.scala | 6 +++- tests/neg/i11581.scala | 33 +++++++++++++++++++ tests/pos/i11581.scala | 27 +++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i11581.scala create mode 100644 tests/pos/i11581.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index ac16c00d14af..86fb8ed4cb3b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -364,11 +364,15 @@ object Parsers { if in.isNewLine then in.nextToken() else accept(SEMI) def acceptStatSepUnlessAtEnd[T <: Tree](stats: ListBuffer[T], altEnd: Token = EOF): Unit = + def skipEmptyStats(): Unit = + while (in.token == SEMI || in.token == NEWLINE || in.token == NEWLINES) do in.nextToken() + in.observeOutdented() in.token match case SEMI | NEWLINE | NEWLINES => - in.nextToken() + skipEmptyStats() checkEndMarker(stats) + skipEmptyStats() case `altEnd` => case _ => if !isStatSeqEnd then diff --git a/tests/neg/i11581.scala b/tests/neg/i11581.scala new file mode 100644 index 000000000000..87f5fd6d7a71 --- /dev/null +++ b/tests/neg/i11581.scala @@ -0,0 +1,33 @@ +class Abc: + def a = { + println(10) + 10 + } + + ; ; + + end a + end a // error +; ; +end Abc +end Abc // error + +class D: +end D +end D // error + +class Xyz { + def a = + println(10) + 10 + +} + + +; +end Xyz +; +; + +end Xyz // error + diff --git a/tests/pos/i11581.scala b/tests/pos/i11581.scala new file mode 100644 index 000000000000..d36593af01f5 --- /dev/null +++ b/tests/pos/i11581.scala @@ -0,0 +1,27 @@ +class Abc: + def a = { + println(10) + 10 + } + + ; ; + + end a + + +; ; + +end Abc + +class Xyz { + def a = + println(10) + 10 + +} + + +; ; +; + +end Xyz \ No newline at end of file