From b505519b57df943c7f5e191ec4764068b9daa798 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 29 Oct 2025 11:00:58 +0800 Subject: [PATCH 1/9] . --- .../dotty/tools/dotc/util/StackTraceOps.scala | 42 +++++++----- compiler/src/dotty/tools/repl/Rendering.scala | 65 +++++++++++-------- .../src/dotty/tools/repl/ReplDriver.scala | 4 +- 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala b/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala index bd5c031a65e0..03fca0d05b3a 100644 --- a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala +++ b/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala @@ -13,7 +13,7 @@ package dotty.tools.dotc.util import scala.language.unsafeNulls - +import dotty.shaded.fansi import collection.mutable, mutable.ListBuffer import dotty.tools.dotc.util.chaining.* import java.lang.System.lineSeparator @@ -31,23 +31,26 @@ object StackTraceOps: * shared stack trace segments. * @param p the predicate to select the prefix */ - def formatStackTracePrefix(p: StackTraceElement => Boolean): String = + def formatStackTracePrefix(p: StackTraceElement => Boolean): fansi.Str = type TraceRelation = String - val Self = new TraceRelation("") - val CausedBy = new TraceRelation("Caused by: ") - val Suppressed = new TraceRelation("Suppressed: ") + val Self = "" + val CausedBy = "Caused by: " + val Suppressed = "Suppressed: " - def header(e: Throwable): String = + def header(e: Throwable): fansi.Str = def because = e.getCause match { case null => null ; case c => header(c) } def msg = e.getMessage match { case null => because ; case s => s } - def txt = msg match { case null => "" ; case s => s": $s" } - s"${e.getClass.getName}$txt" + def txt = msg match { + case null => "" + case s => s": $s" + } + fansi.Color.LightRed(e.getClass.getName) ++ txt val seen = mutable.Set.empty[Throwable] def unseen(e: Throwable): Boolean = (e != null && !seen(e)).tap(if _ then seen += e) - val lines = ListBuffer.empty[String] + val lines = ListBuffer.empty[fansi.Str] // format the stack trace, skipping the shared trace def print(e: Throwable, r: TraceRelation, share: Array[StackTraceElement], indents: Int): Unit = if unseen(e) then @@ -58,20 +61,29 @@ object StackTraceOps: trimmed.reverse val prefix = frames.takeWhile(p) val margin = " " * indents - lines += s"${margin}${r}${header(e)}" - prefix.foreach(frame => lines += s"$margin at $frame") + lines += fansi.Str(margin) ++ fansi.Color.Red(r) ++ header(e) + prefix.foreach(frame => + lines += + fansi.Str(s"$margin ") ++ fansi.Color.Red("at") ++ " " ++ + fansi.Str.join(frame.getClassName.split('.').map(fansi.Color.LightRed(_)), ".") ++ "." ++ + fansi.Color.LightRed(frame.getMethodName) ++ "(" ++ + fansi.Color.LightRed(frame.getFileName) ++ ":" ++ + fansi.Color.LightRed(frame.getLineNumber.toString) ++ ")" + ) val traceFramesLenDiff = trace.length - frames.length val framesPrefixLenDiff = frames.length - prefix.length if traceFramesLenDiff > 0 then - if framesPrefixLenDiff > 0 then lines += s"$margin ... $framesPrefixLenDiff elided and $traceFramesLenDiff more" - else lines += s"$margin ... $traceFramesLenDiff more" - else if framesPrefixLenDiff > 0 then lines += s"$margin ... $framesPrefixLenDiff elided" + if framesPrefixLenDiff > 0 + then lines += fansi.Color.Red(s"$margin ... $framesPrefixLenDiff elided and $traceFramesLenDiff more") + else lines += fansi.Color.Red(s"$margin ... $traceFramesLenDiff more") + else if framesPrefixLenDiff > 0 + then lines += fansi.Color.Red(s"$margin ... $framesPrefixLenDiff elided") print(e.getCause, CausedBy, trace, indents) e.getSuppressed.foreach(print(_, Suppressed, frames, indents + 1)) end print print(t, Self, share = Array.empty, indents = 0) - lines.mkString(lineSeparator) + fansi.Str.join(lines, lineSeparator) end formatStackTracePrefix diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index a86ba12bb0a9..e0e57d4e0535 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -6,6 +6,8 @@ import scala.language.unsafeNulls import dotc.*, core.* import Contexts.*, Denotations.*, Flags.*, NameOps.*, StdNames.*, Symbols.* import printing.ReplPrinter +import printing.SyntaxHighlighting +import dotty.shaded.{fansi, pprint} import reporting.Diagnostic import util.StackTraceOps.* @@ -26,17 +28,21 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): var myClassLoader: AbstractFileClassLoader = uninitialized - private def pprintRender(value: Any, width: Int, height: Int, initialOffset: Int)(using Context): String = { - def fallback() = - dotty.shaded.pprint.PPrinter.BlackWhite + private def pprintRender(value: Any, width: Int, height: Int, initialOffset: Int)(using Context): fansi.Str = { + def fallback() = { + + val fansiStr = pprint.PPrinter.Color .apply(value, width = width, height = height, initialOffset = initialOffset) - .plainText + dotty.shaded.pprint.log(fansiStr.toString.toCharArray) + fansiStr + } + try val cl = classLoader() - val pprintCls = Class.forName("dotty.shaded.pprint.PPrinter$BlackWhite$", false, cl) - val fansiStrCls = Class.forName("dotty.shaded.fansi.Str", false, cl) - val BlackWhite = pprintCls.getField("MODULE$").get(null) - val BlackWhite_apply = pprintCls.getMethod("apply", + val pprintCls = Class.forName("pprint.PPrinter$Color$", false, cl) + val fansiStrCls = Class.forName("fansi.Str", false, cl) + val Color = pprintCls.getField("MODULE$").get(null) + val Color_apply = pprintCls.getMethod("apply", classOf[Any], // value classOf[Int], // width classOf[Int], // height @@ -45,11 +51,11 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): classOf[Boolean], // escape Unicode classOf[Boolean], // show field names ) - val FansiStr_plainText = fansiStrCls.getMethod("plainText") - val fansiStr = BlackWhite_apply.invoke( - BlackWhite, value, width, height, 2, initialOffset, false, true + val fansiStr = Color_apply.invoke( + Color, value, width, height, 2, initialOffset, false, true ) - FansiStr_plainText.invoke(fansiStr).asInstanceOf[String] + dotty.shaded.pprint.log(fansiStr.toString.toCharArray) + fansi.Str(fansiStr.toString) catch case _: ClassNotFoundException => fallback() case _: NoSuchMethodException => fallback() @@ -85,8 +91,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): if ncp <= maxPrintCharacters then str else str.substring(0, str.offsetByCodePoints(0, maxPrintCharacters - 1)) - /** Return a String representation of a value we got from `classLoader()`. */ - private[repl] def replStringOf(value: Object, prefixLength: Int)(using Context): String = { + /** Return a colored fansi.Str representation of a value we got from `classLoader()`. */ + private[repl] def replStringOf(value: Object, prefixLength: Int)(using Context): fansi.Str = { // pretty-print things with 100 cols 50 rows by default, pprintRender( value, @@ -100,7 +106,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): * * Calling this method evaluates the expression using reflection */ - private def valueOf(sym: Symbol, prefixLength: Int)(using Context): Option[String] = + private def valueOf(sym: Symbol, prefixLength: Int)(using Context): Option[fansi.Str] = val objectName = sym.owner.fullName.encode.toString.stripSuffix("$") val resObj: Class[?] = Class.forName(objectName, true, classLoader()) val symValue = resObj @@ -109,11 +115,14 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): .flatMap(result => rewrapValueClass(sym.info.classSymbol, result.invoke(null))) symValue .filter(_ => sym.is(Flags.Method) || sym.info != defn.UnitType) - .map(value => stripReplPrefix(replStringOf(value, prefixLength))) - - private def stripReplPrefix(s: String): String = - if (s.startsWith(REPL_WRAPPER_NAME_PREFIX)) - s.drop(REPL_WRAPPER_NAME_PREFIX.length).dropWhile(c => c.isDigit || c == '$') + .map(value => stripReplPrefixFansi(replStringOf(value, prefixLength))) + + private def stripReplPrefixFansi(s: fansi.Str): fansi.Str = + val plain = s.plainText + if (plain.startsWith(REPL_WRAPPER_NAME_PREFIX)) + val prefixLen = REPL_WRAPPER_NAME_PREFIX.length + val dropLen = prefixLen + plain.drop(prefixLen).takeWhile(c => c.isDigit || c == '$').length + s.substring(dropLen) else s @@ -141,17 +150,17 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): /** Render value definition result */ def renderVal(d: Denotation)(using Context): Either[ReflectiveOperationException, Option[Diagnostic]] = - val dcl = d.symbol.showUser - def msg(s: String) = infoDiagnostic(s, d) + val dcl = fansi.Str(SyntaxHighlighting.highlight(d.symbol.showUser)) + def msg(s: fansi.Str) = infoDiagnostic(s, d) try Right( if d.symbol.is(Flags.Lazy) then Some(msg(dcl)) else { - val prefix = s"$dcl = " + val prefix = dcl ++ " = " // Prefix can have multiple lines, only consider the last one // when determining the initial column offset for pretty-printing - val prefixLength = prefix.linesIterator.toSeq.lastOption.getOrElse("").length - valueOf(d.symbol, prefixLength).map(value => msg(s"$prefix$value")) + val prefixLength = prefix.plainText.linesIterator.toSeq.lastOption.getOrElse("").length + valueOf(d.symbol, prefixLength).map(value => msg(prefix ++ value)) } ) catch case e: ReflectiveOperationException => Left(e) @@ -181,8 +190,12 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): infoDiagnostic(cause.formatStackTracePrefix(!isWrapperInitialization(_)), d) end renderError + private def infoDiagnostic(msg: fansi.Str, d: Denotation)(using Context): Diagnostic = { + new Diagnostic.Info(msg.render, d.symbol.sourcePos) + } + private def infoDiagnostic(msg: String, d: Denotation)(using Context): Diagnostic = - new Diagnostic.Info(msg, d.symbol.sourcePos) + new Diagnostic.Info(SyntaxHighlighting.highlight(msg), d.symbol.sourcePos) object Rendering: final val REPL_WRAPPER_NAME_PREFIX = str.REPL_SESSION_LINE diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 5cd8fd0bf539..3ad98b045177 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -497,9 +497,7 @@ class ReplDriver(settings: Array[String], val formattedTypeDefs = // don't render type defs if wrapper initialization failed if newState.invalidObjectIndexes.contains(state.objectIndex) then Seq.empty else typeDefs(wrapperModule.symbol) - val highlighted = (formattedTypeDefs ++ formattedMembers) - .map(d => new Diagnostic(d.msg.mapMsg(SyntaxHighlighting.highlight), d.pos, d.level)) - (newState, highlighted) + (newState, formattedTypeDefs ++ formattedMembers) } .getOrElse { // user defined a trait/class/object, so no module needed From 3a910e57074b93815aae709dfea69e16f1020d95 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 29 Oct 2025 11:07:43 +0800 Subject: [PATCH 2/9] . --- compiler/src/dotty/tools/repl/Rendering.scala | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index e0e57d4e0535..e83bf7ce00d5 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -28,21 +28,18 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): var myClassLoader: AbstractFileClassLoader = uninitialized - private def pprintRender(value: Any, width: Int, height: Int, initialOffset: Int)(using Context): fansi.Str = { - def fallback() = { - - val fansiStr = pprint.PPrinter.Color + private def pprintRender(value: Any, width: Int, height: Int, initialOffset: Int)(using Context): String = { + def fallback() = + dotty.shaded.pprint.PPrinter.Color .apply(value, width = width, height = height, initialOffset = initialOffset) - dotty.shaded.pprint.log(fansiStr.toString.toCharArray) - fansiStr - } - + .render + .toString try val cl = classLoader() - val pprintCls = Class.forName("pprint.PPrinter$Color$", false, cl) - val fansiStrCls = Class.forName("fansi.Str", false, cl) - val Color = pprintCls.getField("MODULE$").get(null) - val Color_apply = pprintCls.getMethod("apply", + val pprintColorCls = Class.forName("dotty.shaded.pprint.PPrinter$Color$", false, cl) + val fansiStrCls = Class.forName("dotty.shaded.fansi.Str", false, cl) + val Color = pprintColorCls.getField("MODULE$").get(null) + val Color_apply = pprintColorCls.getMethod("apply", classOf[Any], // value classOf[Int], // width classOf[Int], // height @@ -51,11 +48,11 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): classOf[Boolean], // escape Unicode classOf[Boolean], // show field names ) + val FansiStr_render = fansiStrCls.getMethod("render") val fansiStr = Color_apply.invoke( Color, value, width, height, 2, initialOffset, false, true ) - dotty.shaded.pprint.log(fansiStr.toString.toCharArray) - fansi.Str(fansiStr.toString) + FansiStr_render.invoke(fansiStr).asInstanceOf[String] catch case _: ClassNotFoundException => fallback() case _: NoSuchMethodException => fallback() From b182b3dc3084fbe1c1fe5d6b678837a221431283 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 29 Oct 2025 11:23:26 +0800 Subject: [PATCH 3/9] . --- compiler/src/dotty/tools/dotc/util/StackTraceOps.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala b/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala index 03fca0d05b3a..5ed456a2bdf9 100644 --- a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala +++ b/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala @@ -37,6 +37,9 @@ object StackTraceOps: val Self = "" val CausedBy = "Caused by: " val Suppressed = "Suppressed: " + def renderDotDelimited(s: String ) = { + fansi.Str.join(s.split('.').map(fansi.Color.LightRed(_)), ".") + } def header(e: Throwable): fansi.Str = def because = e.getCause match { case null => null ; case c => header(c) } @@ -45,13 +48,12 @@ object StackTraceOps: case null => "" case s => s": $s" } - fansi.Color.LightRed(e.getClass.getName) ++ txt + renderDotDelimited(e.getClass.getName) ++ txt val seen = mutable.Set.empty[Throwable] def unseen(e: Throwable): Boolean = (e != null && !seen(e)).tap(if _ then seen += e) val lines = ListBuffer.empty[fansi.Str] - // format the stack trace, skipping the shared trace def print(e: Throwable, r: TraceRelation, share: Array[StackTraceElement], indents: Int): Unit = if unseen(e) then val trace = e.getStackTrace @@ -65,7 +67,7 @@ object StackTraceOps: prefix.foreach(frame => lines += fansi.Str(s"$margin ") ++ fansi.Color.Red("at") ++ " " ++ - fansi.Str.join(frame.getClassName.split('.').map(fansi.Color.LightRed(_)), ".") ++ "." ++ + renderDotDelimited(frame.getClassName) ++ "." ++ fansi.Color.LightRed(frame.getMethodName) ++ "(" ++ fansi.Color.LightRed(frame.getFileName) ++ ":" ++ fansi.Color.LightRed(frame.getLineNumber.toString) ++ ")" From f83a1b1df88b0e25c943b3b54d2aa0e7e3671687 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 29 Oct 2025 11:52:18 +0800 Subject: [PATCH 4/9] . --- compiler/src/dotty/tools/repl/Rendering.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index e83bf7ce00d5..c581449b6db6 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -91,12 +91,13 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): /** Return a colored fansi.Str representation of a value we got from `classLoader()`. */ private[repl] def replStringOf(value: Object, prefixLength: Int)(using Context): fansi.Str = { // pretty-print things with 100 cols 50 rows by default, - pprintRender( + val res = pprintRender( value, width = 100, height = 50, initialOffset = prefixLength ) + if (ctx.settings.color.value == "never") fansi.Str(res).plainText else res } /** Load the value of the symbol using reflection. @@ -184,7 +185,9 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): ste.getClassName.startsWith(REPL_WRAPPER_NAME_PREFIX) // d.symbol.owner.name.show is simple name && (ste.getMethodName == nme.STATIC_CONSTRUCTOR.show || ste.getMethodName == nme.CONSTRUCTOR.show) - infoDiagnostic(cause.formatStackTracePrefix(!isWrapperInitialization(_)), d) + val formatted0 = cause.formatStackTracePrefix(!isWrapperInitialization(_)) + val formatted: fansi.Str = if (ctx.settings.color.value == "never") formatted0.plainText else formatted0 + infoDiagnostic(formatted, d) end renderError private def infoDiagnostic(msg: fansi.Str, d: Denotation)(using Context): Diagnostic = { From bd06199b061b9cc6fb01f6c58bda1106b45e9557 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 29 Oct 2025 12:57:26 +0800 Subject: [PATCH 5/9] . --- compiler/test/dotty/tools/dotc/util/StackTraceTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala b/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala index 7e49fd64c146..5d16e86eddbd 100644 --- a/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala +++ b/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala @@ -37,7 +37,7 @@ class StackTraceTest: // evaluating s should throw, p trims stack trace, t is the test of resulting trace string def probe(s: => String)(p: StackTraceElement => Boolean)(t: String => Unit): Unit = import StackTraceOps.formatStackTracePrefix - Try(s).recover { case e => e.formatStackTracePrefix(p) } match + Try(s).recover { case e => e.formatStackTracePrefix(p).plainText } match case Success(s) => t(s) case Failure(e) => throw e From ffa9599908b1866899070e98c61c8d4e58ec1ed6 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Nov 2025 12:36:29 -0600 Subject: [PATCH 6/9] fixes --- .../quoted/runtime/impl/printers/SyntaxHighlight.scala | 4 ++-- repl/src/dotty/tools/repl/Rendering.scala | 7 +++---- .../util => repl/src/dotty/tools/repl}/StackTraceOps.scala | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) rename {compiler/src/dotty/tools/dotc/util => repl/src/dotty/tools/repl}/StackTraceOps.scala (98%) diff --git a/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala b/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala index cc3ecc2b153a..5f41e7233e95 100644 --- a/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala +++ b/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala @@ -22,8 +22,8 @@ object SyntaxHighlight { private val ValDefColor = Console.CYAN private val LiteralColor = Console.RED private val StringColor = Console.GREEN - private val TypeColor = Console.MAGENTA - private val AnnotationColor = Console.MAGENTA + private val TypeColor = Console.GREEN + private val AnnotationColor = Console.GREEN def highlightKeyword(str: String): String = KeywordColor + str + NoColor def highlightTypeDef(str: String): String = TypeColor + str + NoColor diff --git a/repl/src/dotty/tools/repl/Rendering.scala b/repl/src/dotty/tools/repl/Rendering.scala index f02d534d94e8..ef0d26082a91 100644 --- a/repl/src/dotty/tools/repl/Rendering.scala +++ b/repl/src/dotty/tools/repl/Rendering.scala @@ -7,9 +7,8 @@ import dotc.*, core.* import Contexts.*, Denotations.*, Flags.*, NameOps.*, StdNames.*, Symbols.* import printing.ReplPrinter import printing.SyntaxHighlighting -import dotty.shaded.{fansi, pprint} import reporting.Diagnostic -import util.StackTraceOps.* +import StackTraceOps.* import scala.compiletime.uninitialized import scala.util.control.NonFatal @@ -47,8 +46,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): val cl = classLoader() val pprintCls = Class.forName("dotty.shaded.pprint.PPrinter$Color$", false, cl) val fansiStrCls = Class.forName("fansi.Str", false, cl) - val BlackWhite = pprintCls.getField("MODULE$").get(null) - val BlackWhite_apply = pprintCls.getMethod("apply", + val Color = pprintCls.getField("MODULE$").get(null) + val Color_apply = pprintCls.getMethod("apply", classOf[Any], // value classOf[Int], // width classOf[Int], // height diff --git a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala b/repl/src/dotty/tools/repl/StackTraceOps.scala similarity index 98% rename from compiler/src/dotty/tools/dotc/util/StackTraceOps.scala rename to repl/src/dotty/tools/repl/StackTraceOps.scala index 5ed456a2bdf9..618bdd979688 100644 --- a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala +++ b/repl/src/dotty/tools/repl/StackTraceOps.scala @@ -10,10 +10,9 @@ * additional information regarding copyright ownership. */ -package dotty.tools.dotc.util +package dotty.tools.repl import scala.language.unsafeNulls -import dotty.shaded.fansi import collection.mutable, mutable.ListBuffer import dotty.tools.dotc.util.chaining.* import java.lang.System.lineSeparator From 18d93363309bd0f8cbaa3c13b6ace3eaca5b4eee Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Nov 2025 12:39:12 -0600 Subject: [PATCH 7/9] fixes --- repl/src/dotty/tools/repl/Rendering.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repl/src/dotty/tools/repl/Rendering.scala b/repl/src/dotty/tools/repl/Rendering.scala index ef0d26082a91..fde300bcf39d 100644 --- a/repl/src/dotty/tools/repl/Rendering.scala +++ b/repl/src/dotty/tools/repl/Rendering.scala @@ -44,7 +44,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): // Due the possible interruption instrumentation, it is unlikely that we can get // rid of reflection here. val cl = classLoader() - val pprintCls = Class.forName("dotty.shaded.pprint.PPrinter$Color$", false, cl) + val pprintCls = Class.forName("pprint.PPrinter$Color$", false, cl) val fansiStrCls = Class.forName("fansi.Str", false, cl) val Color = pprintCls.getField("MODULE$").get(null) val Color_apply = pprintCls.getMethod("apply", From 36144bf94630a659839b84667ec5b2a6f1c7410b Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Nov 2025 12:58:18 -0600 Subject: [PATCH 8/9] . --- .../util => repl/test/dotty/tools/repl}/StackTraceTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {compiler/test/dotty/tools/dotc/util => repl/test/dotty/tools/repl}/StackTraceTest.scala (98%) diff --git a/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala b/repl/test/dotty/tools/repl/StackTraceTest.scala similarity index 98% rename from compiler/test/dotty/tools/dotc/util/StackTraceTest.scala rename to repl/test/dotty/tools/repl/StackTraceTest.scala index 5d16e86eddbd..03863ffce1cc 100644 --- a/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala +++ b/repl/test/dotty/tools/repl/StackTraceTest.scala @@ -1,5 +1,5 @@ -package dotty.tools.dotc.util +package dotty.tools.repl import scala.language.unsafeNulls From 4dc44a96a9a67496cca11a13df4d384a778ff80b Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Nov 2025 18:07:40 -0600 Subject: [PATCH 9/9] . --- .../tools/dotc/printing/PlainPrinter.scala | 5 +- .../tools/dotc/printing/RefinedPrinter.scala | 2 +- .../dotc/printing/SyntaxHighlighting.scala | 16 +-- .../runtime/impl/printers/SourceCode.scala | 96 +++++++-------- .../impl/printers/SyntaxHighlight.scala | 27 ++--- .../printing/SyntaxHighlightingTests.scala | 112 +++++++++--------- 6 files changed, 122 insertions(+), 136 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 90dfb72ef010..ef18a09cf28b 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -705,7 +705,7 @@ class PlainPrinter(_ctx: Context) extends Printer { def toText(denot: Denotation): Text = toText(denot.symbol) ~ "/D" def toText(const: Constant): Text = const.tag match { - case StringTag => stringText(Chars.escapedString(const.value.toString, quoted = true)) + case StringTag => literalText(Chars.escapedString(const.value.toString, quoted = true)) case ClazzTag => "classOf[" ~ toText(const.typeValue) ~ "]" case CharTag => literalText(Chars.escapedChar(const.charValue)) case LongTag => literalText(const.longValue.toString + "L") @@ -841,10 +841,9 @@ class PlainPrinter(_ctx: Context) extends Printer { protected def keywordStr(text: String): String = coloredStr(text, SyntaxHighlighting.KeywordColor) protected def keywordText(text: String): Text = coloredStr(text, SyntaxHighlighting.KeywordColor) - protected def valDefText(text: Text): Text = coloredText(text, SyntaxHighlighting.ValDefColor) + protected def valDefText(text: Text): Text = coloredText(text, SyntaxHighlighting.DefinitionColor) protected def typeText(text: Text): Text = coloredText(text, SyntaxHighlighting.TypeColor) protected def literalText(text: Text): Text = coloredText(text, SyntaxHighlighting.LiteralColor) - protected def stringText(text: Text): Text = coloredText(text, SyntaxHighlighting.StringColor) protected def coloredStr(text: String, color: String): String = if (ctx.useColors) color + text + SyntaxHighlighting.NoColor else text diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index b8de2c7a9115..b34306ef66d4 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -596,7 +596,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case tree @ Inlined(call, bindings, body) => val bodyText = if bindings.isEmpty then toText(body) else blockText(bindings :+ body) if homogenizedView || !ctx.settings.XprintInline.value then bodyText - else if tree.inlinedFromOuterScope then stringText("{{") ~ stringText("/* inlined from outside */") ~ bodyText ~ stringText("}}") + else if tree.inlinedFromOuterScope then literalText("{{") ~ literalText("/* inlined from outside */") ~ bodyText ~ literalText("}}") else keywordText("{{") ~ keywordText("/* inlined from ") ~ toText(call) ~ keywordText(" */") ~ bodyText ~ keywordText("}}") case tpt: untpd.DerivedTypeTree => "" diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index bb6c9d7dccf9..fd30beb0bb5a 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -26,11 +26,9 @@ object SyntaxHighlighting { val NoColor: String = Console.RESET val CommentColor: String = Console.BLUE val KeywordColor: String = Console.YELLOW - val ValDefColor: String = Console.CYAN + val DefinitionColor: String = Console.CYAN val LiteralColor: String = Console.GREEN - val StringColor: String = Console.GREEN val TypeColor: String = Console.GREEN - val AnnotationColor: String = Console.GREEN def highlight(in: String)(using Context): String = { def freshCtx = ctx.fresh.setReporter(Reporter.NoReporter) @@ -101,7 +99,7 @@ object SyntaxHighlighting { def highlightAnnotations(tree: MemberDef): Unit = for (annotation <- tree.rawMods.annotations) - highlightPosition(annotation.span, AnnotationColor) + highlightPosition(annotation.span, TypeColor) def highlight(trees: List[Tree])(using Context): Unit = trees.foreach(traverse) @@ -112,14 +110,16 @@ object SyntaxHighlighting { () case tree: ValOrDefDef => highlightAnnotations(tree) - highlightPosition(tree.nameSpan, ValDefColor) - highlightPosition(tree.endSpan, ValDefColor) + highlightPosition(tree.nameSpan, DefinitionColor) + highlightPosition(tree.endSpan, DefinitionColor) case tree: MemberDef /* ModuleDef | TypeDef */ => highlightAnnotations(tree) - highlightPosition(tree.nameSpan, TypeColor) - highlightPosition(tree.endSpan, TypeColor) + highlightPosition(tree.nameSpan, DefinitionColor) + highlightPosition(tree.endSpan, DefinitionColor) case tree: Ident if tree.isType => highlightPosition(tree.span, TypeColor) + case tree: Select if tree.isType => + highlightPosition(tree.nameSpan, TypeColor) case _: TypeTree => highlightPosition(tree.span, TypeColor) case _ => diff --git a/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala b/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala index 35d57f4a05c0..92b2290e3b1d 100644 --- a/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala +++ b/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala @@ -152,12 +152,12 @@ object SourceCode { if (flags.is(Flags.Case)) this += highlightKeyword("case ") if (name == "package$") { - this += highlightKeyword("package object ") += highlightTypeDef(cdef.symbol.owner.name.stripSuffix("$")) + this += highlightKeyword("package object ") += highlightType(cdef.symbol.owner.name.stripSuffix("$")) } - else if (flags.is(Flags.Module)) this += highlightKeyword("object ") += highlightTypeDef(name.stripSuffix("$")) - else if (flags.is(Flags.Trait)) this += highlightKeyword("trait ") += highlightTypeDef(name) - else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ") += highlightTypeDef(name) - else this += highlightKeyword("class ") += highlightTypeDef(name) + else if (flags.is(Flags.Module)) this += highlightKeyword("object ") += highlightType(name.stripSuffix("$")) + else if (flags.is(Flags.Trait)) this += highlightKeyword("trait ") += highlightType(name) + else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ") += highlightType(name) + else this += highlightKeyword("class ") += highlightType(name) if (!flags.is(Flags.Module)) { for paramClause <- paramss do @@ -237,7 +237,7 @@ object SourceCode { val Some(ValDef(name, tpt, _)) = self: @unchecked indented { val name1 = if (name == "_") "this" else name - this += " " += highlightValDef(name1) += ": " + this += " " += highlightDefinition(name1) += ": " printTypeTree(tpt)(using Some(cdef.symbol)) this += " =>" } @@ -279,7 +279,7 @@ object SourceCode { else this += highlightKeyword("val ") val name1 = splicedName(vdef.symbol).getOrElse(name) - this += highlightValDef(name1) += ": " + this += highlightDefinition(name1) += ": " printTypeTree(tpt) rhs match { case Some(tree) => @@ -315,7 +315,7 @@ object SourceCode { printProtectedOrPrivate(ddef) val name1: String = if (isConstructor) "this" else splicedName(ddef.symbol).getOrElse(name) - this += highlightKeyword("def ") += highlightValDef(name1) + this += highlightKeyword("def ") += highlightDefinition(name1) for clause <- paramss do clause match case TermParamClause(params) => printMethdArgsDefs(params) @@ -337,7 +337,7 @@ object SourceCode { case tree: Ident => splicedName(tree.symbol) match { - case Some(name) => this += highlightTypeDef(name) + case Some(name) => this += highlightType(name) case _ => printType(tree.tpe) } @@ -438,7 +438,7 @@ object SourceCode { printTree(term) term match { case Repeated(_, _) | Inlined(None, Nil, Repeated(_, _)) => this - case _ => this += ": " += highlightTypeDef("_*") + case _ => this += ": " += highlightType("_*") } case _ => inParens { @@ -764,9 +764,9 @@ object SourceCode { if (isDef) { if (argDef.symbol.flags.is(Flags.Covariant)) { - this += highlightValDef("+") + this += highlightDefinition("+") } else if (argDef.symbol.flags.is(Flags.Contravariant)) { - this += highlightValDef("-") + this += highlightDefinition("-") } } @@ -873,18 +873,18 @@ object SourceCode { printedPrefix = true } printedPrefix |= printProtectedOrPrivate(vdef) - if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ") - else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAccessor)) this += highlightValDef("val ") + if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightDefinition("var ") + else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAccessor)) this += highlightDefinition("val ") } } end if - this += highlightValDef(name) += ": " + this += highlightDefinition(name) += ": " printTypeTree(arg.tpt) } private def printCaseDef(caseDef: CaseDef): this.type = { - this += highlightValDef("case ") + this += highlightDefinition("case ") printPattern(caseDef.pattern) caseDef.guard match { case Some(t) => @@ -892,7 +892,7 @@ object SourceCode { printTree(t) case None => } - this += highlightValDef(" =>") + this += highlightDefinition(" =>") indented { caseDef.rhs match { case Block(stats, expr) => @@ -906,9 +906,9 @@ object SourceCode { } private def printTypeCaseDef(caseDef: TypeCaseDef): this.type = { - this += highlightValDef("case ") + this += highlightDefinition("case ") printTypeTree(caseDef.pattern) - this += highlightValDef(" => ") + this += highlightDefinition(" => ") printTypeTree(caseDef.rhs) this } @@ -921,7 +921,7 @@ object SourceCode { this += name case Bind(name, Typed(Wildcard(), tpt)) => - this += highlightValDef(name) += ": " + this += highlightDefinition(name) += ": " printTypeTree(tpt) case Bind(name, pattern) => @@ -972,8 +972,8 @@ object SourceCode { case LongConstant(v) => this += highlightLiteral(v.toString + "L") case FloatConstant(v) => this += highlightLiteral(v.toString + "f") case DoubleConstant(v) => this += highlightLiteral(v.toString) - case CharConstant(v) => this += highlightString(Chars.escapedChar(v)) - case StringConstant(v) => this += highlightString(Chars.escapedString(v, quoted = true)) + case CharConstant(v) => this += highlightLiteral(Chars.escapedChar(v)) + case StringConstant(v) => this += highlightLiteral(Chars.escapedString(v, quoted = true)) case ClassOfConstant(v) => this += "classOf" inSquare(printType(v)) @@ -1027,10 +1027,10 @@ object SourceCode { printType(tree.tpe) case TypeSelect(qual, name) => - printTree(qual) += "." += highlightTypeDef(name) + printTree(qual) += "." += highlightType(name) case TypeProjection(qual, name) => - printTypeTree(qual) += "#" += highlightTypeDef(name) + printTypeTree(qual) += "#" += highlightType(name) case Singleton(ref) => printTree(ref) @@ -1053,7 +1053,7 @@ object SourceCode { case tpe: TypeRef if tpe.typeSymbol == Symbol.requiredClass("scala.annotation.internal.Repeated") => val Types.Sequence(tp) = tpt.tpe: @unchecked printType(tp) - this += highlightTypeDef("*") + this += highlightType("*") case _ => printTypeTree(tpt) this += " " @@ -1066,16 +1066,16 @@ object SourceCode { inBlock(printTypeCases(cases, lineBreak())) case ByName(result) => - this += highlightTypeDef("=> ") + this += highlightType("=> ") printTypeTree(result) case LambdaTypeTree(tparams, body) => printTargsDefs(tparams.zip(tparams), isDef = false) - this += highlightTypeDef(" =>> ") + this += highlightType(" =>> ") printTypeOrBoundsTree(body) case TypeBind(name, _) => - this += highlightTypeDef(name) + this += highlightType(name) case TypeBlock(_, tpt) => printTypeTree(tpt) @@ -1121,23 +1121,23 @@ object SourceCode { printType(prefix) this += "." } - this += highlightTypeDef(sym.name.stripSuffix("$")) + this += highlightType(sym.name.stripSuffix("$")) case TermRef(prefix, name) => if fullNames then prefix match { case NoPrefix() => - this += highlightTypeDef(name) + this += highlightType(name) case ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => - this += highlightTypeDef(name) + this += highlightType(name) case _ => printType(prefix) if (name != "package") - this += "." += highlightTypeDef(name) + this += "." += highlightType(name) this } else - this += highlightTypeDef(name) + this += highlightType(name) case tpe @ Refinement(_, _, _) => printRefinement(tpe) @@ -1175,12 +1175,12 @@ object SourceCode { case AndType(left, right) => printType(left) - this += highlightTypeDef(" & ") + this += highlightType(" & ") printType(right) case OrType(left, right) => printType(left) - this += highlightTypeDef(" | ") + this += highlightType(" | ") printType(right) case MatchType(bound, scrutinee, cases) => @@ -1189,14 +1189,14 @@ object SourceCode { inBlock(printTypes(cases, lineBreak())) case ByNameType(tp) => - this += highlightTypeDef(" => ") + this += highlightType(" => ") printType(tp) case ThisType(tp) => tp match { case tp: TypeRef if !tp.typeSymbol.flags.is(Flags.Module) => printFullClassName(tp) - this += highlightTypeDef(".this") + this += highlightType(".this") case TypeRef(prefix, name) if name.endsWith("$") => if (fullNames){ prefix match { @@ -1207,18 +1207,18 @@ object SourceCode { this += "." } } - this += highlightTypeDef(name.stripSuffix("$")) + this += highlightType(name.stripSuffix("$")) case _ => printType(tp) } case SuperType(thistpe, supertpe) => printType(thistpe) - this += highlightTypeDef(".super") + this += highlightType(".super") case TypeLambda(paramNames, tparams, body) => inSquare(printMethodicTypeParams(paramNames, tparams)) - this += highlightTypeDef(" =>> ") + this += highlightType(" =>> ") printType(body) case ParamRef(lambda, idx) => @@ -1232,7 +1232,7 @@ object SourceCode { printType(tpe) case RecursiveThis(_) => - this += highlightTypeDef("this") + this += highlightType("this") case tpe: MethodType => this += "(" @@ -1283,10 +1283,10 @@ object SourceCode { } private def printDefinitionName(tree: Definition): this.type = tree match { - case ValDef(name, _, _) => this += highlightValDef(name) - case DefDef(name, _, _, _) => this += highlightValDef(name) - case ClassDef(name, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$")) - case TypeDef(name, _) => this += highlightTypeDef(name) + case ValDef(name, _, _) => this += highlightDefinition(name) + case DefDef(name, _, _, _) => this += highlightDefinition(name) + case ClassDef(name, _, _, _, _) => this += highlightType(name.stripSuffix("$")) + case TypeDef(name, _) => this += highlightType(name) } private def printAnnotation(annot: Term)(using elideThis: Option[Symbol]): this.type = { @@ -1336,13 +1336,13 @@ object SourceCode { this += lineBreak() info match { case info: TypeBounds => - this += highlightKeyword("type ") += highlightTypeDef(name) + this += highlightKeyword("type ") += highlightType(name) printBounds(info) case ByNameType(_) | MethodType(_, _, _) | TypeLambda(_, _, _) => - this += highlightKeyword("def ") += highlightTypeDef(name) + this += highlightKeyword("def ") += highlightType(name) printMethodicType(info) case info: TypeRepr => - this += highlightKeyword("val ") += highlightValDef(name) + this += highlightKeyword("val ") += highlightDefinition(name) printMethodicType(info) } } diff --git a/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala b/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala index 5f41e7233e95..b597ca35ea6d 100644 --- a/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala +++ b/compiler/src/scala/quoted/runtime/impl/printers/SyntaxHighlight.scala @@ -3,12 +3,9 @@ package runtime.impl.printers trait SyntaxHighlight { def highlightKeyword(str: String): String - def highlightTypeDef(str: String): String + def highlightType(str: String): String def highlightLiteral(str: String): String - def highlightValDef(str: String): String - def highlightOperator(str: String): String - def highlightAnnotation(str: String): String - def highlightString(str: String): String + def highlightDefinition(str: String): String def highlightTripleQs: String } @@ -19,30 +16,22 @@ object SyntaxHighlight { private val NoColor = Console.RESET private val CommentColor = Console.BLUE private val KeywordColor = Console.YELLOW - private val ValDefColor = Console.CYAN - private val LiteralColor = Console.RED - private val StringColor = Console.GREEN + private val DefinitionColor = Console.CYAN + private val LiteralColor = Console.GREEN private val TypeColor = Console.GREEN - private val AnnotationColor = Console.GREEN def highlightKeyword(str: String): String = KeywordColor + str + NoColor - def highlightTypeDef(str: String): String = TypeColor + str + NoColor + def highlightType(str: String): String = TypeColor + str + NoColor def highlightLiteral(str: String): String = LiteralColor + str + NoColor - def highlightValDef(str: String): String = ValDefColor + str + NoColor - def highlightOperator(str: String): String = TypeColor + str + NoColor - def highlightAnnotation(str: String): String = AnnotationColor + str + NoColor - def highlightString(str: String): String = StringColor + str + NoColor + def highlightDefinition(str: String): String = DefinitionColor + str + NoColor def highlightTripleQs: String = Console.RED_B + "???" + NoColor } def plain: SyntaxHighlight = new SyntaxHighlight { def highlightKeyword(str: String): String = str - def highlightTypeDef(str: String): String = str + def highlightType(str: String): String = str def highlightLiteral(str: String): String = str - def highlightValDef(str: String): String = str - def highlightOperator(str: String): String = str - def highlightAnnotation(str: String): String = str - def highlightString(str: String): String = str + def highlightDefinition(str: String): String = str def highlightTripleQs: String = "???" } } diff --git a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala index 2a2510a95394..e4475e11ca08 100644 --- a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala +++ b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala @@ -16,11 +16,9 @@ class SyntaxHighlightingTests extends DottyTest { .replace(NoColor, ">") .replace(CommentColor, " ") - test("type Foo =", " =") - test("type Foo = Int", " = ") - test("type A = String | Int", " = ") - test("type B = String & Int", " = ") - test("type Id[A] = A", " [] = ") - test("type Foo = [X] =>> List[X]", " = [] =>> []") + test("type Foo", " ") + test("type Foo =", " =") + test("type Foo = Int", " = ") + test("type A = String | Int", " = ") + test("type B = String & Int", " = ") + test("type Id[A] = A", " [] = ") + test("type Foo = [X] =>> List[X]", " = [] =>> []") } @Test @@ -74,11 +72,11 @@ class SyntaxHighlightingTests extends DottyTest { @Test def annotations = { - test("@deprecated class Foo", " ") - test("@Test() class Foo", " ") - test("@Test(\"Hello\") class Foo", " ") - test("@Test(\"Hello\")(\"World\") class Foo", " ") - test("@annotation.tailrec def foo = 1", " = ") + test("@deprecated class Foo", " ") + test("@Test() class Foo", " ") + test("@Test(\"Hello\") class Foo", " ") + test("@Test(\"Hello\")(\"World\") class Foo", " ") + test("@annotation.tailrec def foo = 1", " = ") } @Test @@ -90,37 +88,37 @@ class SyntaxHighlightingTests extends DottyTest { @Test def valOrDefDef = { test("val", "") - test("val foo", " ") - test("val foo =", " =") - test("val foo = 123", " = ") + test("val foo", " ") + test("val foo =", " =") + test("val foo = 123", " = ") test( "val foo: List[List[Int]] = List(List(1))", - " : [[]] = (())" + " : [[]] = (())" ) test("var", "") - test("var foo", " ") - test("var foo:", " :") - test("var foo: Int", " : ") - test("var foo: Int =", " : =") - test("var foo: Int = 123", " : = ") + test("var foo", " ") + test("var foo:", " :") + test("var foo: Int", " : ") + test("var foo: Int =", " : =") + test("var foo: Int = 123", " : = ") test("def", "") - test("def foo", " ") - test("def foo(", " (") - test("def foo(bar", " (") - test("def foo(bar:", " (:") - test("def foo(bar: Int", " (: ") - test("def foo(bar: Int)", " (: )") - test("def foo(bar: Int):", " (: ):") - test("def foo(bar: Int): Int", " (: ): ") - test("def foo(bar: Int): Int =", " (: ): =") - test("def foo(bar: Int): Int = 123", " (: ): = ") - - test("def f1(x: Int) = 123", " (: ) = ") - test("def f2[T](x: T) = { 123 }", " [](: ) = { }") - - test("def f3[T[_", " [[_") + test("def foo", " ") + test("def foo(", " (") + test("def foo(bar", " (") + test("def foo(bar:", " (:") + test("def foo(bar: Int", " (: ") + test("def foo(bar: Int)", " (: )") + test("def foo(bar: Int):", " (: ):") + test("def foo(bar: Int): Int", " (: ): ") + test("def foo(bar: Int): Int =", " (: ): =") + test("def foo(bar: Int): Int = 123", " (: ): = ") + + test("def f1(x: Int) = 123", " (: ) = ") + test("def f2[T](x: T) = { 123 }", " [](: ) = { }") + + test("def f3[T[_", " [[_") } @Test @@ -133,47 +131,47 @@ class SyntaxHighlightingTests extends DottyTest { @Test def softKeywords = { - test("inline def foo = 1", " = ") - test("@inline def foo = 1", " = ") - test("class inline", " ") - test("val inline = 2", " = ") - test("def inline = 2", " = ") - test("def foo(inline: Int) = 2", " (: ) = ") + test("inline def foo = 1", " = ") + test("@inline def foo = 1", " = ") + test("class inline", " ") + test("val inline = 2", " = ") + test("def inline = 2", " = ") + test("def foo(inline: Int) = 2", " (: ) = ") test( """enum Foo: | case foo |end Foo""".stripMargin, - """ : - | - | """.stripMargin + """ : + | + | """.stripMargin ) test( """class Foo: |end Foo""".stripMargin, - """ : - | """.stripMargin + """ : + | """.stripMargin ) test( """object Foo: |end Foo""".stripMargin, - """ : - | """.stripMargin + """ : + | """.stripMargin ) test( """def foo = | () |end foo""".stripMargin, - """ = + """ = | () - | """.stripMargin + | """.stripMargin ) test( """val foo = | () |end foo""".stripMargin, - """ = + """ = | () - | """.stripMargin + | """.stripMargin ) } }