diff options
author | Martin Odersky <odersky@gmail.com> | 2015-08-04 18:34:10 -0700 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-08-04 18:34:10 -0700 |
commit | ac226f26d8f54c79c642ed88bc5c48916afeb61b (patch) | |
tree | d6da7d399826b1652957e18504f10e64f41ae4d4 /tests/run/nonLocalReturns.scala | |
parent | 07e24e8640acf19a6bcedd1b68acbd7c8d8bf29b (diff) | |
download | dotty-ac226f26d8f54c79c642ed88bc5c48916afeb61b.tar.gz dotty-ac226f26d8f54c79c642ed88bc5c48916afeb61b.tar.bz2 dotty-ac226f26d8f54c79c642ed88bc5c48916afeb61b.zip |
Implement non-local returns
Non-local returns are now implemented.
Diffstat (limited to 'tests/run/nonLocalReturns.scala')
-rw-r--r-- | tests/run/nonLocalReturns.scala | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/run/nonLocalReturns.scala b/tests/run/nonLocalReturns.scala new file mode 100644 index 000000000..a425ac723 --- /dev/null +++ b/tests/run/nonLocalReturns.scala @@ -0,0 +1,32 @@ +object Test { + + def foo(xs: List[Int]): Int = { + xs.foreach(x => return x) + 0 + } + + def bar(xs: List[Int]): Int = { + lazy val y = if (xs.isEmpty) return -1 else xs.head + y + } + + def baz(x: Int): Int = + byName { return -2; 3 } + + def byName(x: => Int): Int = x + + def bam(): Int = { // no non-local return needed here + val foo = { + return -3 + 3 + } + foo + } + + def main(args: Array[String]) = { + assert(foo(List(1, 2, 3)) == 1) + assert(bar(Nil) == -1) + assert(baz(3) == -2) + assert(bam() == -3) + } +} |