Skip to content

Commit 3124430

Browse files
authored
Fix #24440: Do not check public flexible types on artifact symbols or inside anonymous classes (#24471)
Fix #24440
2 parents 656f2c5 + 1a72dc6 commit 3124430

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,9 @@ object RefChecks {
12021202
/** Check that public (and protected) methods/fields do not expose flexible types. */
12031203
def checkPublicFlexibleTypes(sym: Symbol)(using Context): Unit =
12041204
if ctx.explicitNulls && !ctx.isJava
1205-
&& sym.exists && !sym.is(Private) && sym.owner.isClass
1206-
&& !sym.isOneOf(Synthetic | InlineProxy | Param | Exported) then
1205+
&& sym.exists && sym.owner.isClass
1206+
&& !sym.owner.isAnonymousClass
1207+
&& !sym.isOneOf(JavaOrPrivateOrSynthetic | InlineProxy | Param | Exported) then
12071208
val resTp = sym.info.finalResultType
12081209
if resTp.existsPart(_.isInstanceOf[FlexibleType], StopAt.Static) then
12091210
report.warning(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//> using options -Yexplicit-nulls -Werror
2+
3+
trait AwtComponentLogging extends java.awt.Component:
4+
5+
override def getPreferredSize: java.awt.Dimension =
6+
val dim: java.awt.Dimension = super.getPreferredSize
7+
dim
8+
9+
private def superPS1 = super.getPreferredSize
10+
11+
private val superPS2 = super.getPreferredSize
12+
13+
class Test:
14+
def getCompoment: java.awt.Component =
15+
new java.awt.Component {
16+
override def getPreferredSize = super.getPreferredSize
17+
}

0 commit comments

Comments
 (0)