From b5714ec36c6b701793621d68147b0a074f8e3ec4 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 6 Aug 2019 23:16:54 +0200 Subject: [PATCH 1/2] Revert "Apply suggestions from code review" This reverts commit 46d232467fd44d117b6f82089f1420e46dda857d. --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 6306d2535e18..cae43cf8f60e 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1332,7 +1332,7 @@ object Parsers { case DO => in.errorOrMigrationWarning( i"""`do while ' is no longer supported, - |use `while { ; } do ()' instead. + |use `while ({ ; }) ()' instead. |The statement can be rewritten automatically under -language:Scala2 -migration -rewrite. """) val start = in.skipToken() @@ -1353,7 +1353,7 @@ object Parsers { } patch(source, cond.span.endPos, "}) ()") } - WhileDo(Block(body :: Nil, cond), Literal(Constant(()))) + WhileDo(Block(Block(Nil, body), Block(Nil, cond)), Literal(Constant(()))) } case TRY => val tryOffset = in.offset From 5dfe7d2e4a8e3cf8a04dcce4e14ce0f39b293527 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 6 Aug 2019 23:26:47 +0200 Subject: [PATCH 2/2] Add do/while double definition tests and reoptimize --- .../dotty/tools/dotc/parsing/Parsers.scala | 2 +- tests/pos-scala2/doWhile.scala | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/pos-scala2/doWhile.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index cae43cf8f60e..e79a8cc55df7 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1353,7 +1353,7 @@ object Parsers { } patch(source, cond.span.endPos, "}) ()") } - WhileDo(Block(Block(Nil, body), Block(Nil, cond)), Literal(Constant(()))) + WhileDo(Block(body, cond), Literal(Constant(()))) } case TRY => val tryOffset = in.offset diff --git a/tests/pos-scala2/doWhile.scala b/tests/pos-scala2/doWhile.scala new file mode 100644 index 000000000000..1e70923381c3 --- /dev/null +++ b/tests/pos-scala2/doWhile.scala @@ -0,0 +1,29 @@ +class Test { + do { + val x = 1 + println(x) + } while { + val x = "a" + println(x) + true + } + + do { + val x = 1 + } while { + val x = "a" + true + } + + val x: Int = 3 + do { + val x = "" + } while (x == 2) + + do (x == 3) + while { + val x = "a" + true + } + +}