File tree 2 files changed +46
-1
lines changed
main/scala/scala/async/internal
test/scala/scala/async/run
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,17 @@ private[async] trait AnfTransform {
51
51
expr match {
52
52
case Apply (fun, args) if isAwait(fun) =>
53
53
val valDef = defineVal(name.await, expr, tree.pos)
54
- stats :+ valDef :+ atPos(tree.pos)(gen.mkAttributedStableRef(valDef.symbol)).setType(tree.tpe)
54
+ val ref = gen.mkAttributedStableRef(valDef.symbol).setType(tree.tpe)
55
+ val ref1 = if (ref.tpe =:= definitions.UnitTpe )
56
+ // https://github.com/scala/async/issues/74
57
+ // Use a cast to hide from "pure expression does nothing" error
58
+ //
59
+ // TODO avoid creating a ValDef for the result of this await to avoid this tree shape altogether.
60
+ // This will require some deeper changes to the later parts of the macro which currently assume regular
61
+ // tree structure around `await` calls.
62
+ gen.mkCast(ref, definitions.UnitTpe )
63
+ else ref
64
+ stats :+ valDef :+ atPos(tree.pos)(ref1)
55
65
56
66
case If (cond, thenp, elsep) =>
57
67
// 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