File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
main/scala/scala/async/internal
test/scala/scala/async/run Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,17 @@ private[async] trait AnfTransform {
7373 expr match {
7474 case Apply (fun, args) if isAwait(fun) =>
7575 val valDef = defineVal(name.await, expr, tree.pos)
76- stats :+ valDef :+ atPos(tree.pos)(gen.mkAttributedStableRef(valDef.symbol)).setType(tree.tpe)
76+ val ref = gen.mkAttributedStableRef(valDef.symbol).setType(tree.tpe)
77+ val ref1 = if (ref.tpe =:= definitions.UnitTpe )
78+ // https://github.com/scala/async/issues/74
79+ // Use a cast to hide from "pure expression does nothing" error
80+ //
81+ // TODO avoid creating a ValDef for the result of this await to avoid this tree shape altogether.
82+ // This will require some deeper changes to the later parts of the macro which currently assume regular
83+ // tree structure around `await` calls.
84+ gen.mkCast(ref, definitions.UnitTpe )
85+ else ref
86+ stats :+ valDef :+ atPos(tree.pos)(ref1)
7787
7888 case If (cond, thenp, elsep) =>
7989 // if type of if-else is Unit don't introduce assignment,
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (C) 2012-2014 Typesafe Inc. <http://www.typesafe.com>
3+ */
4+
5+ package scala .async
6+ package run
7+
8+ import org .junit .Test
9+
10+ import scala .async .internal .AsyncId
11+ import scala .concurrent .Await
12+ import scala .concurrent .duration ._
13+ import scala .language .{postfixOps , reflectiveCalls }
14+
15+
16+ class WarningsSpec {
17+
18+ @ Test
19+ // https://github.com/scala/async/issues/74
20+ def noPureExpressionInStatementPositionWarning_t74 () {
21+ val tb = mkToolbox(s " -cp ${toolboxClasspath} -Xfatal-warnings " )
22+ // was: "a pure expression does nothing in statement position; you may be omitting necessary parentheses"
23+ tb.eval(tb.parse {
24+ """
25+ | import scala.async.internal.AsyncId._
26+ | async {
27+ | if ("".isEmpty) {
28+ | await(println("hello"))
29+ | ()
30+ | } else 42
31+ | }
32+ """ .stripMargin
33+ })
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments