Skip to content

Commit 03af9f5

Browse files
committed
Add capture checking to boundary and NonLocalReturns
1 parent a85c429 commit 03af9f5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

library/src/scala/util/boundary.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object boundary:
3838
/** Labels are targets indicating which boundary will be exited by a `break`.
3939
*/
4040
@implicitNotFound("explain=A Label is generated from an enclosing `scala.util.boundary` call.\nMaybe that boundary is missing?")
41-
final class Label[-T]
41+
final class Label[-T] extends caps.Control
4242

4343
/** Abort current computation and instead return `value` as the value of
4444
* the enclosing `boundary` call that created `label`.
@@ -60,7 +60,7 @@ object boundary:
6060
val local = Label[T]()
6161
try body(using local)
6262
catch case ex: Break[T] @unchecked =>
63-
if ex.label eq local then ex.value
63+
if ex.isSameLabelAs(local) then ex.value
6464
else throw ex
6565

6666
end boundary

library/src/scala/util/control/NonLocalReturns.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package scala.util.control
22

3+
import language.experimental.captureChecking
4+
35
import scala.compiletime.uninitialized
46

57
/** Library implementation of nonlocal return.
@@ -22,7 +24,7 @@ import scala.compiletime.uninitialized
2224
@deprecated("Use scala.util.boundary instead", "3.3")
2325
object NonLocalReturns {
2426
@deprecated("Use scala.util.boundary.Break instead", "3.3")
25-
class ReturnThrowable[T] extends ControlThrowable {
27+
class ReturnThrowable[T] extends ControlThrowable, caps.Control {
2628
private var myResult: T = uninitialized
2729
def throwReturn(result: T): Nothing = {
2830
myResult = result

0 commit comments

Comments
 (0)