diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 70525007707a..1523a07b02fd 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1066,7 +1066,6 @@ object SymDenotations { final def isEffectivelyFinal(using Context): Boolean = isOneOf(EffectivelyFinalFlags) || is(Inline, butNot = Deferred) - || is(JavaDefinedVal, butNot = Method) || !owner.isExtensibleClass /** A class is effectively sealed if has the `final` or `sealed` modifier, or it diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index bc7aef564173..ea70c712dc09 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -778,8 +778,10 @@ object RefChecks { ) def classDecls = inclazz.info.nonPrivateDecl(member.name) - (inclazz != clazz) && - classDecls.hasAltWith(d => isSignatureMatch(d.symbol) && javaAccessCheck(d.symbol)) + (inclazz != clazz) && classDecls.hasAltWith(d => + isSignatureMatch(d.symbol) && javaAccessCheck(d.symbol) && + !d.symbol.is(JavaDefinedVal, butNot = Method) // Java fields cannot be overriden + ) } // 4. Check that every defined member with an `override` modifier overrides some other member. diff --git a/tests/pos/i9392/J.java b/tests/pos/i9392/J.java new file mode 100644 index 000000000000..d2ad42cfc3c7 --- /dev/null +++ b/tests/pos/i9392/J.java @@ -0,0 +1,6 @@ +package pkg; + +public class J { + int i = 0; + public int i() { return 1; } +} diff --git a/tests/pos/i9392/S.scala b/tests/pos/i9392/S.scala new file mode 100644 index 000000000000..c094e773ce08 --- /dev/null +++ b/tests/pos/i9392/S.scala @@ -0,0 +1,17 @@ +class S1 extends pkg.J { + override def i(): Int = 2 +} + +class S2 extends pkg.J { + override def i: Int = 2 +} +object Test { + val s1 = new S1 + + val i1 = s1.i + val i2 = s1.i() + + val s2 = new S2 + + val i3 = s2.i +}