Skip to content

Commit a4c78a4

Browse files
committed
Always show current class at the top of trace
1 parent 43553ea commit a4c78a4

15 files changed

+228
-167
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import scala.collection.mutable
1313

1414
object Errors:
1515
sealed trait Error {
16-
def source: Tree
1716
def trace: Seq[Tree]
1817
def show(using Context): String
1918

19+
def pos(using Context): SourcePosition = trace.last.sourcePos
20+
2021
def issue(using Context): Unit =
21-
report.warning(show + stacktrace, source.srcPos)
22+
report.warning(show + stacktrace, this.pos)
2223

23-
private def isTraceInformative: Boolean =
24-
trace.size > 1 || trace.size == 1 && trace.head.ne(source)
24+
private def isTraceInformative(using Context): Boolean =
25+
trace.size > 1 || trace.size == 1 && trace.head.sourcePos.ne(pos)
2526

2627
def stacktrace(using Context): String = if !isTraceInformative then "" else " Calling trace:\n" + {
2728
var lastLineNum = -1
@@ -77,35 +78,34 @@ object Errors:
7778
def show(using Context): String =
7879
"Access non-initialized " + field.show + "."
7980

80-
override def issue(using Context): Unit =
81-
report.warning(show + stacktrace, field.srcPos)
81+
override def pos(using Context): SourcePosition = field.sourcePos
8282
}
8383

8484
/** Promote a value under initialization to fully-initialized */
85-
case class PromoteError(msg: String, source: Tree, trace: Seq[Tree]) extends Error {
85+
case class PromoteError(msg: String, trace: Seq[Tree]) extends Error {
8686
def show(using Context): String = msg
8787
}
8888

89-
case class AccessCold(field: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
89+
case class AccessCold(field: Symbol, trace: Seq[Tree]) extends Error {
9090
def show(using Context): String =
91-
"Access field " + source.show + " on a value with an unknown initialization status."
91+
"Access field on a value with an unknown initialization status."
9292
}
9393

94-
case class CallCold(meth: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
94+
case class CallCold(meth: Symbol, trace: Seq[Tree]) extends Error {
9595
def show(using Context): String =
96-
"Call method " + source.show + " on a value with an unknown initialization" + "."
96+
"Call method on a value with an unknown initialization" + "."
9797
}
9898

99-
case class CallUnknown(meth: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
99+
case class CallUnknown(meth: Symbol, trace: Seq[Tree]) extends Error {
100100
def show(using Context): String =
101101
val prefix = if meth.is(Flags.Method) then "Calling the external method " else "Accessing the external field"
102102
prefix + meth.show + " may cause initialization errors" + "."
103103
}
104104

105105
/** Promote a value under initialization to fully-initialized */
106-
case class UnsafePromotion(msg: String, source: Tree, trace: Seq[Tree], error: Error) extends Error {
106+
case class UnsafePromotion(msg: String, trace: Seq[Tree], error: Error) extends Error {
107107
override def issue(using Context): Unit =
108-
report.warning(show, source.srcPos)
108+
report.warning(show, this.pos)
109109

110110
def show(using Context): String = {
111111
var index = 0

0 commit comments

Comments
 (0)