Enable smart-cast handling for expressions and add relevant tests.

This commit is contained in:
sergeych committed 2026-03-09 10:29:04 +03:00
1 parent f03006ce37
commit 90e586b5d2
2 files changed
+67 -4

No files matched your search

@@ -21,6 +21,7 @@ import net.sergeych.lyng.ScriptError
import net.sergeych.lyng.eval
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
class TypesTest {
@@ -181,6 +182,41 @@ class TypesTest {
""".trimIndent())
}
@Test
fun testAssertIsSmartCastEnablesMemberCall() = runTest {
eval(
"""
class Ctx {
fun println(msg: String) = msg
}
fun use(callContext) {
assert(callContext is Ctx)
callContext.println("hello")
}
assertEquals("hello", use(Ctx()))
""".trimIndent()
)
}
@Test
fun testBareIsExpressionDoesNotSmartCastForMemberCall() = runTest {
val ex = assertFailsWith<ScriptError> {
eval(
"""
class Ctx {
fun println(msg: String) = msg
}
fun use(callContext) {
callContext is Ctx
callContext.println("hello")
}
use(Ctx())
""".trimIndent()
)
}
assertTrue(ex.message?.contains("member access requires compile-time receiver type: println") == true)
}
@Test
fun testListLiteralInferenceForBounds() = runTest {
eval("""