diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 7e0191048a9c..2b77606933d7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -382,7 +382,8 @@ class Typer extends Namer if !curOwner.is(Package) || isDefinedInCurrentUnit(defDenot) then result = checkNewOrShadowed(found, Definition) // no need to go further out, we found highest prec entry found match - case found: NamedType if curOwner.isClass && isInherited(found.denot) => + case found: NamedType + if curOwner.isClass && isInherited(found.denot) && !ctx.compilationUnit.isJava => checkNoOuterDefs(found.denot, ctx, ctx) case _ => else diff --git a/tests/pos/i13106.java b/tests/pos/i13106.java new file mode 100644 index 000000000000..6a10fd3cfa9b --- /dev/null +++ b/tests/pos/i13106.java @@ -0,0 +1,7 @@ +final class A { + public static final class C { } + public static final class D { + public static final class C { } + public C foo() { return new C(); } + } +}