Skip to content

Commit

Permalink
Fix #772 by parsing 'box <callExpr>' instead of 'box <ident>' (#779)
Browse files Browse the repository at this point in the history
Resolves #772 (if it works)

The only downside now is that box-unbox inference could get some super
weird and unexpected input. Oh well :)
  • Loading branch information
jiribenes authored Jan 15, 2025
1 parent eb7febb commit 1e58eea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions effekt/jvm/src/test/scala/effekt/RecursiveDescentTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class RecursiveDescentTests extends munit.FunSuite {
)
parseExpr("box { (x: Int) => x }")
parseExpr("box new Fresh { def fresh() = \"42\" }")
parseExpr("box foo()")
parseExpr("box bar(1)")
parseExpr("box baz(quux)")

// { f } is parsed as a capture set and not backtracked.
intercept[Throwable] { parseExpr("box { f }") }
Expand Down
2 changes: 1 addition & 1 deletion effekt/shared/src/main/scala/effekt/RecursiveDescent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class RecursiveDescent(positions: Positions, tokens: Seq[Token], source: Source)
val captures = `box` ~> backtrack(captureSet())
val expr = if (peek(`{`)) functionArg()
else if (peek(`new`)) newExpr()
else Var(idRef())
else callExpr()
Box(captures, expr)


Expand Down
7 changes: 7 additions & 0 deletions examples/neg/issue772.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def main(): Unit = {
def sayHelloTo(name: String): Unit =
println("Hello, " ++ name ++ "!")

val _ = box sayHelloTo("Jolene") // ERROR Unbox requires a boxed type, but got Unit.
()
}

0 comments on commit 1e58eea

Please sign in to comment.