@@ -1759,24 +1759,31 @@ class Objects:
17591759 if cls.isAllOf(Flags .JavaInterface ) then Bottom
17601760 else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
17611761
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+
17621767 val mutateErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17631768 def errorMutateOtherStaticObject (currentObj : ClassSymbol , addr : Heap .Addr )(using Trace , Context ) =
17641769 val otherObj = addr.owner
1770+ val addr_trace = addr.getTrace
17651771 if mutateErrorSet.add((currentObj, otherObj)) then
17661772 val msg =
17671773 s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
17681774 " 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 )
17701776
17711777 report.warning(msg, Trace .position)
17721778
17731779 val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17741780 def errorReadOtherStaticObject (currentObj : ClassSymbol , addr : Heap .Addr )(using Trace , Context ) =
17751781 val otherObj = addr.owner
1782+ val addr_trace = addr.getTrace
17761783 if readErrorSet.add((currentObj, otherObj)) then
17771784 val msg =
17781785 " Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
17791786 " 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 )
17811788
17821789 report.warning(msg, Trace .position)
0 commit comments