From aab030cba9b90a238ed3f28e8e1b9a95663edf4c Mon Sep 17 00:00:00 2001 From: Gagandeep Kalra Date: Sun, 12 Dec 2021 11:59:14 +0800 Subject: [PATCH 1/3] wip: 13097 todo: fix remaining tests --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 7 +++++++ .../test/dotty/tools/repl/ReplCompilerTests.scala | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 63b6e9f8ac51..7414ebd43909 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2333,6 +2333,13 @@ object Parsers { if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled => val app = applyToClosure(t, in.offset, convertToParams(termIdent())) simpleExprRest(app, location, canApply = true) +// Failing tests +// tests\pos\indent-colons.scala failed +// tests\pos\i12218.scala failed +// tests\pos\closure-args.scala failed + case EOF if in.fewerBracesEnabled && in.isNestedStart => + incompleteInputError("indented definitions expected, eof found") + t case _ => t } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 87c493ecde6a..1da449c739d8 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -283,3 +283,15 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose") { assert(storedOutput().trim().endsWith("val a: Int = 42")) } } + +class FewerBracesTests extends ReplTest(ReplTest.defaultOptions :+ "-language:experimental.fewerBraces" :+ "-Ydebug-error") { + @Test def i13097 = fromInitialState { implicit state => + given Context = state.context + assert(ParseResult.isIncomplete("val x = List(42).foreach:")) + } + + @Test def i13097Part2 = fromInitialState { implicit state => + given Context = state.context + assert(ParseResult.isIncomplete("class C:")) + } +} From 60eab0606ada045995cbf8bee94f81a76ec683e4 Mon Sep 17 00:00:00 2001 From: Gagandeep Kalra Date: Sun, 12 Dec 2021 11:59:14 +0800 Subject: [PATCH 2/3] wip: 13097 todo: fix remaining tests --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 7 +++++++ .../test/dotty/tools/repl/ReplCompilerTests.scala | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 63b6e9f8ac51..7414ebd43909 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2333,6 +2333,13 @@ object Parsers { if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled => val app = applyToClosure(t, in.offset, convertToParams(termIdent())) simpleExprRest(app, location, canApply = true) +// Failing tests +// tests\pos\indent-colons.scala failed +// tests\pos\i12218.scala failed +// tests\pos\closure-args.scala failed + case EOF if in.fewerBracesEnabled && in.isNestedStart => + incompleteInputError("indented definitions expected, eof found") + t case _ => t } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 406826ad67b1..ae3b42e9d7a3 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -283,3 +283,15 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose") { assert(storedOutput().trim().endsWith("val a: Int = 42")) } } + +class FewerBracesTests extends ReplTest(ReplTest.defaultOptions :+ "-language:experimental.fewerBraces" :+ "-Ydebug-error") { + @Test def i13097 = fromInitialState { implicit state => + given Context = state.context + assert(ParseResult.isIncomplete("val x = List(42).foreach:")) + } + + @Test def i13097Part2 = fromInitialState { implicit state => + given Context = state.context + assert(ParseResult.isIncomplete("class C:")) + } +} From 8f3c8449c9836a22cefd73c3359213dae343cad1 Mon Sep 17 00:00:00 2001 From: Gagandeep Kalra Date: Wed, 9 Feb 2022 01:19:51 +0800 Subject: [PATCH 3/3] fixed fewerBraces experimental flag repl bug, added targeted error scenario --- .../dotty/tools/dotc/parsing/Parsers.scala | 21 ++++++++++--------- .../dotty/tools/repl/ReplCompilerTests.scala | 7 ++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index fc961ef399a4..f880e1fb6535 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1247,13 +1247,17 @@ object Parsers { // note: next is defined here because current == NEWLINE if (in.token == NEWLINE && p(in.next.token)) newLineOpt() - def colonAtEOLOpt(): Unit = { + def colonAtEOLOpt(): Boolean = { possibleColonOffset = in.lastOffset - if in.token == COLONEOL then in.nextToken() + if in.token == COLONEOL then { + in.nextToken() + true + } else false } - def argumentStart(): Unit = - colonAtEOLOpt() + // returns true if COLONEOL encountered + def argumentStart(): Boolean = + val result = colonAtEOLOpt() if migrateTo3 && in.token == NEWLINE && in.next.token == LBRACE then in.nextToken() if in.indentWidth(in.offset) == in.currentRegion.indentWidth then @@ -1263,6 +1267,7 @@ object Parsers { |an argument to the previous expression.${rewriteNotice()}""", in.sourcePos()) patch(source, Span(in.offset), " ") + result def possibleTemplateStart(isNew: Boolean = false): Unit = in.observeColonEOL() @@ -2304,7 +2309,7 @@ object Parsers { } def simpleExprRest(t: Tree, location: Location, canApply: Boolean = true): Tree = { - if (canApply) argumentStart() + val seenCOLONEOL = if (canApply) argumentStart() else false in.token match { case DOT => in.nextToken() @@ -2338,11 +2343,7 @@ object Parsers { if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled => val app = applyToClosure(t, in.offset, convertToParams(termIdent())) simpleExprRest(app, location, canApply = true) -// Failing tests -// tests\pos\indent-colons.scala failed -// tests\pos\i12218.scala failed -// tests\pos\closure-args.scala failed - case EOF if in.fewerBracesEnabled && in.isNestedStart => + case EOF if in.fewerBracesEnabled && seenCOLONEOL => incompleteInputError("indented definitions expected, eof found") t case _ => diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 4ea622da0493..a4b75b234a63 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -282,14 +282,11 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose"): end ReplVerboseTests class FewerBracesTests extends ReplTest(ReplTest.defaultOptions :+ "-language:experimental.fewerBraces" :+ "-Ydebug-error"): - @Test def i13097 = fromInitialState { implicit state => - given Context = state.context + @Test def i13097_1 = contextually { assert(ParseResult.isIncomplete("val x = List(42).foreach:")) } - @Test def i13097Part2 = fromInitialState { implicit state => - given Context = state.context + @Test def i13097_2 = contextually { assert(ParseResult.isIncomplete("class C:")) } - end FewerBracesTests