Aladdin - Scala Bugtracking
[#1194] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Stephane Iulian fixed 2007-07-02 14:03:28.0
subject Overriding lazy values
code
class A {
  val x: Int = { print("/*A.x*/"); 2 }
  lazy val y: Int = { print("/*A.y*/"); 2 }
}

class B extends A {
  override val x: Int = { print("/*B.x*/"); 3 }
  override lazy val y: Int = { print("/*B.y*/"); 3 }
}

object test extends Application {
 val a = new A
 print("a.x=")
 println(a.x)

 val b = new B
 print("b.x=")
 println(b.x) 
}
what happened
test.scala:8: error: error overriding variable y in class A of type Int;
 variable y cannot override a mutable variable
  override lazy val y: Int = { print("/*B.y*/"); 3 }
                    ^
one error found
what expected No error (?!) or at least a better error message
[back to overview]
Changes of this bug report
Iulian  edited on  2007-07-02 15:40:49.0
It's allowed now. Lazy values behave as normal values w.r.t. to overriding rules.