fix: top level block, even isolated, is treated as a lambda too

This commit is contained in:
Sergey Chernov 2025-06-08 00:42:08 +04:00
parent c0cf190452
commit 4dc73b91c2
2 changed files with 7 additions and 4 deletions

View File

@ -47,7 +47,7 @@ One interesting way of using closure isolation is to keep state of the functions
>>> 0
>>> 1
>>> 2
>> void
>>> void
Inner `counter` is not accessible from outside, no way; still it is kept
between calls in the closure, as inner function `doit`, returned from the

View File

@ -16,14 +16,14 @@ class Compiler(
private fun parseScript(start: Pos, tokens: CompilerContext): Script {
val statements = mutableListOf<Statement>()
while (parseStatement(tokens)?.also {
while (parseStatement(tokens,braceMeansLambda = true)?.also {
statements += it
} != null) {/**/
}
return Script(start, statements)
}
private fun parseStatement(cc: CompilerContext): Statement? {
private fun parseStatement(cc: CompilerContext,braceMeansLambda: Boolean = false): Statement? {
while (true) {
val t = cc.next()
return when (t.type) {
@ -49,6 +49,9 @@ class Compiler(
Token.Type.LBRACE -> {
cc.previous()
if( braceMeansLambda )
parseExpression(cc)
else
parseBlock(cc)
}