[K/JS] Use only single variant of default arguments function wrapper for exported and not-exported functions
This commit is contained in:
@@ -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"
|
||||
}
|
||||
Vendored
+1
-2
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user