Open
Description
Compiler version
3.0.0
Minimized code
// no `override` - fine
trait Ok1 { var i: Int }
class Ok1C extends Ok1 { var i: Int = 1 }
// `override` of desugared `var` - fine
trait Ok2 {
def i: Int
def i_=(v: Int): Unit
}
class Ok2C extends Ok2 { override var i: Int = 1 }
// fails
trait NotOk {var i: Int}
class NotOkC extends NotOk { override var i: Int = 1 }
Output
error overriding variable i in trait NotOk of type Int;
variable i of type Int cannot override a mutable variable
Expectation
override
is used to implement abstract or re-implement concrete things, and guarantees their presence. In this case it seems impossible to use override
to implement an abstract var
.
The example compiles in scala 2