aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-03-27 14:39:39 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-03-27 14:53:28 +0100
commitf38a2f78243b4cc481d7150e78adef2b2f8afc8d (patch)
tree2548b81364d77bb97583c99b2c06b520c44c8ad0 /src/test/scala/scala/async/run
parentbdb1686c00a7fc9304c91eb5418a83529ab935fc (diff)
downloadscala-async-f38a2f78243b4cc481d7150e78adef2b2f8afc8d.tar.gz
scala-async-f38a2f78243b4cc481d7150e78adef2b2f8afc8d.tar.bz2
scala-async-f38a2f78243b4cc481d7150e78adef2b2f8afc8d.zip
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. Fixes #52
Diffstat (limited to 'src/test/scala/scala/async/run')
-rw-r--r--src/test/scala/scala/async/run/lazyval/LazyValSpec.scala34
1 files changed, 34 insertions, 0 deletions
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
+ }
+}
+