@@ -66,7 +66,7 @@ import dotty.tools.dotc.core.Flags.AbstractOrTrait
6666 * whole-program analysis. However, the check is not modular in terms of project boundaries.
6767 *
6868 */
69- object Objects :
69+ class Objects :
7070
7171 // ----------------------------- abstract domain -----------------------------
7272
@@ -1757,16 +1757,20 @@ object Objects:
17571757 if cls.isAllOf(Flags .JavaInterface ) then Bottom
17581758 else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
17591759
1760+ val mutateErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17601761 def errorMutateOtherStaticObject (currentObj : ClassSymbol , otherObj : ClassSymbol )(using Trace , Context ) =
1761- val msg =
1762- s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
1763- " Mutating other static objects during the initialization of one static object is forbidden. " + Trace .show
1762+ if mutateErrorSet.add((currentObj, otherObj)) then
1763+ val msg =
1764+ s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
1765+ " Mutating other static objects during the initialization of one static object is forbidden. " + Trace .show
17641766
1765- report.warning(msg, Trace .position)
1767+ report.warning(msg, Trace .position)
17661768
1769+ val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17671770 def errorReadOtherStaticObject (currentObj : ClassSymbol , otherObj : ClassSymbol )(using Trace , Context ) =
1768- val msg =
1769- " Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
1770- " Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace .show
1771+ if readErrorSet.add((currentObj, otherObj)) then
1772+ val msg =
1773+ " Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
1774+ " Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace .show
17711775
1772- report.warning(msg, Trace .position)
1776+ report.warning(msg, Trace .position)
0 commit comments