KT-2752: fixes after code review

This commit is contained in:
Alexey Andreev
2016-09-20 16:03:33 +03:00
parent 00867cb269
commit 6f7e7d8504
30 changed files with 380 additions and 138 deletions
@@ -1,15 +1,13 @@
// KT-2995 creating factory methods to simulate overloaded constructors don't work in JavaScript
// This test is incorrect, since both constructor and function must have the same name.
package foo
class Foo(val name: String)
//fun Foo() = Foo("<default-name>")
fun Foo(x: Int) = Foo("<$x>")
fun box(): String {
// TODO: Don't know another way to suppress the test
/*assertEquals("<default-name>", Foo().name)
assertEquals("BarBaz", Foo("BarBaz").name)*/
assertEquals("<123>", Foo(123).name)
assertEquals("BarBaz", Foo("BarBaz").name)
return "OK"
}
+2 -2
View File
@@ -1,11 +1,11 @@
package foo
@JsName("AA") object A {
@JsName("foo") fun foo() = "A.foo"
@JsName("foo") fun bar() = "A.foo"
}
@JsName("BB") class B {
@JsName("foo") fun foo() = "B.foo"
@JsName("foo") fun bar() = "B.foo"
}
fun testA() = js("""
@@ -0,0 +1,16 @@
package foo
class A {
val x: String
constructor() {
}
init {
val o = "O"
fun baz() = o + "K"
x = baz()
}
}
fun box() = A().x
@@ -0,0 +1,3 @@
lib1->
lib2->
main->lib1,lib2
@@ -0,0 +1,7 @@
package lib1
interface A {
private fun foo() = "A.foo"
fun bar() = foo()
}
@@ -0,0 +1,7 @@
package lib2
interface B {
private fun foo() = "B.foo"
fun bar() = foo()
}
@@ -0,0 +1,32 @@
package main
import lib1.A
import lib2.B
class Derived1 : A, B {
override fun bar() = super<A>.bar()
}
class Derived2 : A, B {
override fun bar() = super<B>.bar()
}
// NOTE. This test is fragile, it may fail due to unexpected (and correct) changes in algorithm that assigns
// unique identifiers to non-public declarations. However, we don't see any way of doing such test so that
// it won't report false positives eventually. So be patient and just update this test whenever you changed
// algorithm of assigning unique identifiers.
// Please, check that A.foo and B.foo have different JS names.
private fun checkJsNames(o: dynamic): Boolean = "foo_2pru9n\$_0" in o && "foo_2psha1\$_0" in o
fun box(): String {
val a = Derived1()
if (a.bar() != "A.foo") return "fail1: ${a.bar()}"
val b = Derived2()
if (b.bar() != "B.foo") return "fail2: ${b.bar()}"
if (!checkJsNames(a)) return "fail3"
if (!checkJsNames(b)) return "fail4"
return "OK"
}
@@ -0,0 +1,3 @@
lib->
lib-old->
main->lib-old
@@ -0,0 +1,7 @@
package lib
open class A {
fun foo() = 12
}
inline fun check() = true
@@ -0,0 +1,7 @@
package lib
open class A {
private val x = 23
fun foo() = x
}
@@ -0,0 +1,31 @@
package main
import lib.A
import lib.check
class B : A() {
private var x = 42
fun bar() = x
}
// NOTE. This test is fragile, it may fail due to unexpected (and correct) changes in algorithm that assigns
// unique identifiers to non-public declarations. However, we don't see any way of doing such test so that
// it won't report false positives eventually. So be patient and just update this test whenever you changed
// algorithm of assigning unique identifiers.
// Please, check that A.x and B.x have different JS names.
private fun checkJsNames(o: dynamic): Boolean = "x_i8qwny\$_0" in o && "x_dqqnpp\$_0" in o
fun box(): String {
if (!check()) return "check failed: did not compile agains old library"
val a = A()
if (a.foo() != 23) return "fail1: ${a.foo()}"
val b = B()
if (b.foo() != 23) return "fail2: ${b.foo()}"
if (b.bar() != 42) return "fail3: ${b.bar()}"
if (!checkJsNames(b)) return "fail4"
return "OK"
}