Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressing repetitive warnings in the global initialization checker #19898

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------

Expand Down Expand Up @@ -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
willerf marked this conversation as resolved.
Show resolved Hide resolved
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)
Loading