From ac226f26d8f54c79c642ed88bc5c48916afeb61b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 4 Aug 2015 18:34:10 -0700 Subject: Implement non-local returns Non-local returns are now implemented. --- tests/run/nonLocalReturns.scala | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/run/nonLocalReturns.scala (limited to 'tests/run/nonLocalReturns.scala') 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) + } +} -- cgit v1.2.3