aboutsummaryrefslogtreecommitdiff
path: root/tests/run/nothingTypeDce.scala
blob: b1acb7d51ac862f77592de8663bd93076b2f0bf1 (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
// See comment in BCodeBodyBuilder

// -target:jvm-1.6 -Ybackend:GenBCode -Yopt:unreachable-code
// target enables stack map frames generation

class C {
  // can't just emit a call to ???, that returns value of type Nothing$ (not Int).
  def f1: Int = ???

  def f2: Int = throw new Error("")

  def f3(x: Boolean) = {
    var y = 0
    // cannot assign an object of type Nothing$ to Int
    if (x) y = ???
    else   y = 1
    y
  }

  def f4(x: Boolean) = {
    var y = 0
    // tests that whatever is emitted after the throw is valid (what? depends on opts, presence of stack map frames)
    if (x) y = throw new Error("")
    else   y = 1
    y
  }

  def f5(x: Boolean) = {
    // stack heights need to be the same. ??? looks to the jvm like returning a value of
    // type Nothing$, need to drop or throw it.
    println(
      if (x) { ???; 10 }
      else 20
    )
  }

  def f6(x: Boolean) = {
    println(
      if (x) { throw new Error(""); 10 }
      else 20
    )
  }

  def f7(x: Boolean) = {
    println(
      if (x) throw new Error("")
      else 20
    )
  }

  def f8(x: Boolean) = {
    println(
      if (x) throw new Error("")
      else 20
    )
  }
}

object Test extends dotty.runtime.LegacyApp {
  // creating an instance is enough to trigger bytecode verification for all methods,
  // no need to invoke the methods.
  new C()
}