fix #55 newlines in function declarations and constructors
This commit is contained in:
		
							parent
							
								
									0526cdfb38
								
							
						
					
					
						commit
						8d1cafae80
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -106,4 +106,15 @@ class OOTest {
 | 
			
		||||
            }
 | 
			
		||||
        """.trimIndent())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    fun testMultilineConstructor() = runTest {
 | 
			
		||||
        eval("""
 | 
			
		||||
            class Point(
 | 
			
		||||
                x,
 | 
			
		||||
                y
 | 
			
		||||
            ) 
 | 
			
		||||
            assertEquals(Point(1,2), Point(1,2) )
 | 
			
		||||
            """.trimIndent())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user