Skip to content

Commit 1e58eea

Browse files
authored
Fix #772 by parsing 'box <callExpr>' instead of 'box <ident>' (#779)
Resolves #772 (if it works) The only downside now is that box-unbox inference could get some super weird and unexpected input. Oh well :)
1 parent eb7febb commit 1e58eea

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

effekt/jvm/src/test/scala/effekt/RecursiveDescentTests.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class RecursiveDescentTests extends munit.FunSuite {
140140
)
141141
parseExpr("box { (x: Int) => x }")
142142
parseExpr("box new Fresh { def fresh() = \"42\" }")
143+
parseExpr("box foo()")
144+
parseExpr("box bar(1)")
145+
parseExpr("box baz(quux)")
143146

144147
// { f } is parsed as a capture set and not backtracked.
145148
intercept[Throwable] { parseExpr("box { f }") }

effekt/shared/src/main/scala/effekt/RecursiveDescent.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class RecursiveDescent(positions: Positions, tokens: Seq[Token], source: Source)
672672
val captures = `box` ~> backtrack(captureSet())
673673
val expr = if (peek(`{`)) functionArg()
674674
else if (peek(`new`)) newExpr()
675-
else Var(idRef())
675+
else callExpr()
676676
Box(captures, expr)
677677

678678

examples/neg/issue772.effekt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def main(): Unit = {
2+
def sayHelloTo(name: String): Unit =
3+
println("Hello, " ++ name ++ "!")
4+
5+
val _ = box sayHelloTo("Jolene") // ERROR Unbox requires a boxed type, but got Unit.
6+
()
7+
}

0 commit comments

Comments
 (0)