blob: c76168e5e6365ccf19a55c76b4adb845e375fcb7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Copyright (C) 2012-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package scala.async
package run
import org.junit.Test
import scala.language.{postfixOps, reflectiveCalls}
import scala.tools.nsc.reporters.StoreReporter
class WarningsSpec {
@Test
// https://github.com/scala/async/issues/74
def noPureExpressionInStatementPositionWarning_t74(): Unit = {
val tb = mkToolbox(s"-cp ${toolboxClasspath} -Xfatal-warnings")
// was: "a pure expression does nothing in statement position; you may be omitting necessary parentheses"
tb.eval(tb.parse {
"""
| import scala.async.internal.AsyncId._
| async {
| if ("".isEmpty) {
| await(println("hello"))
| ()
| } else 42
| }
""".stripMargin
})
}
@Test
// https://github.com/scala/async/issues/74
def noDeadCodeWarningForAsyncThrow() {
val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings -Ystop-after:refchecks")
// was: "a pure expression does nothing in statement position; you may be omitting necessary parentheses"
val source =
"""
| class Test {
| import scala.async.Async._
| import scala.concurrent.ExecutionContext.Implicits.global
| async { throw new Error() }
| }
""".stripMargin
val run = new global.Run
val sourceFile = global.newSourceFile(source)
run.compileSources(sourceFile :: Nil)
assert(!global.reporter.hasErrors, global.reporter.asInstanceOf[StoreReporter].infos)
}
@Test
def noDeadCodeWarningInMacroExpansion() {
val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings -Ystop-after:refchecks")
val source = """
| class Test {
| def test = {
| import scala.async.Async._, scala.concurrent._, ExecutionContext.Implicits.global
| async {
| val opt = await(async(Option.empty[String => Future[Unit]]))
| opt match {
| case None =>
| throw new RuntimeException("case a")
| case Some(f) =>
| await(f("case b"))
| }
| }
| }
|}
""".stripMargin
val run = new global.Run
val sourceFile = global.newSourceFile(source)
run.compileSources(sourceFile :: Nil)
assert(!global.reporter.hasErrors, global.reporter.asInstanceOf[StoreReporter].infos)
}
@Test
def ignoreNestedAwaitsInIDE_t1002561() {
// https://www.assembla.com/spaces/scala-ide/tickets/1002561
val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ystop-after:typer ")
val source = """
| class Test {
| def test = {
| import scala.async.Async._, scala.concurrent._, ExecutionContext.Implicits.global
| async {
| 1 + await({def foo = (async(await(async(2)))); foo})
| }
| }
|}
""".stripMargin
val run = new global.Run
val sourceFile = global.newSourceFile(source)
run.compileSources(sourceFile :: Nil)
assert(!global.reporter.hasErrors, global.reporter.asInstanceOf[StoreReporter].infos)
}
}
|