[K/JS] Add undefined type to parameter with default argument that are placed before non-optional parameters

^KT-53180 Fixed
This commit is contained in:
Artem Kobzar
2023-02-28 11:53:28 +00:00
committed by Space Team
parent fbc0796ed2
commit deb6ca66ea
10 changed files with 75 additions and 12 deletions
@@ -20,5 +20,7 @@ declare namespace JS_TESTS {
function inlineFun(x: number, callback: (p0: number) => void): void;
function formatList(value: any/* kotlin.collections.List<UnknownType *> */): string;
function createList(): any/* kotlin.collections.List<UnknownType *> */;
function defaultParametersAtTheBegining(a: string | undefined, b: string): string;
function nonDefaultParameterInBetween(a: string | undefined, b: string, c?: string): string;
}
}
@@ -72,3 +72,10 @@ fun formatList(value: List<*>): String = value.joinToString(", ") { it.toString(
fun createList(): List<*> = listOf(1, 2, 3)
// KT-53180
fun defaultParametersAtTheBegining(a: String = "Default Value", b: String) = "$a and $b"
fun nonDefaultParameterInBetween(a: String = "Default A", b: String, c: String = "Default C") = "$a and $b and $c"
@@ -25,6 +25,8 @@ var genericWithConstraint = JS_TESTS.foo.genericWithConstraint;
var genericWithMultipleConstraints = JS_TESTS.foo.genericWithMultipleConstraints;
var formatList = JS_TESTS.foo.formatList;
var createList = JS_TESTS.foo.createList;
var defaultParametersAtTheBegining = JS_TESTS.foo.defaultParametersAtTheBegining;
var nonDefaultParametersInBetween = JS_TESTS.foo.nonDefaultParameterInBetween;
function assert(condition) {
if (!condition) {
throw "Assertion failed";
@@ -58,5 +60,11 @@ function box() {
inlineFun(10, function (x) { result = x; });
assert(result === 10);
assert(formatList(createList()) === "1, 2, 3");
assert(defaultParametersAtTheBegining("A", "B") == "A and B");
assert(defaultParametersAtTheBegining(undefined, "B") == "Default Value and B");
assert(nonDefaultParametersInBetween("A", "B", "C") == "A and B and C");
assert(nonDefaultParametersInBetween("A", "B") == "A and B and Default C");
assert(nonDefaultParametersInBetween(undefined, "B", "C") == "Default A and B and C");
assert(nonDefaultParametersInBetween(undefined, "B") == "Default A and B and Default C");
return "OK";
}
@@ -13,6 +13,8 @@ import genericWithConstraint = JS_TESTS.foo.genericWithConstraint;
import genericWithMultipleConstraints = JS_TESTS.foo.genericWithMultipleConstraints;
import formatList = JS_TESTS.foo.formatList;
import createList = JS_TESTS.foo.createList;
import defaultParametersAtTheBegining = JS_TESTS.foo.defaultParametersAtTheBegining;
import nonDefaultParametersInBetween = JS_TESTS.foo.nonDefaultParameterInBetween;
function assert(condition: boolean) {
if (!condition) {
throw "Assertion failed";
@@ -57,5 +59,13 @@ function box(): string {
assert(formatList(createList()) === "1, 2, 3")
assert(defaultParametersAtTheBegining("A", "B") == "A and B")
assert(defaultParametersAtTheBegining(undefined, "B") == "Default Value and B")
assert(nonDefaultParametersInBetween("A", "B", "C") == "A and B and C")
assert(nonDefaultParametersInBetween("A", "B") == "A and B and Default C")
assert(nonDefaultParametersInBetween(undefined, "B", "C") == "Default A and B and C")
assert(nonDefaultParametersInBetween(undefined, "B") == "Default A and B and Default C")
return "OK";
}
@@ -20,5 +20,7 @@ declare namespace JS_TESTS {
function inlineFun(x: number, callback: (p0: number) => void): void;
function formatList(value: any/* kotlin.collections.List<UnknownType *> */): string;
function createList(): any/* kotlin.collections.List<UnknownType *> */;
function defaultParametersAtTheBegining(a: string | undefined, b: string): string;
function nonDefaultParameterInBetween(a: string | undefined, b: string, c?: string): string;
}
}
@@ -68,3 +68,10 @@ fun formatList(value: List<*>): String = value.joinToString(", ") { it.toString(
@JsExport
fun createList(): List<*> = listOf(1, 2, 3)
// KT-53180
@JsExport
fun defaultParametersAtTheBegining(a: String = "Default Value", b: String) = "$a and $b"
@JsExport
fun nonDefaultParameterInBetween(a: String = "Default A", b: String, c: String = "Default C") = "$a and $b and $c"
@@ -25,6 +25,8 @@ var genericWithConstraint = JS_TESTS.foo.genericWithConstraint;
var genericWithMultipleConstraints = JS_TESTS.foo.genericWithMultipleConstraints;
var formatList = JS_TESTS.foo.formatList;
var createList = JS_TESTS.foo.createList;
var defaultParametersAtTheBegining = JS_TESTS.foo.defaultParametersAtTheBegining;
var nonDefaultParametersInBetween = JS_TESTS.foo.nonDefaultParameterInBetween;
function assert(condition) {
if (!condition) {
throw "Assertion failed";
@@ -58,5 +60,11 @@ function box() {
inlineFun(10, function (x) { result = x; });
assert(result === 10);
assert(formatList(createList()) === "1, 2, 3");
assert(defaultParametersAtTheBegining("A", "B") == "A and B");
assert(defaultParametersAtTheBegining(undefined, "B") == "Default Value and B");
assert(nonDefaultParametersInBetween("A", "B", "C") == "A and B and C");
assert(nonDefaultParametersInBetween("A", "B") == "A and B and Default C");
assert(nonDefaultParametersInBetween(undefined, "B", "C") == "Default A and B and C");
assert(nonDefaultParametersInBetween(undefined, "B") == "Default A and B and Default C");
return "OK";
}
@@ -13,6 +13,8 @@ import genericWithConstraint = JS_TESTS.foo.genericWithConstraint;
import genericWithMultipleConstraints = JS_TESTS.foo.genericWithMultipleConstraints;
import formatList = JS_TESTS.foo.formatList;
import createList = JS_TESTS.foo.createList;
import defaultParametersAtTheBegining = JS_TESTS.foo.defaultParametersAtTheBegining;
import nonDefaultParametersInBetween = JS_TESTS.foo.nonDefaultParameterInBetween;
function assert(condition: boolean) {
if (!condition) {
throw "Assertion failed";
@@ -57,5 +59,13 @@ function box(): string {
assert(formatList(createList()) === "1, 2, 3")
assert(defaultParametersAtTheBegining("A", "B") == "A and B")
assert(defaultParametersAtTheBegining(undefined, "B") == "Default Value and B")
assert(nonDefaultParametersInBetween("A", "B", "C") == "A and B and C")
assert(nonDefaultParametersInBetween("A", "B") == "A and B and Default C")
assert(nonDefaultParametersInBetween(undefined, "B", "C") == "Default A and B and C")
assert(nonDefaultParametersInBetween(undefined, "B") == "Default A and B and Default C")
return "OK";
}