From 2a7c504364b80ba77c217608bf7286775c518b74 Mon Sep 17 00:00:00 2001 From: Valentin Schneeberger Date: Wed, 28 Feb 2024 10:33:55 +0100 Subject: [PATCH 1/4] Fix issue #18596 --- .../dotc/printing/SyntaxHighlighting.scala | 29 +++++++++++-------- .../dotty/tools/repl/ReplCompilerTests.scala | 5 ++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index 6f65320d2c8e..2ede48f07231 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -126,22 +126,27 @@ object SyntaxHighlighting { val parser = new Parser(source) val trees = parser.blockStatSeq() - TreeHighlighter.highlight(trees) + try + TreeHighlighter.highlight(trees) - val highlighted = new StringBuilder() - for (idx <- colorAt.indices) { - val prev = if (idx == 0) NoColor else colorAt(idx - 1) - val curr = colorAt(idx) - if (curr != prev) - highlighted.append(curr) - highlighted.append(in(idx)) - } + val highlighted = new StringBuilder() + + for (idx <- colorAt.indices) { + val prev = if (idx == 0) NoColor else colorAt(idx - 1) + val curr = colorAt(idx) + if (curr != prev) + highlighted.append(curr) + highlighted.append(in(idx)) + } - if (colorAt.last != NoColor) - highlighted.append(NoColor) + if (colorAt.last != NoColor) + highlighted.append(NoColor) - highlighted.toString + highlighted.toString + catch + case(e): StackOverflowError => + in } } } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 26092b73f107..44d3198ff465 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -458,3 +458,8 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose"): } end ReplVerboseTests + +class ReplHighlightTests extends ReplTest(ReplTest.defaultOptions.filterNot(_.startsWith("-color")) :+ "-color:always"): + @Test def i18596: Unit = initially: + run("""(1 to 500).foldRight("x") { case (_, n) => s"$n" }""") + From 9fbeeb33c1ce992b0de5246925b576f771952211 Mon Sep 17 00:00:00 2001 From: Valentin Schneeberger Date: Wed, 28 Feb 2024 10:37:54 +0100 Subject: [PATCH 2/4] Also add parser of other issue --- .../src/dotty/tools/dotc/printing/SyntaxHighlighting.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index 2ede48f07231..2a62c9ef63c1 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -124,9 +124,9 @@ object SyntaxHighlighting { } } - val parser = new Parser(source) - val trees = parser.blockStatSeq() try + val parser = new Parser(source) + val trees = parser.blockStatSeq() TreeHighlighter.highlight(trees) @@ -149,4 +149,5 @@ object SyntaxHighlighting { in } } + } From d84978060281520f5ab07653fca8797a0508ac7a Mon Sep 17 00:00:00 2001 From: Valentin Schneeberger Date: Thu, 29 Feb 2024 16:59:03 +0100 Subject: [PATCH 3/4] Add test for issue 16904 --- compiler/test/dotty/tools/repl/ReplCompilerTests.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 44d3198ff465..24645f7c5e47 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -463,3 +463,11 @@ class ReplHighlightTests extends ReplTest(ReplTest.defaultOptions.filterNot(_.st @Test def i18596: Unit = initially: run("""(1 to 500).foldRight("x") { case (_, n) => s"$n" }""") + @Test def i16904: Unit = initially: + run(""""works not fine"* 10000""") + + run(""" + case class Tree(left: Tree, right: Tree) + def deepTree(depth: Int): Tree + deepTree(300)""") + From ef75f3b218803fb91d36c596fa5946a8b53be0af Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Tue, 26 Mar 2024 13:55:19 +0100 Subject: [PATCH 4/4] Fix case style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Doeraene --- compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index 2a62c9ef63c1..ce925e336b53 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -145,7 +145,7 @@ object SyntaxHighlighting { highlighted.toString catch - case(e): StackOverflowError => + case e: StackOverflowError => in } }