JS: more default arguments fixes (KT-24413, KT-21968 fixed)
MPP-related: * inherited from interfaces * inherited body from interface * default arguments in an interface, implemented by a class delegate * super call of a method with default argument Also: * inheritance from an interface and another interface descendant (KT-21968) * inheritance through an intermediate interface
This commit is contained in:
+1
-1
@@ -69,7 +69,7 @@ fun ValueParameterDescriptor.hasDefaultValue(): Boolean {
|
||||
return DFS.ifAny(
|
||||
listOf(this),
|
||||
{ current -> current.overriddenDescriptors.map(ValueParameterDescriptor::getOriginal) },
|
||||
{ it.declaresDefaultValue() || it.isActualParameterWithAnyExpectedDefault }
|
||||
{ it.declaresDefaultValue() || it.isActualParameterWithCorrespondingExpectedDefault }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-3
@@ -1,6 +1,4 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(value: Int = 1)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val a: Int = 1,
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// See KT-21968
|
||||
|
||||
interface A {
|
||||
fun f(cause: Int? = null): Boolean
|
||||
}
|
||||
|
||||
open class B : A {
|
||||
override fun f(cause: Int?): Boolean = true
|
||||
}
|
||||
|
||||
class D : B(), A
|
||||
|
||||
fun box(): String {
|
||||
return if (D().f()) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// IGNORE_BACKEND: JVM
|
||||
// See KT-15971
|
||||
|
||||
interface Foo {
|
||||
fun foo(a: Double = 1.0): Double
|
||||
}
|
||||
|
||||
interface FooChain: Foo
|
||||
|
||||
open class Impl {
|
||||
fun foo(a: Double) = a
|
||||
}
|
||||
|
||||
class FooImpl : FooChain, Impl()
|
||||
|
||||
fun box(): String {
|
||||
if (FooImpl().foo() != 1.0) return "fail"
|
||||
if (FooImpl().foo(2.0) != 2.0) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// IGNORE_BACKEND: JVM, JS
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
interface I<T> {
|
||||
val prop: T
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// IGNORE_BACKEND: JVM, JS
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
interface I<T> {
|
||||
val prop: T
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
open class MyClass {
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
// FILE: lib.kt
|
||||
|
||||
expect interface I {
|
||||
fun foo(x: Int = 1): Unit
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
var log = ""
|
||||
fun log(a: String) {
|
||||
log += a + ";"
|
||||
}
|
||||
|
||||
interface C {
|
||||
fun foo(x: Int): Unit {
|
||||
log("C.foo($x)")
|
||||
}
|
||||
}
|
||||
|
||||
actual interface I {
|
||||
actual fun foo(x: Int): Unit
|
||||
}
|
||||
|
||||
class G(c: C) : C by c, I
|
||||
class H(c: C) : I, C by c
|
||||
|
||||
fun test1() {
|
||||
log = ""
|
||||
|
||||
val g1 = G(object: C {})
|
||||
g1.foo(2)
|
||||
g1.foo()
|
||||
val g2 = G(object: C {
|
||||
override fun foo(x: Int) {
|
||||
log("[2] object:C.foo($x)")
|
||||
}
|
||||
})
|
||||
g2.foo(2)
|
||||
g2.foo()
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
log = ""
|
||||
|
||||
val h1 = H(object: C {})
|
||||
h1.foo(2)
|
||||
h1.foo()
|
||||
val h2 = H(object: C {
|
||||
override fun foo(x: Int) {
|
||||
log("[2] object:C.foo($x)")
|
||||
}
|
||||
})
|
||||
h2.foo(2)
|
||||
h2.foo()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
test1()
|
||||
if (log != "C.foo(2);C.foo(1);[2] object:C.foo(2);[2] object:C.foo(1);") return "fail1: $log"
|
||||
|
||||
test2()
|
||||
if (log != "C.foo(2);C.foo(1);[2] object:C.foo(2);[2] object:C.foo(1);") return "fail2: $log"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
|
||||
// FILE: lib.kt
|
||||
expect interface I {
|
||||
fun f(p: String = "OK"): String
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
actual interface I {
|
||||
actual fun f(p: String): String
|
||||
}
|
||||
|
||||
class Impl : I {
|
||||
override fun f(p: String) = p
|
||||
}
|
||||
|
||||
fun box() = Impl().f()
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
|
||||
// FILE: lib.kt
|
||||
|
||||
package foo
|
||||
|
||||
expect interface H {
|
||||
fun foo(x: String = "default"): String
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
package foo
|
||||
|
||||
actual interface H {
|
||||
actual fun foo(x: String): String
|
||||
}
|
||||
|
||||
interface I: H {
|
||||
override fun foo(x: String): String = "I.foo($x)"
|
||||
}
|
||||
|
||||
interface J : I {
|
||||
override fun foo(x: String): String
|
||||
}
|
||||
|
||||
interface K : J {
|
||||
override fun foo(x: String): String = "K.foo($x)"
|
||||
}
|
||||
|
||||
class A : I
|
||||
|
||||
class B : K
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
var r = a.foo()
|
||||
if (r != "I.foo(default)") return "fail: A.foo()"
|
||||
r = a.foo("Q")
|
||||
if (r != "I.foo(Q)") return "fail A.foo(Q): $r"
|
||||
|
||||
val b = B()
|
||||
r = b.foo()
|
||||
if (r != "K.foo(default)") return "fail B.foo(): $r"
|
||||
r = b.foo("W")
|
||||
if (r != "K.foo(W)") return "fail B.foo(W): $r"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
// FILE: lib.kt
|
||||
|
||||
package foo
|
||||
|
||||
expect open class A {
|
||||
open fun foo(x: Int = 20, y: Int = 3): Int
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
package foo
|
||||
|
||||
actual open class A {
|
||||
actual open fun foo(x: Int, y: Int) = 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"
|
||||
}
|
||||
Generated
+30
@@ -8300,6 +8300,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/function"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexInheritance.kt")
|
||||
public void testComplexInheritance() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/complexInheritance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("covariantOverride.kt")
|
||||
public void testCovariantOverride() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverride.kt");
|
||||
@@ -8350,6 +8355,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTrait.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("funInTraitChain.kt")
|
||||
public void testFunInTraitChain() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTraitChain.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("innerExtentionFunction.kt")
|
||||
public void testInnerExtentionFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunction.kt");
|
||||
@@ -13472,6 +13482,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegatedExpectedInterface.kt")
|
||||
public void testDelegatedExpectedInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/delegatedExpectedInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/function.kt");
|
||||
@@ -13487,6 +13502,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedFromExpectedInterface.kt")
|
||||
public void testInheritedFromExpectedInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedFromExpectedMethod.kt")
|
||||
public void testInheritedFromExpectedMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt");
|
||||
@@ -13497,6 +13517,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedViaAnotherInterfaceIndirectly.kt")
|
||||
public void testInheritedViaAnotherInterfaceIndirectly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedViaAnotherInterfaceIndirectly.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithDefaultLambda.kt")
|
||||
public void testInlineFunctionWithDefaultLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
||||
@@ -13511,6 +13536,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
public void testKt23239() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("superCall.kt")
|
||||
public void testSuperCall() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -8300,6 +8300,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/function"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexInheritance.kt")
|
||||
public void testComplexInheritance() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/complexInheritance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("covariantOverride.kt")
|
||||
public void testCovariantOverride() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverride.kt");
|
||||
@@ -8350,6 +8355,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTrait.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("funInTraitChain.kt")
|
||||
public void testFunInTraitChain() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTraitChain.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("innerExtentionFunction.kt")
|
||||
public void testInnerExtentionFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunction.kt");
|
||||
@@ -13472,6 +13482,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegatedExpectedInterface.kt")
|
||||
public void testDelegatedExpectedInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/delegatedExpectedInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/function.kt");
|
||||
@@ -13487,6 +13502,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedFromExpectedInterface.kt")
|
||||
public void testInheritedFromExpectedInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedFromExpectedMethod.kt")
|
||||
public void testInheritedFromExpectedMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt");
|
||||
@@ -13497,6 +13517,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedViaAnotherInterfaceIndirectly.kt")
|
||||
public void testInheritedViaAnotherInterfaceIndirectly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedViaAnotherInterfaceIndirectly.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithDefaultLambda.kt")
|
||||
public void testInlineFunctionWithDefaultLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
||||
@@ -13511,6 +13536,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
public void testKt23239() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("superCall.kt")
|
||||
public void testSuperCall() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -8287,6 +8287,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Function extends AbstractLightAnalysisModeTest {
|
||||
@TestMetadata("funInTraitChain.kt")
|
||||
public void ignoreFunInTraitChain() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTraitChain.kt");
|
||||
}
|
||||
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
@@ -8300,6 +8305,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/function"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexInheritance.kt")
|
||||
public void testComplexInheritance() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/complexInheritance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("covariantOverride.kt")
|
||||
public void testCovariantOverride() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverride.kt");
|
||||
@@ -13454,6 +13464,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class DefaultArguments extends AbstractLightAnalysisModeTest {
|
||||
@TestMetadata("delegatedExpectedInterface.kt")
|
||||
public void ignoreDelegatedExpectedInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/delegatedExpectedInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("superCall.kt")
|
||||
public void ignoreSuperCall() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
|
||||
}
|
||||
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
@@ -13487,6 +13507,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedFromExpectedInterface.kt")
|
||||
public void testInheritedFromExpectedInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedFromExpectedMethod.kt")
|
||||
public void testInheritedFromExpectedMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt");
|
||||
@@ -13497,6 +13522,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedViaAnotherInterfaceIndirectly.kt")
|
||||
public void testInheritedViaAnotherInterfaceIndirectly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedViaAnotherInterfaceIndirectly.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithDefaultLambda.kt")
|
||||
public void testInlineFunctionWithDefaultLambda() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
||||
|
||||
Reference in New Issue
Block a user