diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-07 09:35:05 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-07 09:43:04 +1000 |
commit | e1377aa06ffe817d15315bbce3a6a636f2dd1f0e (patch) | |
tree | 9462ab70a38a58519e7885f93b37d9f9be35382a /src/main/scala/scala/async/internal/AnfTransform.scala | |
parent | 9da0183d3932a432da312cce29184aaac788facb (diff) | |
download | scala-async-e1377aa06ffe817d15315bbce3a6a636f2dd1f0e.tar.gz scala-async-e1377aa06ffe817d15315bbce3a6a636f2dd1f0e.tar.bz2 scala-async-e1377aa06ffe817d15315bbce3a6a636f2dd1f0e.zip |
Avoid compiler warning when awaiting Future[Unit]
During the ANF transform, we were generating a tree of the shape:
{
val temp: Unit = await(futureOfUnit)
temp
()
}
I tried to simplifiy this to avoid creating the temporary value,
but this proved difficult as it would have required changes to
the subsequent state machine transformation.
Even replacing `temp` with `()` made the state machine transform
harder.
So for now, I've just inserted `temp.asInstanceOf[Unit]` to hide
from the compiler warning.
Fixes #74
(cherry picked from commit f3f058991b207a07041672a7e119422d9054788d)
Diffstat (limited to 'src/main/scala/scala/async/internal/AnfTransform.scala')
-rw-r--r-- | src/main/scala/scala/async/internal/AnfTransform.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/scala/scala/async/internal/AnfTransform.scala b/src/main/scala/scala/async/internal/AnfTransform.scala index bf66fde..3c8c837 100644 --- a/src/main/scala/scala/async/internal/AnfTransform.scala +++ b/src/main/scala/scala/async/internal/AnfTransform.scala @@ -73,7 +73,17 @@ private[async] trait AnfTransform { expr match { case Apply(fun, args) if isAwait(fun) => val valDef = defineVal(name.await, expr, tree.pos) - stats :+ valDef :+ atPos(tree.pos)(gen.mkAttributedStableRef(valDef.symbol)).setType(tree.tpe) + val ref = gen.mkAttributedStableRef(valDef.symbol).setType(tree.tpe) + val ref1 = if (ref.tpe =:= definitions.UnitTpe) + // https://github.com/scala/async/issues/74 + // Use a cast to hide from "pure expression does nothing" error + // + // TODO avoid creating a ValDef for the result of this await to avoid this tree shape altogether. + // This will require some deeper changes to the later parts of the macro which currently assume regular + // tree structure around `await` calls. + gen.mkCast(ref, definitions.UnitTpe) + else ref + stats :+ valDef :+ atPos(tree.pos)(ref1) case If(cond, thenp, elsep) => // if type of if-else is Unit don't introduce assignment, |