From b5562936e14c8b405c875f502efe3185bf0397ca Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Tue, 18 Nov 2025 14:00:21 +0100 Subject: [PATCH 1/2] Do not check public flexible types on artifact symbols --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 4 ++-- tests/explicit-nulls/pos/i24440.scala | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/explicit-nulls/pos/i24440.scala diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 1006044e851d..adc3fe75046e 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1202,8 +1202,8 @@ object RefChecks { /** Check that public (and protected) methods/fields do not expose flexible types. */ def checkPublicFlexibleTypes(sym: Symbol)(using Context): Unit = if ctx.explicitNulls && !ctx.isJava - && sym.exists && !sym.is(Private) && sym.owner.isClass - && !sym.isOneOf(Synthetic | InlineProxy | Param | Exported) then + && sym.exists && sym.owner.isClass + && !sym.isOneOf(JavaOrPrivateOrSynthetic | InlineProxy | Param | Exported) then val resTp = sym.info.finalResultType if resTp.existsPart(_.isInstanceOf[FlexibleType], StopAt.Static) then report.warning( diff --git a/tests/explicit-nulls/pos/i24440.scala b/tests/explicit-nulls/pos/i24440.scala new file mode 100644 index 000000000000..93800a023f82 --- /dev/null +++ b/tests/explicit-nulls/pos/i24440.scala @@ -0,0 +1,11 @@ +//> using options -Yexplicit-nulls -Werror + +trait AwtComponentLogging extends java.awt.Component: + + override def getPreferredSize: java.awt.Dimension = + val dim: java.awt.Dimension = super.getPreferredSize + dim + + private def superPS1 = super.getPreferredSize + + private val superPS2 = super.getPreferredSize From 1a72dc6ee3b054631054e4fc5f5ba51f22c4eeb1 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Tue, 18 Nov 2025 14:06:06 +0100 Subject: [PATCH 2/2] Prevent checking public flexible types on anonymous classes --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 1 + tests/explicit-nulls/pos/i24440.scala | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index adc3fe75046e..7037a9a986aa 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1203,6 +1203,7 @@ object RefChecks { def checkPublicFlexibleTypes(sym: Symbol)(using Context): Unit = if ctx.explicitNulls && !ctx.isJava && sym.exists && sym.owner.isClass + && !sym.owner.isAnonymousClass && !sym.isOneOf(JavaOrPrivateOrSynthetic | InlineProxy | Param | Exported) then val resTp = sym.info.finalResultType if resTp.existsPart(_.isInstanceOf[FlexibleType], StopAt.Static) then diff --git a/tests/explicit-nulls/pos/i24440.scala b/tests/explicit-nulls/pos/i24440.scala index 93800a023f82..0ef3e88e7cf7 100644 --- a/tests/explicit-nulls/pos/i24440.scala +++ b/tests/explicit-nulls/pos/i24440.scala @@ -9,3 +9,9 @@ trait AwtComponentLogging extends java.awt.Component: private def superPS1 = super.getPreferredSize private val superPS2 = super.getPreferredSize + +class Test: + def getCompoment: java.awt.Component = + new java.awt.Component { + override def getPreferredSize = super.getPreferredSize + } \ No newline at end of file