diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2007-07-02 13:39:23 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2007-07-02 13:39:23 +0000 |
commit | 510f9833512173798008198c86d86d1f10a24e15 (patch) | |
tree | df4069a1bf55ee48b0eccb1e584330e91edcd8c5 | |
parent | b0cee5943fd5d3ca077e000eafee4bde476c33d8 (diff) | |
download | scala-510f9833512173798008198c86d86d1f10a24e15.tar.gz scala-510f9833512173798008198c86d86d1f10a24e15.tar.bz2 scala-510f9833512173798008198c86d86d1f10a24e15.zip |
Fixed bug 1194, overriding lazy values.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 2 | ||||
-rw-r--r-- | test/files/run/lazy-override.check | 3 | ||||
-rw-r--r-- | test/files/run/lazy-override.scala | 29 |
4 files changed, 34 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 27458ad145..f5173a1219 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -989,6 +989,7 @@ trait Symbols { else if (isTrait) "trait" else if (isClass) "class" else if (isType) "type" + else if (isTerm && hasFlag(LAZY)) "lazy value" else if (isVariable) "variable" else if (isPackage) "package" else if (isModule) "object" diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 48ffb1a186..9880f88ff3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -179,7 +179,7 @@ abstract class RefChecks extends InfoTransform { } else if ((other hasFlag ABSOVERRIDE) && other.isIncompleteIn(clazz) && !(member hasFlag ABSOVERRIDE)) { overrideError("needs `abstract override' modifiers") } else if ((member hasFlag (OVERRIDE | ABSOVERRIDE)) && - (other hasFlag ACCESSOR) && other.accessed.isVariable) { + (other hasFlag ACCESSOR) && other.accessed.isVariable && !other.accessed.hasFlag(LAZY)) { overrideError("cannot override a mutable variable") } else if (other.isStable && !member.isStable) { // (1.4) overrideError("needs to be an immutable value") diff --git a/test/files/run/lazy-override.check b/test/files/run/lazy-override.check new file mode 100644 index 0000000000..225a9b120d --- /dev/null +++ b/test/files/run/lazy-override.check @@ -0,0 +1,3 @@ +/*A.x*/a.x=2 +/*A.x*//*B.y*/b.x=/*B.x*/3 +b.z=/*B.z/3 diff --git a/test/files/run/lazy-override.scala b/test/files/run/lazy-override.scala new file mode 100644 index 0000000000..0b72f60f03 --- /dev/null +++ b/test/files/run/lazy-override.scala @@ -0,0 +1,29 @@ +class A { + val x: Int = { print("/*A.x*/"); 2 } + lazy val y: Int = { print("/*A.y*/"); 2 } + lazy val z: Int = { print("/*A.z*/"); 2 } +} + +class B extends A { + // lazy overrides strict val + override lazy val x: Int = { print("/*B.x*/"); 3 } + // strict val overrides lazy + override val y: Int = { print("/*B.y*/"); 3 } + // lazy overrides lazy + override lazy val z: Int = { print("/*B.z/"); 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) + print("b.z=") + println(b.z) +} |