improved lazy delegate; added with(newThis) {} to stdlib

This commit is contained in:
sergeych committed 2026-01-05 22:25:46 +01:00
1 parent f792c73b8f
commit 41a3617850
6 files changed
+85 -8

No files matched your search

+19 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com
* Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -113,4 +113,22 @@ class StdlibTest {
assertEquals(5, (1..10).toList().count { it % 2 == 1 } )
""")
}
@Test
fun testWith() = runTest {
eval("""
class Person(val name, var age)
val p = Person("Alice", 30)
val result = with(p) {
assertEquals("Alice", name)
assertEquals(30, age)
age = 31
"done"
}
assertEquals("done", result)
assertEquals(31, p.age)
""".trimIndent())
}
}