diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 8d96d256a881..4a0db540ca2d 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -474,7 +474,7 @@ object RefChecks { overrideError("needs `override` modifier") else if (other.is(AbsOverride) && other.isIncompleteIn(clazz) && !member.is(AbsOverride)) overrideError("needs `abstract override` modifiers") - else if member.is(Override) && other.is(Accessor, butNot = Deferred) && other.accessedFieldOrGetter.is(Mutable, butNot = Lazy) then + else if member.is(Override) && other.is(Mutable) then overrideError("cannot override a mutable variable") else if (member.isAnyOverride && !(member.owner.thisType.baseClasses exists (_ isSubClass other.owner)) && diff --git a/tests/pos/i13019.scala b/tests/neg/i13019.scala similarity index 80% rename from tests/pos/i13019.scala rename to tests/neg/i13019.scala index 491b6df03d0b..7f0958df083c 100644 --- a/tests/pos/i13019.scala +++ b/tests/neg/i13019.scala @@ -10,4 +10,4 @@ class Ok2C extends Ok2 { override var i: Int = 1 } // was: variable i of type Int cannot override a mutable variable trait NotOk {var i: Int} -class NotOkC extends NotOk { override var i: Int = 1 } +class NotOkC extends NotOk { override var i: Int = 1 } // error diff --git a/tests/neg/i14722.scala b/tests/neg/i14722.scala new file mode 100644 index 000000000000..c129eb42b53d --- /dev/null +++ b/tests/neg/i14722.scala @@ -0,0 +1,20 @@ +abstract class HasId(var id: String) + +case class Entity(override val id: String) extends HasId(id) // error + +object Test extends App { + val entity = Entity("0001") + entity.id = "0002" + println(entity.id) +} + +trait HasId2: + var id: String = "" + +case class Entity2(override val id: String) extends HasId2 // error + +trait HasId3: + def id: String + def id_=(x: String): Unit + +case class Entity3(override var id: String) extends HasId3 // ok