diff options
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, 9 insertions, 3 deletions
diff --git a/src/main/scala/scala/async/internal/AnfTransform.scala b/src/main/scala/scala/async/internal/AnfTransform.scala index 3c8c837..e41c64e 100644 --- a/src/main/scala/scala/async/internal/AnfTransform.scala +++ b/src/main/scala/scala/async/internal/AnfTransform.scala @@ -70,6 +70,9 @@ private[async] trait AnfTransform { val stats :+ expr = anf.transformToList(tree) def statsExprUnit = stats :+ expr :+ localTyper.typedPos(expr.pos)(Literal(Constant(()))) + def statsExprThrow = + stats :+ expr :+ localTyper.typedPos(expr.pos)(Throw(Apply(Select(New(gen.mkAttributedRef(defn.IllegalStateExceptionClass)), nme.CONSTRUCTOR), Nil))) + expr match { case Apply(fun, args) if isAwait(fun) => val valDef = defineVal(name.await, expr, tree.pos) @@ -81,7 +84,7 @@ private[async] trait AnfTransform { // 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) + localTyper.typedPos(tree.pos)(gen.mkCast(ref, definitions.UnitTpe)) else ref stats :+ valDef :+ atPos(tree.pos)(ref1) @@ -90,6 +93,8 @@ private[async] trait AnfTransform { // but add Unit value to bring it into form expected by async transform if (expr.tpe =:= definitions.UnitTpe) { statsExprUnit + } else if (expr.tpe =:= definitions.NothingTpe) { + statsExprThrow } else { val varDef = defineVar(name.ifRes, expr.tpe, tree.pos) def branchWithAssign(orig: Tree) = localTyper.typedPos(orig.pos) { @@ -110,8 +115,9 @@ private[async] trait AnfTransform { // but add Unit value to bring it into form expected by async transform if (expr.tpe =:= definitions.UnitTpe) { statsExprUnit - } - else { + } else if (expr.tpe =:= definitions.NothingTpe) { + statsExprThrow + } else { val varDef = defineVar(name.matchRes, expr.tpe, tree.pos) def typedAssign(lhs: Tree) = localTyper.typedPos(lhs.pos)(Assign(Ident(varDef.symbol), mkAttributedCastPreservingAnnotations(lhs, varDef.symbol.tpe))) |