Split up test on map access onto two tests: stdlib & compiler box test
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
|||||||
|
// IGNORE_BACKEND: JS
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class Delegate<T>(var inner: T) {
|
||||||
|
operator fun getValue(t: Any?, p: KProperty<*>): T = inner
|
||||||
|
operator fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
||||||
|
}
|
||||||
|
|
||||||
|
val del = Delegate("zzz")
|
||||||
|
|
||||||
|
class A {
|
||||||
|
inner class B {
|
||||||
|
var prop: String by del
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun asFailsWithCCE(block: () -> Unit) {
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
catch (e: ClassCastException) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
throw AssertionError("Should throw ClassCastException, got $e")
|
||||||
|
}
|
||||||
|
throw AssertionError("Should throw ClassCastException, no exception thrown")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val c = A().B()
|
||||||
|
|
||||||
|
(del as Delegate<Int>).inner = 10
|
||||||
|
asFailsWithCCE { c.prop } // does not fail in JS due KT-8135.
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
// IGNORE_BACKEND: JVM, JS
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class Delegate<T>(var inner: T) {
|
||||||
|
operator fun getValue(t: Any?, p: KProperty<*>): T = inner
|
||||||
|
operator fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
|
||||||
|
}
|
||||||
|
|
||||||
|
val del = Delegate("zzz")
|
||||||
|
|
||||||
|
class A {
|
||||||
|
inner class B {
|
||||||
|
var prop: String by del
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun asFailsWithCCE(block: () -> Unit) {
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
catch (e: ClassCastException) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
throw AssertionError("Should throw ClassCastException, got $e")
|
||||||
|
}
|
||||||
|
throw AssertionError("Should throw ClassCastException, no exception thrown")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val c = A().B()
|
||||||
|
|
||||||
|
(del as Delegate<String?>).inner = null
|
||||||
|
asFailsWithCCE { c.prop } // does not fail in JVM, JS due KT-8135.
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -32,7 +32,6 @@ class ValByMapExtensionsTest {
|
|||||||
|
|
||||||
|
|
||||||
class VarByMapExtensionsTest {
|
class VarByMapExtensionsTest {
|
||||||
// IGNORE_BACKEND: NATIVE
|
|
||||||
val map = hashMapOf<String, Any?>("a" to "all", "b" to null, "c" to 1, "xProperty" to 1.0)
|
val map = hashMapOf<String, Any?>("a" to "all", "b" to null, "c" to 1, "xProperty" to 1.0)
|
||||||
val map2: MutableMap<String, CharSequence> = hashMapOf("a2" to "all")
|
val map2: MutableMap<String, CharSequence> = hashMapOf("a2" to "all")
|
||||||
|
|
||||||
@@ -55,47 +54,6 @@ class VarByMapExtensionsTest {
|
|||||||
map2.remove("a2")
|
map2.remove("a2")
|
||||||
assertEquals("empty", a2)
|
assertEquals("empty", a2)
|
||||||
|
|
||||||
map["c"] = "string"
|
|
||||||
// fails { c } // does not fail in JS due to KT-8135
|
|
||||||
|
|
||||||
map["a"] = null
|
|
||||||
a // fails { a } // does not fail due to KT-8135
|
|
||||||
|
|
||||||
assertFailsWith<NoSuchElementException> { d }
|
|
||||||
map["d"] = null
|
|
||||||
assertEquals(null, d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class VarByMapExtensionsTest_ForNative {
|
|
||||||
val map = hashMapOf<String, Any?>("a" to "all", "b" to null, "c" to 1, "xProperty" to 1.0)
|
|
||||||
val map2: MutableMap<String, CharSequence> = hashMapOf("a2" to "all")
|
|
||||||
|
|
||||||
var a: String by map
|
|
||||||
var b: Any? by map
|
|
||||||
var c: Int by map
|
|
||||||
var d: String? by map
|
|
||||||
var a2: String by map2.withDefault { "empty" }
|
|
||||||
//var x: Int by map2 // prohibited by type system
|
|
||||||
|
|
||||||
@Test fun doTest() {
|
|
||||||
assertEquals("all", a)
|
|
||||||
assertEquals(null, b)
|
|
||||||
assertEquals(1, c)
|
|
||||||
c = 2
|
|
||||||
assertEquals(2, c)
|
|
||||||
assertEquals(2, map["c"])
|
|
||||||
|
|
||||||
assertEquals("all", a2)
|
|
||||||
map2.remove("a2")
|
|
||||||
assertEquals("empty", a2)
|
|
||||||
|
|
||||||
map["c"] = "string"
|
|
||||||
// fails { c } // does not fail in JS due to KT-8135
|
|
||||||
|
|
||||||
map["a"] = null
|
|
||||||
//a Fails in Native, KT-8135 is already fixed in Native. // fails { a } // does not fail due to KT-8135
|
|
||||||
|
|
||||||
assertFailsWith<NoSuchElementException> { d }
|
assertFailsWith<NoSuchElementException> { d }
|
||||||
map["d"] = null
|
map["d"] = null
|
||||||
assertEquals(null, d)
|
assertEquals(null, d)
|
||||||
|
|||||||
Reference in New Issue
Block a user