summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2007-08-23 09:55:45 +0000
committerIulian Dragos <jaguarul@gmail.com>2007-08-23 09:55:45 +0000
commit8d96aea0a2d626e78a2f6477cb739447a17be153 (patch)
tree020d35073560c70715eadd2841656a8715bebe7b
parent62cd29a17818625f9a0ec84ffdac827281ae6265 (diff)
downloadscala-8d96aea0a2d626e78a2f6477cb739447a17be153.tar.gz
scala-8d96aea0a2d626e78a2f6477cb739447a17be153.tar.bz2
scala-8d96aea0a2d626e78a2f6477cb739447a17be153.zip
Fixed bug #1287, lazy vals in trait methods.
-rw-r--r--src/compiler/scala/tools/nsc/transform/LazyVals.scala4
-rw-r--r--test/files/run/lazy-traits.scala7
2 files changed, 10 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
index e4cfa6029f..74fa713430 100644
--- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala
+++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
@@ -42,6 +42,8 @@ abstract class LazyVals extends Transform {
/** Perform the following transformations:
* - for a lazy accessor inside a method, make it check the initialization bitmap
* - for all methods, add enough int vars to allow one flag per lazy local value
+ * - remove ACCESSOR flags: accessors in traits are not statically implemented,
+ * but moved to the host class. local lazy values should be statically implemented.
*/
override def transform(tree: Tree): Tree = {
val sym = tree.symbol
@@ -51,7 +53,7 @@ abstract class LazyVals extends Transform {
val idx = lazyVals(sym.enclMethod)
val rhs1 = mkLazyDef(sym.enclMethod, super.transform(rhs), idx)
lazyVals(sym.owner) = idx + 1
- sym.resetFlag(LAZY)
+ sym.resetFlag(LAZY | ACCESSOR)
rhs1
} else
super.transform(rhs)
diff --git a/test/files/run/lazy-traits.scala b/test/files/run/lazy-traits.scala
index f91da7ed1a..6238813e8d 100644
--- a/test/files/run/lazy-traits.scala
+++ b/test/files/run/lazy-traits.scala
@@ -116,6 +116,13 @@ trait PrivateLazy {
/** Test successful compilation. */
class InheritPrivateLazy extends AnyRef with PrivateLazy {}
+/** Test successful compilation, see bug #1287. */
+trait LocalLazyVal {
+ def foo = {
+ lazy val next = 10 + 1
+ next
+ }
+}
object Test extends Application {