@@ -65,7 +65,7 @@ import scala.annotation.constructorOnly
65
65
* whole-program analysis. However, the check is not modular in terms of project boundaries.
66
66
*
67
67
*/
68
- object Objects :
68
+ class Objects :
69
69
70
70
// ----------------------------- abstract domain -----------------------------
71
71
@@ -1734,16 +1734,20 @@ object Objects:
1734
1734
if cls.isAllOf(Flags .JavaInterface ) then Bottom
1735
1735
else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
1736
1736
1737
+ val mutateErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
1737
1738
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
1741
1743
1742
- report.warning(msg, Trace .position)
1744
+ report.warning(msg, Trace .position)
1743
1745
1746
+ val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
1744
1747
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
1748
1752
1749
- report.warning(msg, Trace .position)
1753
+ report.warning(msg, Trace .position)
0 commit comments