@@ -1759,24 +1759,31 @@ class Objects:
1759
1759
if cls.isAllOf(Flags .JavaInterface ) then Bottom
1760
1760
else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
1761
1761
1762
+ def printTraceWhenMultiple (trace : Trace )(using Context ): String =
1763
+ if trace.toVector.size > 1 then
1764
+ Trace .buildStacktrace(trace, " The mutable state is created through: " + System .lineSeparator())
1765
+ else " "
1766
+
1762
1767
val mutateErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
1763
1768
def errorMutateOtherStaticObject (currentObj : ClassSymbol , addr : Heap .Addr )(using Trace , Context ) =
1764
1769
val otherObj = addr.owner
1770
+ val addr_trace = addr.getTrace
1765
1771
if mutateErrorSet.add((currentObj, otherObj)) then
1766
1772
val msg =
1767
1773
s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
1768
1774
" Mutating other static objects during the initialization of one static object is forbidden. " + Trace .show +
1769
- " The mutable state is created through: " + Trace .show( using addr.getTrace )
1775
+ printTraceWhenMultiple(addr_trace )
1770
1776
1771
1777
report.warning(msg, Trace .position)
1772
1778
1773
1779
val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
1774
1780
def errorReadOtherStaticObject (currentObj : ClassSymbol , addr : Heap .Addr )(using Trace , Context ) =
1775
1781
val otherObj = addr.owner
1782
+ val addr_trace = addr.getTrace
1776
1783
if readErrorSet.add((currentObj, otherObj)) then
1777
1784
val msg =
1778
1785
" Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
1779
1786
" Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace .show +
1780
- " The mutable state is created through: " + Trace .show( using addr.getTrace )
1787
+ printTraceWhenMultiple(addr_trace )
1781
1788
1782
1789
report.warning(msg, Trace .position)
0 commit comments