From ac40aa63e7430d8ece56c38b3c321383e2e432e5 Mon Sep 17 00:00:00 2001 From: willerf Date: Fri, 8 Mar 2024 08:36:42 -0500 Subject: [PATCH] suppress warnings in global init checker --- .../tools/dotc/transform/init/Checker.scala | 3 ++- .../tools/dotc/transform/init/Objects.scala | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Checker.scala b/compiler/src/dotty/tools/dotc/transform/init/Checker.scala index 7cf028c95064..692b3177786d 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Checker.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Checker.scala @@ -50,7 +50,8 @@ class Checker extends Phase: Semantic.checkClasses(classes)(using checkCtx) if ctx.settings.YcheckInitGlobal.value then - Objects.checkClasses(classes)(using checkCtx) + val obj = new Objects + obj.checkClasses(classes)(using checkCtx) } units0 diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 763b71619de8..39ce09ccfa23 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -65,7 +65,7 @@ import scala.annotation.constructorOnly * whole-program analysis. However, the check is not modular in terms of project boundaries. * */ -object Objects: +class Objects: // ----------------------------- abstract domain ----------------------------- @@ -1734,16 +1734,20 @@ object Objects: if cls.isAllOf(Flags.JavaInterface) then Bottom else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic) + val mutateErrorSet: mutable.Set[(ClassSymbol, ClassSymbol)] = mutable.Set.empty def errorMutateOtherStaticObject(currentObj: ClassSymbol, otherObj: ClassSymbol)(using Trace, Context) = - val msg = - s"Mutating ${otherObj.show} during initialization of ${currentObj.show}.\n" + - "Mutating other static objects during the initialization of one static object is forbidden. " + Trace.show + if mutateErrorSet.add((currentObj, otherObj)) then + val msg = + s"Mutating ${otherObj.show} during initialization of ${currentObj.show}.\n" + + "Mutating other static objects during the initialization of one static object is forbidden. " + Trace.show - report.warning(msg, Trace.position) + report.warning(msg, Trace.position) + val readErrorSet: mutable.Set[(ClassSymbol, ClassSymbol)] = mutable.Set.empty def errorReadOtherStaticObject(currentObj: ClassSymbol, otherObj: ClassSymbol)(using Trace, Context) = - val msg = - "Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + ".\n" + - "Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace.show + if readErrorSet.add((currentObj, otherObj)) then + val msg = + "Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + ".\n" + + "Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace.show - report.warning(msg, Trace.position) + report.warning(msg, Trace.position)