Add generic bounds checks and union/intersection types

This commit is contained in:
sergeych committed 2026-02-03 15:36:11 +03:00
1 parent c5bf4e5039
commit 54c6fca0e8
5 files changed
+256 -33

No files matched your search

@@ -5273,6 +5273,40 @@ class ScriptTest {
assertEquals(ObjFalse, scope.eval("isInt(\"42\")"))
}
@Test
fun testGenericBoundsAndReifiedTypeParams() = runTest {
val resInt = eval(
"""
fun square<T: Int | Real>(x: T) = x * x
square(2)
""".trimIndent()
)
assertEquals(4L, (resInt as ObjInt).value)
val resReal = eval(
"""
fun square<T: Int | Real>(x: T) = x * x
square(1.5)
""".trimIndent()
)
assertEquals(2.25, (resReal as ObjReal).value, 0.00001)
assertFailsWith<ScriptError> {
eval(
"""
fun square<T: Int | Real>(x: T) = x * x
square("x")
""".trimIndent()
)
}
val reified = eval(
"""
fun sameType<T>(x: T, y: Object) = y is T
sameType(1, "a")
""".trimIndent()
)
assertEquals(false, (reified as ObjBool).value)
}
@Test
fun testFilterBug() = runTest {
eval(