From 981424b376e8e66253c2ec863ca1222e41d8b374 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 21 Sep 2012 14:10:33 +0200 Subject: Closes SI-6358. Move accessor generation for lazy vals to typers. Until now lazy accessors were handled somehow special because their symbol was created in typers but the corresponding tree was only added in Refchecks. This irregularity caused serious problems for value classes. Also it now looks just better when lazy value is treated in a similar way as other fields. I needed to adapt reifier so that it handles the new implementation correctly. Previously it had to recreate lazy val only by removing defdef and renaming. Now we basically need to recreate lazy val from scratch. There is one minor change to cps plugin but that is still fine because lazy vals were never really part of the transformation. Some range positions needed to be fixed manually. We could do it at the creation time but that would require a lot more "if (symbol.isLazy)" conditions for MethodSyntheis and Symbol/Tree creation and would just unnecessary complicate api. If someone has a better idea, please speak up. Range positions changes were necessary because previously accessors were created at refchecks and they weren't checked by validator (even though they were wrong). This commit removes lazy val implementation restriction introduced for 2.10.0. --- test/files/continuations-neg/lazy.check | 8 +++----- test/files/neg/valueclasses-impl-restrictions.check | 12 ++++-------- test/files/neg/valueclasses-impl-restrictions.scala | 1 - test/files/pos/t6358.scala | 6 ++++++ test/files/run/reify_lazyunit.check | 3 +++ test/files/run/reify_lazyunit.scala | 13 +++++++++++++ 6 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 test/files/pos/t6358.scala create mode 100644 test/files/run/reify_lazyunit.check create mode 100644 test/files/run/reify_lazyunit.scala (limited to 'test/files') diff --git a/test/files/continuations-neg/lazy.check b/test/files/continuations-neg/lazy.check index b8c6887409..3c460546be 100644 --- a/test/files/continuations-neg/lazy.check +++ b/test/files/continuations-neg/lazy.check @@ -1,6 +1,4 @@ -lazy.scala:5: error: type mismatch; - found : Unit @scala.util.continuations.cpsParam[Unit,Unit] - required: Unit - def foo() = { - ^ +lazy.scala:6: error: implementation restriction: cps annotations not allowed on lazy value definitions + lazy val x = shift((k:Unit=>Unit)=>k()) + ^ one error found diff --git a/test/files/neg/valueclasses-impl-restrictions.check b/test/files/neg/valueclasses-impl-restrictions.check index 17d07ba960..63924493aa 100644 --- a/test/files/neg/valueclasses-impl-restrictions.check +++ b/test/files/neg/valueclasses-impl-restrictions.check @@ -2,20 +2,16 @@ valueclasses-impl-restrictions.scala:3: error: implementation restriction: neste This restriction is planned to be removed in subsequent releases. object X ^ -valueclasses-impl-restrictions.scala:4: error: implementation restriction: lazy val is not allowed in value class -This restriction is planned to be removed in subsequent releases. - lazy val y = 1 - ^ -valueclasses-impl-restrictions.scala:10: error: implementation restriction: nested trait is not allowed in value class +valueclasses-impl-restrictions.scala:9: error: implementation restriction: nested trait is not allowed in value class This restriction is planned to be removed in subsequent releases. trait I2 { ^ -valueclasses-impl-restrictions.scala:16: error: implementation restriction: nested class is not allowed in value class +valueclasses-impl-restrictions.scala:15: error: implementation restriction: nested class is not allowed in value class This restriction is planned to be removed in subsequent releases. val i2 = new I2 { val q = x.s } ^ -valueclasses-impl-restrictions.scala:22: error: implementation restriction: nested class is not allowed in value class +valueclasses-impl-restrictions.scala:21: error: implementation restriction: nested class is not allowed in value class This restriction is planned to be removed in subsequent releases. private[this] class I2(val q: String) ^ -5 errors found +four errors found diff --git a/test/files/neg/valueclasses-impl-restrictions.scala b/test/files/neg/valueclasses-impl-restrictions.scala index 53396db958..137f3f854c 100644 --- a/test/files/neg/valueclasses-impl-restrictions.scala +++ b/test/files/neg/valueclasses-impl-restrictions.scala @@ -1,7 +1,6 @@ class M(val t: Int) extends AnyVal { def lazyString = { object X - lazy val y = 1 () => X } } diff --git a/test/files/pos/t6358.scala b/test/files/pos/t6358.scala new file mode 100644 index 0000000000..25539c885e --- /dev/null +++ b/test/files/pos/t6358.scala @@ -0,0 +1,6 @@ +class L(val t: Int) extends AnyVal { + def lazyString = { + lazy val x = t.toString + () => x + } +} diff --git a/test/files/run/reify_lazyunit.check b/test/files/run/reify_lazyunit.check new file mode 100644 index 0000000000..1b46c909be --- /dev/null +++ b/test/files/run/reify_lazyunit.check @@ -0,0 +1,3 @@ +12 +one +two diff --git a/test/files/run/reify_lazyunit.scala b/test/files/run/reify_lazyunit.scala new file mode 100644 index 0000000000..78b00cde28 --- /dev/null +++ b/test/files/run/reify_lazyunit.scala @@ -0,0 +1,13 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + reify { + lazy val x = { 0; println("12")} + x + println("one") + x + println("two") + }.eval +} + -- cgit v1.2.3