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 {
19
19
}
20
20
21
21
/** 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 =
23
23
returner.throwReturn(result)
24
24
25
25
/** Enable nonlocal returns in `op`. */
Original file line number Diff line number Diff line change @@ -8,9 +8,20 @@ object Test {
8
8
false
9
9
}
10
10
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
+
11
20
def main (arg : Array [String ]): Unit = {
12
21
assert(has(1 :: 2 :: Nil , 1 ))
13
22
assert(has(1 :: 2 :: Nil , 2 ))
14
23
assert(! has(1 :: 2 :: Nil , 3 ))
24
+ assert(animal(1 ) == Cat )
25
+ assert(animal(- 1 ) == Dog )
15
26
}
16
- }
27
+ }
You can’t perform that action at this time.
0 commit comments