class val and var in body

This commit is contained in:
sergeych committed 2025-06-09 23:55:06 +04:00
1 parent 56e0d2fd63
commit 961228ca0b
5 files changed
+69 -8

No files matched your search

@@ -1415,4 +1415,24 @@ class ScriptTest {
assertEquals( 0, p.x )
""".trimIndent())
}
@Test
fun testStructBodyVal() = runTest {
val c = Context()
c.eval("""
struct Point(x,y) {
val length = sqrt(x*x+y*y)
var foo = "zero"
}
val p = Point(3,4)
assertEquals(5, p.length)
assertEquals("zero", p.foo)
p.y = 10
p.foo = "bar"
assert( p.y == 10 )
assert( p.foo == "bar")
// length is a val, is shoud not change
assert( p.length == 5 )
""".trimIndent())
}
}