@@ -1734,16 +1734,24 @@ object Objects:
17341734 if cls.isAllOf(Flags .JavaInterface ) then Bottom
17351735 else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
17361736
1737+ val mutateErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17371738 def errorMutateOtherStaticObject (currentObj : ClassSymbol , otherObj : ClassSymbol )(using Trace , Context ) =
1738- val msg =
1739- s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
1740- " Mutating other static objects during the initialization of one static object is forbidden. " + Trace .show
1739+ if mutateErrorSet.contains((currentObj, otherObj)) then ()
1740+ else
1741+ mutateErrorSet += ((currentObj, otherObj))
1742+ val msg =
1743+ s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
1744+ " Mutating other static objects during the initialization of one static object is forbidden. " + Trace .show
17411745
1742- report.warning(msg, Trace .position)
1746+ report.warning(msg, Trace .position)
17431747
1748+ val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17441749 def errorReadOtherStaticObject (currentObj : ClassSymbol , otherObj : ClassSymbol )(using Trace , Context ) =
1745- val msg =
1746- " Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
1747- " Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace .show
1750+ if readErrorSet.contains((currentObj, otherObj)) then ()
1751+ else
1752+ readErrorSet += ((currentObj, otherObj))
1753+ val msg =
1754+ " Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
1755+ " Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace .show
17481756
1749- report.warning(msg, Trace .position)
1757+ report.warning(msg, Trace .position)
0 commit comments