diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index 6bf9e72..a2da1d9 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -65,9 +65,17 @@ class Compiler( } } } - parseStatement(braceMeansLambda = true)?.also { + val s = parseStatement(braceMeansLambda = true)?.also { statements += it - } ?: break + } + if (s == null) { + when( t.type ) { + Token.Type.RBRACE, Token.Type.EOF, Token.Type.SEMICOLON -> {} + else -> + throw ScriptError(t.pos, "unexpeced `${t.value}` here") + } + break + } } while (true) return Script(start, statements)//returnScope.needCatch) @@ -833,8 +841,18 @@ class Compiler( val isExtern = cc.skipId("extern") when { cc.matchQualifiers("fun", "private") -> parseFunctionDeclaration(Visibility.Private, isExtern) - cc.matchQualifiers("fun", "private", "static") -> parseFunctionDeclaration(Visibility.Private, isExtern, isStatic = true) - cc.matchQualifiers("fun", "static") -> parseFunctionDeclaration(Visibility.Public, isExtern, isStatic = true) + cc.matchQualifiers("fun", "private", "static") -> parseFunctionDeclaration( + Visibility.Private, + isExtern, + isStatic = true + ) + + cc.matchQualifiers("fun", "static") -> parseFunctionDeclaration( + Visibility.Public, + isExtern, + isStatic = true + ) + cc.matchQualifiers("fn", "private") -> parseFunctionDeclaration(Visibility.Private, isExtern) cc.matchQualifiers("fun", "open") -> parseFunctionDeclaration(isOpen = true, isExtern = isExtern) cc.matchQualifiers("fn", "open") -> parseFunctionDeclaration(isOpen = true, isExtern = isExtern) @@ -1541,7 +1559,7 @@ class Compiler( } private suspend fun - parseFunctionDeclaration( + parseFunctionDeclaration( visibility: Visibility = Visibility.Public, @Suppress("UNUSED_PARAMETER") isOpen: Boolean = false, isExtern: Boolean = false, @@ -1613,7 +1631,7 @@ class Compiler( (thisObj as? ObjInstance)?.let { i -> fnBody.execute(ClosureScope(this, i.instanceScope)) } - // other classes can create one-time scope for this rare case: + // other classes can create one-time scope for this rare case: ?: fnBody.execute(thisObj.autoInstanceScope(this)) } } diff --git a/lynglib/src/commonTest/kotlin/OOTest.kt b/lynglib/src/commonTest/kotlin/OOTest.kt index 5b68b1d..ac40bda 100644 --- a/lynglib/src/commonTest/kotlin/OOTest.kt +++ b/lynglib/src/commonTest/kotlin/OOTest.kt @@ -43,4 +43,21 @@ class OOTest { assertEquals( "foo!", Point.getData() ) """.trimIndent()) } + +// @Test + fun testDynamic() = runTest { + eval(""" + println("0") + class DynamicTest : Dynamic { + + fun getDynamic(name) { + if (name == "foo") "bar" else null + } + } + println("1") + val d = DynamicTest() + println(d) + println("2") + """.trimIndent()) + } } \ No newline at end of file diff --git a/lynglib/src/commonTest/kotlin/ScriptTest.kt b/lynglib/src/commonTest/kotlin/ScriptTest.kt index 8ab03c6..2e0233c 100644 --- a/lynglib/src/commonTest/kotlin/ScriptTest.kt +++ b/lynglib/src/commonTest/kotlin/ScriptTest.kt @@ -2375,8 +2375,6 @@ class ScriptTest { x++; y++ } assertEquals(p, Point(2,3)) - >>> void - """.trimIndent() ) } @@ -2393,8 +2391,6 @@ class ScriptTest { y++ } assertEquals(p, Point(2,3)) - >>> void - """.trimIndent() ) }