Skip to content

Commit 0dd88e5

Browse files
committed
Rewrite non-local return
1 parent 5fa3c8b commit 0dd88e5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

compiler/shared/main/scala/mlscript/compiler/ir/Interp.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import scala.collection.immutable._
99
import scala.annotation._
1010
import shorthands._
1111
import scala.collection.mutable.ListBuffer
12+
import scala.util.boundary, boundary.break
1213

1314
enum Stuck:
1415
case StuckExpr(expr: Expr, msg: Str)
@@ -102,12 +103,13 @@ class Interpreter(verbose: Bool):
102103
case Value.Class(cls2, xs) => L(StuckExpr(expr, s"unexpected class $cls2"))
103104
case x => L(StuckExpr(expr, s"unexpected value $x"))
104105
}
105-
case BasicOp(name, args) =>
106+
case BasicOp(name, args) => boundary:
106107
evalArgs(args).flatMap(
107108
xs =>
108109
name match
109110
case "+" | "-" | "*" | "/" | "==" | "!=" | "<=" | ">=" | "<" | ">" =>
110-
if xs.length < 2 then return L(StuckExpr(expr, s"not enough arguments for basic operation $name"))
111+
if xs.length < 2 then break:
112+
L(StuckExpr(expr, s"not enough arguments for basic operation $name"))
111113
else eval(name, xs.head, xs.tail.head).toRight(StuckExpr(expr, s"unable to evaluate basic operation"))
112114
case _ => L(StuckExpr(expr, s"unexpected basic operation $name")))
113115
case AssignField(assignee, cls, field, value) =>

0 commit comments

Comments
 (0)