[K/JS] Use only single variant of default arguments function wrapper for exported and not-exported functions

This commit is contained in:
Artem Kobzar
2022-09-19 17:49:04 +00:00
committed by Space
parent ea7ce55082
commit 73e7053c35
59 changed files with 1109 additions and 597 deletions
@@ -0,0 +1,28 @@
// EXPECTED_REACHABLE_NODES: 1299
package foo
interface A {
open fun foo(x: Int = 20, y: Int = 3) = x + y
}
open class B : A {
override fun foo(x: Int, y: Int) = 0
fun bar1() = super.foo()
fun bar2() = super.foo(30)
fun bar3() = super.foo(y = 4)
}
fun box(): String {
val v1 = B().bar1()
if (v1 != 23) return "fail1: $v1"
val v2 = B().bar2()
if (v2 != 33) return "fail2: $v2"
val v3 = B().bar3()
if (v3 != 24) return "fail3: $v3"
return "OK"
}
@@ -0,0 +1,82 @@
// EXPECTED_REACHABLE_NODES: 1252
// RUN_PLAIN_BOX_FUNCTION
// INFER_MAIN_MODULE
// SKIP_DCE_DRIVEN
// IGNORE_BACKEND: JS
// MODULE: export_default_method
// FILE: lib.kt
@JsExport
abstract class Adapter {
abstract fun method(o: String = "O", k: String = "K")
}
@JsExport
class TwoArgumentsWrapper(val adapter: Adapter) {
fun method(a: String, b: String) {
adapter.method(a, b)
}
}
@JsExport
class OneArgumentWrapper(val adapter: Adapter) {
fun method(param: String) {
adapter.method(param)
}
}
@JsExport
class NoArgumentsWrapper(val adapter: Adapter) {
fun method() {
adapter.method()
}
}
// FILE: test.js
function box() {
const Adapter = this.export_default_method.Adapter
const Wrapper2 = this.export_default_method.TwoArgumentsWrapper
const Wrapper1 = this.export_default_method.OneArgumentWrapper
const Wrapper0 = this.export_default_method.NoArgumentsWrapper
class WebAdapter extends Adapter {
constructor(name) {
super()
this.resetError(name)
}
method(o = "O", k = "K") {
this.result = o + k
}
resetError(name) {
this.result = `Error: ${name}'s overridden method was not called`
}
}
const webAdapter = new WebAdapter("webAdapter2")
const wrapper2 = new Wrapper2(webAdapter)
wrapper2.method("O", "K")
if (webAdapter.result !== "OK") return webAdapter.result
webAdapter.resetError("webAdapter1")
const wrapper1 = new Wrapper1(webAdapter)
wrapper1.method("O")
if (webAdapter.result !== "OK") return webAdapter.result
webAdapter.resetError("webAdapter0")
const wrapper0 = new Wrapper0(webAdapter)
wrapper0.method()
if (webAdapter.result !== "OK") return webAdapter.result
return "OK"
}
@@ -15,8 +15,7 @@ inline fun <reified T> boo() = "boo"
// MODULE: main(#my_libr@ry)
// MODULE_KIND: PLAIN
// FILE: box.kt
// CHECK_CONTAINS_NO_CALLS: box except=assertEquals TARGET_BACKENDS=JS
// CHECK_CONTAINS_NO_CALLS: box except=assertEquals$default IGNORED_BACKENDS=JS
// CHECK_CONTAINS_NO_CALLS: box except=assertEquals
fun box(): String {
assertEquals("foo", foo())
@@ -12,4 +12,4 @@ fun baz() = 1
fun bar() = 2
// LINES(JS): 1 3 3 2 2 4 3 4 4 4 5 5 2 8 8 10 10 10 12 12 12
// LINES(JS_IR): 8 8 * 1 3 3 1 4 5 1 1 * 10 10 * 12 12
// LINES(JS_IR): 1 3 3 4 5 1 * 8 8 * 10 10 * 12 12
+1 -1
View File
@@ -6,4 +6,4 @@ data class A(
// LINES(JS): 1 2 3 * 1 2 2 1 3 3 1 1 1 2 3 1 1 1 2 3 1 1 1 2 3 1 1 1 1 1 2 3
// FIXME: componentN function body should point to the corresponding property.
// LINES(JS_IR): 2 2 3 3 * 2 2 * 3 3 * 1 1 * 1 1 * 1 1 * 1 1 1 1 1 1 1 1 * 1 1 * 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
// LINES(JS_IR): 2 2 3 3 * 2 2 * 3 3 * 1 1 * 1 1 * 1 1 * 1 1 1 1 * 1 1 * 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
@@ -11,4 +11,4 @@ class B : A() {
}
// LINES(JS): 1 2 2 2 2 2 2 2 2 2 4 4 4 * 7 7 8 10 9 9
// LINES(JS_IR): 2 2 * 2 2 2 2 2 * 4 4 * 7 * 9 9
// LINES(JS_IR): 2 2 * 2 2 2 * 4 4 * 7 * 9 9
+1 -1
View File
@@ -8,4 +8,4 @@ fun box(
}
// LINES(JS): 1 8 2 2 2 2 3 3 3 4 6 6 7 7
// LINES(JS_IR): 1 1 2 1 4 1 * 6 6 7 7 * 1 1 2 1 1 4 1 1
// LINES(JS_IR): 1 2 1 1 4 1 6 6 7 7