JS: add tests to prove that compiler does not optimize RTTI and safe calls based on type information. Remove corresponding optimization for !! operation. See KT-14033

This commit is contained in:
Alexey Andreev
2016-12-13 17:13:53 +03:00
parent e6501591fa
commit b21f906856
8 changed files with 86 additions and 14 deletions
@@ -0,0 +1,3 @@
function createWrongObject() {
return new (JS_TESTS.foo.C);
}
@@ -0,0 +1,34 @@
package foo
open class A
class B : A()
class C
fun box(): String {
var b: B = createWrongObject()
if (b is A) return "fail1: is"
if (b as? A != null) return "fail1: as?"
try {
println(b as A)
return "fail1: as"
}
catch (e: ClassCastException) {
// It's expected
}
b = B()
if (b !is A) return "fail2: is"
if (b as? A == null) return "fail2: as?"
try {
if ((b as A) != b) return "fail2: as"
}
catch (e: ClassCastException) {
return "fail2a: as"
}
return "OK"
}
external fun createWrongObject(): B