summaryrefslogtreecommitdiff
path: root/test/files/run/t6863.scala
blob: 7210ebc01d02721cc232b3ac2b0d3d86e5a44d4c (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/** Make sure that when a variable is captured its initialization expression is handled properly */
object Test {
  def lazyVal() = {
  	// internally lazy vals become vars which are initialized with "_", so they need to be tested just like vars do
  	lazy val x = "42"
    assert({ () => x }.apply == "42")
  }
  def ident() = {
    val y = "42"
    var x = y
    assert({ () => x }.apply == "42")
  }
  def apply() = {
    def y(x : Int) = x.toString
    var x = y(42)
    assert({ () => x }.apply == "42")
  }
  def literal() = {
    var x = "42"
    assert({ () => x }.apply == "42")
  }
  def `new`() = {
    var x = new String("42")
    assert({ () => x }.apply == "42")
  }
  def select() = {
    object Foo{val bar = "42"}
    var x = Foo.bar
    assert({ () => x }.apply == "42")
  }
  def `throw`() = {
    var x = if (true) "42" else throw new Exception("42")
    assert({ () => x }.apply == "42")
  }
  def assign() = {
    var y = 1
    var x = y = 42
    assert({ () => x}.apply == ())
  }
  def valDef() = {
    var x = {val y = 42}
    assert({ () => x}.apply == ())
  }
  def `return`(): String = {
    var x = if (true) return "42" else ()
    assert({ () => x}.apply == ())
    "42"
  }
  def tryFinally() = {
    var x = try { "42" } finally ()
    assert({ () => x }.apply == "42")
  }
  def tryCatch() = {
    var x = try { "42" } catch { case _: Throwable => "43" }
    assert({ () => x }.apply == "42")
  }
  def `if`() = {
  	var x = if (true) ()
    assert({ () => x }.apply == ())
  }
  def ifElse() = {
    var x = if(true) "42" else "43"
    assert({ () => x }.apply == "42")
  }
  def matchCase() = {
    var x = 100 match {
       case 100 => "42"
      case _ => "43"
    }
    assert({ () => x }.apply == "42")
  }
  def block() = {
    var x = {
      val y = 42
      "42"
    }
    assert({ () => x }.apply == "42")
  }
  def labelDef() = {
    var x = 100 match {
      case 100 => try "42" finally ()
    }
    assert({ () => x }.apply == "42")
  }
  def nested() = {
    var x = {
      val y = 42
        if(true) try "42" catch {case _: Throwable => "43"}
        else "44"
    }
    assert({ () => x }.apply == "42")
  }
  def main(args: Array[String]) {
  	lazyVal()
    ident()
    apply()
    literal()
    `new`()
    select()
    `throw`()
    assign()
    valDef()
    `return`()
    tryFinally()
    tryCatch()
    ifElse()
    `if`()
    matchCase()
    block()
    labelDef()
    nested()
  }
}