File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
library/src/scala/util/control Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ object NonLocalReturns {
1919 }
2020
2121 /** Performs a nonlocal return by throwing an exception. */
22- def throwReturn [T ](result : T )(using returner : ReturnThrowable [T ]): Nothing =
22+ def throwReturn [T ](result : T )(using returner : ReturnThrowable [? >: T ]): Nothing =
2323 returner.throwReturn(result)
2424
2525 /** Enable nonlocal returns in `op`. */
Original file line number Diff line number Diff line change @@ -8,9 +8,20 @@ object Test {
88 false
99 }
1010
11+ trait Animal
12+ object Dog extends Animal
13+ object Cat extends Animal
14+
15+ def animal (arg : Int ): Animal = returning {
16+ if (arg < 0 ) throwReturn(Dog )
17+ Cat
18+ }
19+
1120 def main (arg : Array [String ]): Unit = {
1221 assert(has(1 :: 2 :: Nil , 1 ))
1322 assert(has(1 :: 2 :: Nil , 2 ))
1423 assert(! has(1 :: 2 :: Nil , 3 ))
24+ assert(animal(1 ) == Cat )
25+ assert(animal(- 1 ) == Dog )
1526 }
16- }
27+ }
You can’t perform that action at this time.
0 commit comments