@@ -65,7 +65,7 @@ import scala.annotation.constructorOnly
6565 * whole-program analysis. However, the check is not modular in terms of project boundaries.
6666 *
6767 */
68- object Objects :
68+ class Objects :
6969
7070 // ----------------------------- abstract domain -----------------------------
7171
@@ -1734,16 +1734,20 @@ 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.add((currentObj, otherObj)) then
1740+ val msg =
1741+ s " Mutating ${otherObj.show} during initialization of ${currentObj.show}. \n " +
1742+ " Mutating other static objects during the initialization of one static object is forbidden. " + Trace .show
17411743
1742- report.warning(msg, Trace .position)
1744+ report.warning(msg, Trace .position)
17431745
1746+ val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
17441747 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
1748+ if readErrorSet.add((currentObj, otherObj)) then
1749+ val msg =
1750+ " Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + " .\n " +
1751+ " Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace .show
17481752
1749- report.warning(msg, Trace .position)
1753+ report.warning(msg, Trace .position)
0 commit comments