rra/ilgonmic/revert-signatures-changes
[JS IR] Fix line number test [JS IR] Ignore isInstance repl test [JS IR] Ignore isInstance repl test [JS IR] Add test with unsafe variance Revert "[JS IR] Optimize away upcasts" This reverts commit8149189585. Get rid of duplicated signatures Revert "[JS IR] Consider erasing type parameters in return type in js signatures" This reverts commit6adcbe081e. Revert "rra/ilgonmic/exported-bridges-2 [JS IR] Use js name for signature" This reverts commit00289d35[JS IR] Leave as is [JS IR] Add test with overloading by generic [JS IR] Add test from master [JS IR] Add tests from master Merge-request: KT-MR-5987 Merged-by: Ilya Goncharov <Ilya.Goncharov@jetbrains.com> ^KT-51700 fixed ^KT-51523 fixed ^KT-51685 fixed
This commit is contained in:
@@ -1,150 +0,0 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1306
|
||||
|
||||
// Test that upcasts are optimized away
|
||||
|
||||
open class Base
|
||||
|
||||
class Derived: Base()
|
||||
|
||||
var counter = 0
|
||||
var _derived = Derived()
|
||||
|
||||
@JsExport
|
||||
fun getDerived(): Derived {
|
||||
counter += 1
|
||||
return _derived
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun getDerivedNullable(): Derived? {
|
||||
counter += 1
|
||||
return _derived
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun getDerivedNull(): Derived? {
|
||||
counter += 1
|
||||
return null
|
||||
}
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast1 except=getDerived IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=upcast1 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun upcast1() = getDerived() as Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast2 except=getDerived IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast2 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast2 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=upcast2 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun upcast2() = getDerived() as Base?
|
||||
|
||||
// CHECK_BINOP_COUNT: function=upcast3 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun upcast3() = getDerivedNullable() as Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast4 except=getDerivedNullable IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast4 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast4 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=upcast1 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun upcast4() = getDerivedNullable() as Base?
|
||||
|
||||
// CHECK_BINOP_COUNT: function=upcast5 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun upcast5() = getDerivedNull() as Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast6 except=getDerivedNull IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast6 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast6 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=upcast6 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun upcast6() = getDerivedNull() as Base?
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: safeCast1 except=getDerived IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=safeCast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=safeCast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=safeCast1 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun safeCast1() = getDerived() as? Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: safeCast2 except=getDerived IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=safeCast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=safeCast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=safeCast2 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun safeCast2() = getDerived() as? Base?
|
||||
|
||||
// CHECK_BINOP_COUNT: function=safeCast3 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun safeCast3() = getDerivedNullable() as? Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: safeCast4 except=getDerivedNullable IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=safeCast4 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=safeCast4 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=safeCast4 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun safeCast4() = getDerivedNullable() as? Base?
|
||||
|
||||
// CHECK_BINOP_COUNT: function=safeCast5 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun safeCast5() = getDerivedNull() as? Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: safeCast6 except=getDerivedNull IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=safeCast6 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=safeCast6 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=safeCast6 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun safeCast6() = getDerivedNull() as? Base?
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast1 except=getDerived IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast1 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=instanceCheck1 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun instanceCheck1() = getDerived() is Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast2 except=getDerived IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast2 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast2 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=instanceCheck2 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun instanceCheck2() = getDerived() is Base?
|
||||
|
||||
// CHECK_BINOP_COUNT: function=instanceCheck3 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun instanceCheck3() = getDerivedNullable() is Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast4 except=getDerivedNullable IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast4 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast4 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=instanceCheck4 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun instanceCheck4() = getDerivedNullable() is Base?
|
||||
|
||||
// CHECK_BINOP_COUNT: function=instanceCheck5 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun instanceCheck5() = getDerivedNull() is Base
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: upcast6 except=getDerivedNull IGNORED_BACKENDS=JS
|
||||
// CHECK_TERNARY_OPERATOR_COUNT: function=upcast6 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_IF_COUNT: function=upcast6 count=0 IGNORED_BACKENDS=JS
|
||||
// CHECK_BINOP_COUNT: function=instanceCheck6 count=0 symbol=instanceof IGNORED_BACKENDS=JS
|
||||
fun instanceCheck6() = getDerivedNull() is Base?
|
||||
|
||||
fun box(): String {
|
||||
assertSame(_derived, upcast1(), "upcast1()")
|
||||
assertSame(_derived, upcast2(), "upcast2()")
|
||||
assertSame(_derived, upcast3(), "upcast3()")
|
||||
assertSame(_derived, upcast4(), "upcast4()")
|
||||
failsClassCast("upcast5()") { upcast5() }
|
||||
assertSame(null, upcast6(), "upcast6()")
|
||||
assertEquals(6, counter)
|
||||
|
||||
counter = 0
|
||||
|
||||
assertSame(_derived, safeCast1(), "safeCast1()")
|
||||
assertSame(_derived, safeCast2(), "safeCast2()")
|
||||
assertSame(_derived, safeCast3(), "safeCast3()")
|
||||
assertSame(_derived, safeCast4(), "safeCast4()")
|
||||
assertSame(null, safeCast5(), "safeCast5()")
|
||||
assertSame(null, safeCast6(), "safeCast6()")
|
||||
assertEquals(6, counter)
|
||||
|
||||
counter = 0
|
||||
|
||||
assertTrue(instanceCheck1(), "instanceCheck1()")
|
||||
assertTrue(instanceCheck2(), "instanceCheck2()")
|
||||
assertTrue(instanceCheck3(), "instanceCheck3()")
|
||||
assertTrue(instanceCheck4(), "instanceCheck4()")
|
||||
assertFalse(instanceCheck5(), "instanceCheck5()")
|
||||
assertTrue(instanceCheck6(), "instanceCheck6()")
|
||||
assertEquals(6, counter)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
abstract class Foo<out E> {
|
||||
abstract fun foo(element: @UnsafeVariance E): Boolean
|
||||
}
|
||||
|
||||
class Bar<E : C> : Foo<E>() {
|
||||
override fun foo(element: E): Boolean {
|
||||
if (element !is C?) return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
open class C
|
||||
|
||||
open class D : C()
|
||||
|
||||
fun box(): String {
|
||||
val a = (object{})
|
||||
val foo: Foo<Any?> = Bar<D>()
|
||||
if (foo.foo(a as Any?)) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
class L<T>
|
||||
|
||||
class A {
|
||||
fun foo(a: L<Int>) = "Int"
|
||||
fun foo(a: L<String>) = "String"
|
||||
fun L<Int>.bar() = "Int2"
|
||||
fun L<String>.bar() = "String2"
|
||||
}
|
||||
|
||||
fun foo(a: L<Int>) = "Int"
|
||||
fun foo(a: L<String>) = "String"
|
||||
|
||||
private class TestClass {
|
||||
private val data = mutableListOf<List<Any>>()
|
||||
fun withData(data: List<List<Any>>) = apply { this.data.addAll(data) }
|
||||
fun withData(row: List<Any>) = apply {
|
||||
data.add(row)
|
||||
}
|
||||
|
||||
fun getCols(): Int {
|
||||
return data.firstOrNull()?.size ?: return 0
|
||||
}
|
||||
}
|
||||
|
||||
object B {
|
||||
fun baz(vararg v: B) = "[A]"
|
||||
|
||||
fun baz(vararg v: String) = "[S]"
|
||||
|
||||
fun baz(v: Array<String>) = "Array<String>"
|
||||
}
|
||||
|
||||
class C<in T> {
|
||||
fun bac(c: T): String {
|
||||
return "T4"
|
||||
}
|
||||
|
||||
fun bac(c: Int): String {
|
||||
return "Int5"
|
||||
}
|
||||
|
||||
fun bac(c: List<T>): String {
|
||||
return "ListT4"
|
||||
}
|
||||
|
||||
fun bac(c: List<Int>): String {
|
||||
return "ListInt4"
|
||||
}
|
||||
|
||||
fun bac(c: List<*>): String {
|
||||
return "ListStar4"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A().foo(L<Int>()) != "Int") return "fail1"
|
||||
A().apply {
|
||||
if (L<Int>().bar() != "Int2") return "fail2"
|
||||
}
|
||||
if (foo(L<Int>()) != "Int") return "fail3"
|
||||
|
||||
val b = TestClass()
|
||||
val data = mutableListOf<List<Any>>()
|
||||
data.add(listOf("a", "b", "c"))
|
||||
data.add(listOf("d", "e", "f"))
|
||||
b.withData(data)
|
||||
if (b.getCols() != 3) return "fail4"
|
||||
|
||||
if (B.baz(B) != "[A]") return "fail5"
|
||||
if (B.baz("a") != "[S]") return "fail6"
|
||||
if (B.baz(arrayOf("b")) != "Array<String>") return "fail7"
|
||||
|
||||
if(C<String>().bac("a") != "T4") return "fail8"
|
||||
if(C<String>().bac(5) != "Int5") return "fail9"
|
||||
if(C<String>().bac(listOf("a", "b")) != "ListT4") return "fail10"
|
||||
if(C<String>().bac(listOf(5, 6)) != "ListInt4") return "fail11"
|
||||
if(C<String>().bac(listOf(Any(), Any())) != "ListStar4") return "fail12"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user