diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 1006044e851d..7037a9a986aa 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1202,8 +1202,9 @@ 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.owner.isAnonymousClass + && !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..0ef3e88e7cf7 --- /dev/null +++ b/tests/explicit-nulls/pos/i24440.scala @@ -0,0 +1,17 @@ +//> 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 + +class Test: + def getCompoment: java.awt.Component = + new java.awt.Component { + override def getPreferredSize = super.getPreferredSize + } \ No newline at end of file