Skip to content

Commit 97d4b22

Browse files
committed
Refine stacktrace printing
1 parent c2d1a3c commit 97d4b22

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package init
55
import ast.tpd._
66

77
import core._
8-
import Decorators._
8+
import Decorators._, printing.SyntaxHighlighting
99
import Types._, Symbols._, Contexts._
10-
import util.NoSourcePosition
10+
import util.SourcePosition
1111

1212
import Effects._, Potentials._
1313

@@ -30,19 +30,22 @@ object Errors {
3030

3131
def stacktrace(implicit ctx: Context): String = if (trace.isEmpty) "" else " Calling trace:\n" + {
3232
var indentCount = 0
33-
var last = ""
33+
var last: String = ""
3434
val sb = new StringBuilder
3535
trace.foreach { tree =>
3636
indentCount += 1
3737
val pos = tree.sourcePos
38-
val line = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
39-
if (last != line)
40-
sb.append(
41-
if (pos.source.exists)
42-
i"${ " " * indentCount }-> ${pos.lineContent.trim}\t$line\n"
43-
else
44-
i"${tree.show}\n"
45-
)
38+
val prefix = s"${ " " * indentCount }-> "
39+
val line =
40+
if pos.source.exists then
41+
val loc = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
42+
val code = SyntaxHighlighting.highlight(pos.lineContent.trim)
43+
i"$code\t$loc"
44+
else
45+
tree.show
46+
47+
if (last != line) sb.append(prefix + line + "\n")
48+
4649
last = line
4750
}
4851
sb.toString

0 commit comments

Comments
 (0)