diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-05-12 18:30:53 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-05-12 18:30:53 +0200 |
commit | 89bacb9c25a58454ff1878e67f7ea07ffc8c269f (patch) | |
tree | 51f1ff6c66aebe1b6109b1cffcc2bb8e4cf760a3 /tests/pending/run/t6863.scala | |
parent | a0fa33deafbea1bf53edc068c5ed9db5592822f9 (diff) | |
download | dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.tar.gz dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.tar.bz2 dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.zip |
Run tests as they were in scala.
Diffstat (limited to 'tests/pending/run/t6863.scala')
-rw-r--r-- | tests/pending/run/t6863.scala | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/pending/run/t6863.scala b/tests/pending/run/t6863.scala new file mode 100644 index 000000000..7210ebc01 --- /dev/null +++ b/tests/pending/run/t6863.scala @@ -0,0 +1,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() + } +} + |