fix #55 newlines in function declarations and constructors

This commit is contained in:
Sergey Chernov 2025-08-20 11:07:49 +03:00
parent 0526cdfb38
commit 8d1cafae80
3 changed files with 31 additions and 1 deletions

View File

@ -622,6 +622,8 @@ class Compiler(
var endTokenType: Token.Type? = null
val startPos = cc.savePos()
cc.skipWsTokens()
while (endTokenType == null) {
var t = cc.next()
when (t.type) {
@ -679,7 +681,7 @@ class Compiler(
// important: valid argument list continues with ',' and ends with '->' or ')'
// otherwise it is not an argument list:
when (val tt = cc.next().type) {
when (val tt = cc.nextNonWhitespace().type) {
Token.Type.RPAREN -> {
// end of arguments
endTokenType = tt

View File

@ -106,4 +106,15 @@ class OOTest {
}
""".trimIndent())
}
@Test
fun testMultilineConstructor() = runTest {
eval("""
class Point(
x,
y
)
assertEquals(Point(1,2), Point(1,2) )
""".trimIndent())
}
}

View File

@ -3049,5 +3049,22 @@ class ScriptTest {
""".trimIndent())
}
@Test
fun testMultilineFnDeclaration() = runTest {
eval("""
fun test(
x = 1,
y = 2
) {
x * y
}
assertEquals( 10, test(5) )
assertEquals( 42, test(
6,
7
) )
""".trimIndent())
}
}