File tree 3 files changed +13
-6
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -474,11 +474,7 @@ object RefChecks {
474
474
overrideError(" needs `override` modifier" )
475
475
else if (other.is(AbsOverride ) && other.isIncompleteIn(clazz) && ! member.is(AbsOverride ))
476
476
overrideError(" needs `abstract override` modifiers" )
477
- else if member.is(Override )
478
- && (other.is(Mutable )
479
- || other.is(Accessor , butNot = Deferred )
480
- && other.accessedFieldOrGetter.is(Mutable , butNot = Lazy ))
481
- then
477
+ else if member.is(Override ) && other.is(Mutable ) then
482
478
overrideError(" cannot override a mutable variable" )
483
479
else if (member.isAnyOverride &&
484
480
! (member.owner.thisType.baseClasses exists (_ isSubClass other.owner)) &&
Original file line number Diff line number Diff line change @@ -10,4 +10,4 @@ class Ok2C extends Ok2 { override var i: Int = 1 }
10
10
11
11
// was: variable i of type Int cannot override a mutable variable
12
12
trait NotOk {var i : Int }
13
- class NotOkC extends NotOk { override var i : Int = 1 }
13
+ class NotOkC extends NotOk { override var i : Int = 1 } // error
Original file line number Diff line number Diff line change @@ -7,3 +7,14 @@ object Test extends App {
7
7
entity.id = " 0002"
8
8
println(entity.id)
9
9
}
10
+
11
+ trait HasId2 :
12
+ var id : String = " "
13
+
14
+ case class Entity2 (override val id : String ) extends HasId2 // error
15
+
16
+ trait HasId3 :
17
+ def id : String
18
+ def id_= (x : String ): Unit
19
+
20
+ case class Entity3 (override var id : String ) extends HasId3 // ok
You can’t perform that action at this time.
0 commit comments