diff --git a/compiler/src/dotty/tools/dotc/transform/init/Trace.scala b/compiler/src/dotty/tools/dotc/transform/init/Trace.scala index dc9ab3bfc7a1..9988b5cd39e6 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Trace.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Trace.scala @@ -22,12 +22,16 @@ object Trace: val empty: Trace = Vector.empty + val CONNECTING_INDENT = "\u2502 " // "| " + val CHILD = "\u251c\u2500\u2500 " // "|-- " + val LAST_CHILD = "\u2514\u2500\u2500 " // "\-- " + extension (trace: Trace) def add(node: Tree): Trace = trace :+ node def toVector: Vector[Tree] = trace def ++(trace2: Trace): Trace = trace ++ trace2 - def show(using trace: Trace, ctx: Context): String = buildStacktrace(trace, "\n") + def show(using trace: Trace, ctx: Context): String = buildStacktrace(trace, "") def position(using trace: Trace): Tree = trace.last @@ -42,7 +46,6 @@ object Trace: var lines: mutable.ArrayBuffer[String] = new mutable.ArrayBuffer trace.foreach { tree => val pos = tree.sourcePos - val prefix = "-> " val line = if pos.source.exists then val loc = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]" @@ -52,18 +55,19 @@ object Trace: tree match case defDef: DefTree => // The definition can be huge, avoid printing the whole definition. - defDef.symbol.show + defDef.symbol.showFullName case _ => - tree.show + tree.show.split(System.lineSeparator(), 2).nn.head.nn val positionMarkerLine = if pos.exists && pos.source.exists then - positionMarker(pos) + CONNECTING_INDENT + positionMarker(pos) else "" // always use the more precise trace location - if lastLineNum == pos.line then + if lastLineNum >= 0 && lastLineNum == pos.line then lines.dropRightInPlace(1) + val prefix = if tree `eq` trace.last then LAST_CHILD else CHILD lines += (prefix + line + "\n" + positionMarkerLine) lastLineNum = pos.line