From 945b31e07fe0e2366c44a2cb03276933d38ac3c4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 8 Jun 2020 14:32:05 +0200 Subject: [PATCH] Fix #9115: Make Java-defined fields effectively final --- compiler/src/dotty/tools/dotc/core/Flags.scala | 2 +- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 1 + tests/neg/i9115/A.java | 3 +++ tests/neg/i9115/B.scala | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i9115/A.java create mode 100644 tests/neg/i9115/B.scala diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 0b8eb22034b0..d0ace2318974 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -308,7 +308,7 @@ object Flags { val (Given @ _, _, _) = newFlags(29, "given") /** Symbol is defined by a Java class */ - val (JavaDefined @ _, _, _) = newFlags(30, "") + val (JavaDefined @ _, JavaDefinedVal @ _, _) = newFlags(30, "") /** Symbol is implemented as a Java static */ val (JavaStatic @ _, JavaStaticTerm @ _, JavaStaticType @ _) = newFlags(31, "") diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index f51aec15c45d..ad8ca5eacfc2 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1158,6 +1158,7 @@ object SymDenotations { final def isEffectivelyFinal(implicit ctx: 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/tests/neg/i9115/A.java b/tests/neg/i9115/A.java new file mode 100644 index 000000000000..2c039ddf2693 --- /dev/null +++ b/tests/neg/i9115/A.java @@ -0,0 +1,3 @@ +public class A { + public String foo = "A"; +} diff --git a/tests/neg/i9115/B.scala b/tests/neg/i9115/B.scala new file mode 100644 index 000000000000..a82c8e10a198 --- /dev/null +++ b/tests/neg/i9115/B.scala @@ -0,0 +1,3 @@ +class B extends A { + override val foo: String = "B" // error +} \ No newline at end of file