Skip to content

Commit a767c6b

Browse files
committed
Fix swallowing of warnings
If the span of an error message is too long (e.g., for a huge object definition), some warnings will be swallowed.
1 parent 7406ddb commit a767c6b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ object Objects:
252252
val joinedTrace = data.pendingTraces.slice(index + 1, data.checkingObjects.size).foldLeft(pendingTrace) { (a, acc) => acc ++ a }
253253
val callTrace = Trace.buildStacktrace(joinedTrace, "Calling trace:\n")
254254
val cycle = data.checkingObjects.slice(index, data.checkingObjects.size)
255-
val pos = clazz.defTree
255+
val pos = clazz.defTree.sourcePos.focus
256256
report.warning("Cyclic initialization: " + cycle.map(_.klass.show).mkString(" -> ") + " -> " + clazz.show + ". " + callTrace, pos)
257257
end if
258258
data.checkingObjects(index)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ object Trace:
4949
val code = SyntaxHighlighting.highlight(pos.lineContent.trim.nn)
5050
i"$code\t$loc"
5151
else
52-
tree.show
52+
tree match
53+
case defDef: DefTree =>
54+
// The definition can be huge, avoid printing the whole definition.
55+
defDef.symbol.show
56+
case _ =>
57+
tree.show
5358
val positionMarkerLine =
5459
if pos.exists && pos.source.exists then
5560
positionMarker(pos)

0 commit comments

Comments
 (0)