@@ -66,7 +66,7 @@ import dotty.tools.dotc.core.Flags.AbstractOrTrait
66
66
* whole-program analysis. However, the check is not modular in terms of project boundaries.
67
67
*
68
68
*/
69
- object Objects :
69
+ class Objects :
70
70
71
71
// ----------------------------- abstract domain -----------------------------
72
72
@@ -1757,16 +1757,20 @@ object Objects:
1757
1757
if cls.isAllOf(Flags .JavaInterface ) then Bottom
1758
1758
else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)
1759
1759
1760
+ val mutateErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
1760
1761
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
1764
1766
1765
- report.warning(msg, Trace .position)
1767
+ report.warning(msg, Trace .position)
1766
1768
1769
+ val readErrorSet : mutable.Set [(ClassSymbol , ClassSymbol )] = mutable.Set .empty
1767
1770
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
1771
1775
1772
- report.warning(msg, Trace .position)
1776
+ report.warning(msg, Trace .position)
0 commit comments