diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-03-27 14:39:39 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-03-27 14:52:00 +0100 |
commit | ee66e081ad0dec0e0c20fbb7e40fd20122bba238 (patch) | |
tree | 354938b6e0e3ab18bf89f7d8090456fb767f3509 /src/test/scala/scala/async | |
parent | 6808ce4a4023becd984ebe06805d1eeb844694e1 (diff) | |
download | scala-async-ee66e081ad0dec0e0c20fbb7e40fd20122bba238.tar.gz scala-async-ee66e081ad0dec0e0c20fbb7e40fd20122bba238.tar.bz2 scala-async-ee66e081ad0dec0e0c20fbb7e40fd20122bba238.zip |
[backport] Allow lazy vals without await in the initializer
We were incorrectly typechecking the `ClassDef` of the state machine
in the macro in a way that discarded the resulting trees, and only
kept around the symbol.
The led to the the macro engine retypechecking
that node, which somehow led to duplicated lazy val initiaializer
`DefDef`-s in the template, which manifest as a `VerifyError`.
This commit:
- rescues the typechecked `ClassDef` node from the eager
typechecking by the macro
- loosens the restriction on lazy vals in async blocks. They are
still prohibited if they contain an await on the RHS
- Adds a test that shows evalution is indeed lazy.
(cherry picked from commit cc4587b1985519f7049d0feb0783d8e22c10f792)
Conflicts:
src/main/scala/scala/async/internal/AsyncAnalysis.scala
src/main/scala/scala/async/internal/AsyncTransform.scala
Diffstat (limited to 'src/test/scala/scala/async')
-rw-r--r-- | src/test/scala/scala/async/neg/NakedAwait.scala | 4 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/lazyval/LazyValSpec.scala | 34 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/test/scala/scala/async/neg/NakedAwait.scala b/src/test/scala/scala/async/neg/NakedAwait.scala index 9778c72..f9264c7 100644 --- a/src/test/scala/scala/async/neg/NakedAwait.scala +++ b/src/test/scala/scala/async/neg/NakedAwait.scala @@ -163,10 +163,10 @@ class NakedAwait { @Test def lazyValIllegal() { - expectError("lazy vals are illegal") { + expectError("await must not be used under a lazy val initalizer") { """ | import _root_.scala.async.internal.AsyncId._ - | def foo(): Any = async { val x = { lazy val y = 0; y } } + | def foo(): Any = async { val x = { lazy val y = await(0); y } } | () | |""".stripMargin diff --git a/src/test/scala/scala/async/run/lazyval/LazyValSpec.scala b/src/test/scala/scala/async/run/lazyval/LazyValSpec.scala new file mode 100644 index 0000000..6214b43 --- /dev/null +++ b/src/test/scala/scala/async/run/lazyval/LazyValSpec.scala @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2012-2014 Typesafe Inc. <http://www.typesafe.com> + */ + +package scala.async +package run +package lazyval + +import scala.async.run.noawait + +import scala.async.internal.AsyncId +import scala.async.internal.AsyncId +import AsyncId._ +import org.junit.Test +import scala.async.internal.AsyncId._ + +class LazyValSpec { + @Test + def lazyValAllowed() { + val result = async { + var x = 0 + lazy val y = { x += 1; 42 } + assert(x == 0, x) + val z = await(1) + val result = y + x + assert(x == 1, x) + identity(y) + assert(x == 1, x) + result + } + result mustBe 43 + } +} + |