blob: 409f70ac53635826f714d9adb11230d445b31821 (
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
|
package scala.async
package run
package nesteddef
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
import scala.async.internal.AsyncId
@RunWith(classOf[JUnit4])
class NestedDef {
@Test
def nestedDef() {
import AsyncId._
val result = async {
val a = 0
val x = await(a) - 1
val local = 43
def bar(d: Double) = -d + a + local
def foo(z: Any) = (a.toDouble, bar(x).toDouble, z)
foo(await(2))
}
result mustBe ((0d, 44d, 2))
}
@Test
def nestedFunction() {
import AsyncId._
val result = async {
val a = 0
val x = await(a) - 1
val local = 43
val bar = (d: Double) => -d + a + local
val foo = (z: Any) => (a.toDouble, bar(x).toDouble, z)
foo(await(2))
}
result mustBe ((0d, 44d, 2))
}
// We must lift `foo` and `bar` in the next two tests.
@Test
def nestedDefTransitive1() {
import AsyncId._
val result = async {
val a = 0
val x = await(a) - 1
def bar = a
def foo = bar
foo
}
result mustBe 0
}
@Test
def nestedDefTransitive2() {
import AsyncId._
val result = async {
val a = 0
val x = await(a) - 1
def bar = a
def foo = bar
0
}
result mustBe 0
}
// checking that our use/definition analysis doesn't cycle.
@Test
def mutuallyRecursive1() {
import AsyncId._
val result = async {
val a = 0
val x = await(a) - 1
def foo: Int = if (true) 0 else bar
def bar: Int = if (true) 0 else foo
bar
}
result mustBe 0
}
// checking that our use/definition analysis doesn't cycle.
@Test
def mutuallyRecursive2() {
import AsyncId._
val result = async {
val a = 0
def foo: Int = if (true) 0 else bar
def bar: Int = if (true) 0 else foo
val x = await(a) - 1
bar
}
result mustBe 0
}
}
|