Skip to content

Commit 6fa5aea

Browse files
committed
Improve trace for TASTy without valid line numbers
Ref: scala#18882
1 parent 8cb4945 commit 6fa5aea

File tree

1 file changed

+10
-6
lines changed
  • compiler/src/dotty/tools/dotc/transform/init

1 file changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/transform/init/Trace.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ object Trace:
2222

2323
val empty: Trace = Vector.empty
2424

25+
val CONNECTING_INDENT = "\u2502 " // "| "
26+
val CHILD = "\u251c\u2500\u2500 " // "|-- "
27+
val LAST_CHILD = "\u2514\u2500\u2500 " // "\-- "
28+
2529
extension (trace: Trace)
2630
def add(node: Tree): Trace = trace :+ node
2731
def toVector: Vector[Tree] = trace
2832
def ++(trace2: Trace): Trace = trace ++ trace2
2933

30-
def show(using trace: Trace, ctx: Context): String = buildStacktrace(trace, "\n")
34+
def show(using trace: Trace, ctx: Context): String = buildStacktrace(trace, "")
3135

3236
def position(using trace: Trace): Tree = trace.last
3337

@@ -42,7 +46,6 @@ object Trace:
4246
var lines: mutable.ArrayBuffer[String] = new mutable.ArrayBuffer
4347
trace.foreach { tree =>
4448
val pos = tree.sourcePos
45-
val prefix = "-> "
4649
val line =
4750
if pos.source.exists then
4851
val loc = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
@@ -52,18 +55,19 @@ object Trace:
5255
tree match
5356
case defDef: DefTree =>
5457
// The definition can be huge, avoid printing the whole definition.
55-
defDef.symbol.show
58+
defDef.symbol.showFullName
5659
case _ =>
57-
tree.show
60+
tree.show.split(System.lineSeparator(), 2).nn.head.nn
5861
val positionMarkerLine =
5962
if pos.exists && pos.source.exists then
60-
positionMarker(pos)
63+
CONNECTING_INDENT + positionMarker(pos)
6164
else ""
6265

6366
// always use the more precise trace location
64-
if lastLineNum == pos.line then
67+
if lastLineNum >= 0 && lastLineNum == pos.line then
6568
lines.dropRightInPlace(1)
6669

70+
val prefix = if tree `eq` trace.last then LAST_CHILD else CHILD
6771
lines += (prefix + line + "\n" + positionMarkerLine)
6872

6973
lastLineNum = pos.line

0 commit comments

Comments
 (0)