summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2009-01-15 15:20:57 +0000
committerIulian Dragos <jaguarul@gmail.com>2009-01-15 15:20:57 +0000
commitbc7db60a2535a38300b8eabe99bc0b95d3d2efe4 (patch)
treec954a76989c22d8d96b6ac298157cbf218c8c4e1
parente877601ffbf61d79c8241bcce948cdde99efb0f1 (diff)
downloadscala-bc7db60a2535a38300b8eabe99bc0b95d3d2efe4.tar.gz
scala-bc7db60a2535a38300b8eabe99bc0b95d3d2efe4.tar.bz2
scala-bc7db60a2535a38300b8eabe99bc0b95d3d2efe4.zip
Fix for #1589.
-rw-r--r--src/compiler/scala/tools/nsc/transform/LazyVals.scala5
-rw-r--r--test/files/run/lazy-locals.scala8
2 files changed, 12 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
index b53fa2fcf4..f3d74e3ed4 100644
--- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala
+++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
@@ -52,7 +52,8 @@ abstract class LazyVals extends Transform {
tree match {
case DefDef(mods, name, tparams, vparams, tpt, rhs) =>
val res = if (!sym.owner.isClass && sym.hasFlag(LAZY)) {
- val enclosingDummyOrMethod = if (sym.owner.isLocalDummy) sym.owner else sym.enclMethod
+ val enclosingDummyOrMethod =
+ if (sym.enclMethod == NoSymbol) sym.owner else sym.enclMethod
val idx = lazyVals(enclosingDummyOrMethod)
val rhs1 = mkLazyDef(enclosingDummyOrMethod, super.transform(rhs), idx)
lazyVals(sym.owner) = idx + 1
@@ -71,6 +72,8 @@ abstract class LazyVals extends Transform {
case Block(_, _) if !added =>
added = true
typed(addBitmapDefs(sym, stat))
+ case ValDef(mods, name, tpt, b @ Block(_, _)) =>
+ typed(copy.ValDef(stat, mods, name, tpt, addBitmapDefs(stat.symbol, b)))
case _ =>
stat
}
diff --git a/test/files/run/lazy-locals.scala b/test/files/run/lazy-locals.scala
index 000f4d2faf..5279901795 100644
--- a/test/files/run/lazy-locals.scala
+++ b/test/files/run/lazy-locals.scala
@@ -153,6 +153,14 @@ object Test extends Application {
}
}
+ // ticket #1589, should not crash
+ class Test {
+ val x = {
+ lazy val t = "abc";
+ t
+ }
+ }
+
println(testLazy)
testLazy32
testLazy33