Skip to content

Commit ac40aa6

Browse files
committed
suppress warnings in global init checker
1 parent 21cfb15 commit ac40aa6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/init/Checker.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class Checker extends Phase:
5050
Semantic.checkClasses(classes)(using checkCtx)
5151

5252
if ctx.settings.YcheckInitGlobal.value then
53-
Objects.checkClasses(classes)(using checkCtx)
53+
val obj = new Objects
54+
obj.checkClasses(classes)(using checkCtx)
5455
}
5556

5657
units0

Diff for: compiler/src/dotty/tools/dotc/transform/init/Objects.scala

+13-9
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)