Overridden functions using default arguments in recursive call are no more considered tail recursive #KT-4285 Fixed
This commit is contained in:
@@ -957,6 +957,9 @@ public class ControlFlowInformationProvider {
|
||||
// is this a recursive call?
|
||||
CallableDescriptor functionDescriptor = resolvedCall.getResultingDescriptor();
|
||||
if (!functionDescriptor.getOriginal().equals(subroutineDescriptor)) return;
|
||||
// Overridden functions using default arguments at tail call are not included: KT-4285
|
||||
if (resolvedCall.getCall().getValueArguments().size() != functionDescriptor.getValueParameters().size() &&
|
||||
!functionDescriptor.getOverriddenDescriptors().isEmpty()) return;
|
||||
|
||||
KtElement element = callInstruction.getElement();
|
||||
//noinspection unchecked
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
open class A {
|
||||
open fun foo(s: String = "OK") = s
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
<!NO_TAIL_CALLS_FOUND!>override tailrec fun foo(s: String): String<!> {
|
||||
return if (s == "OK") s else foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = B().foo("FAIL")
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public fun box(): kotlin.String
|
||||
|
||||
public open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun foo(/*0*/ s: kotlin.String = ...): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class B : A {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open tailrec override /*1*/ fun foo(/*0*/ s: kotlin.String = ...): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// See also KT-4285
|
||||
open class A {
|
||||
open fun foo(x: Int = 0) {}
|
||||
|
||||
open fun gav(y: Int = 1, z: Int = 2) {}
|
||||
}
|
||||
|
||||
class B: A() {
|
||||
<!NO_TAIL_CALLS_FOUND!>tailrec override fun foo(x: Int)<!> {
|
||||
foo()
|
||||
}
|
||||
|
||||
<!NO_TAIL_CALLS_FOUND!>tailrec override fun gav(y: Int, z: Int)<!> {
|
||||
gav(y)
|
||||
}
|
||||
|
||||
tailrec fun bar(y: Double): Double = bar(y * 2.0)
|
||||
}
|
||||
|
||||
class C: A() {
|
||||
tailrec override fun foo(x: Int) {
|
||||
foo(0)
|
||||
}
|
||||
|
||||
tailrec override fun gav(y: Int, z: Int) {
|
||||
gav(y - 1, z - 1)
|
||||
}
|
||||
|
||||
tailrec fun bar(<!UNUSED_PARAMETER!>y<!>: Int = 1, z: Int = 2) {
|
||||
bar(z)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package
|
||||
|
||||
public open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun foo(/*0*/ x: kotlin.Int = ...): kotlin.Unit
|
||||
public open fun gav(/*0*/ y: kotlin.Int = ..., /*1*/ z: kotlin.Int = ...): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class B : A {
|
||||
public constructor B()
|
||||
public final tailrec fun bar(/*0*/ y: kotlin.Double): kotlin.Double
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open tailrec override /*1*/ fun foo(/*0*/ x: kotlin.Int = ...): kotlin.Unit
|
||||
public open tailrec override /*1*/ fun gav(/*0*/ y: kotlin.Int = ..., /*1*/ z: kotlin.Int = ...): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class C : A {
|
||||
public constructor C()
|
||||
public final tailrec fun bar(/*0*/ y: kotlin.Int = ..., /*1*/ z: kotlin.Int = ...): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open tailrec override /*1*/ fun foo(/*0*/ x: kotlin.Int = ...): kotlin.Unit
|
||||
public open tailrec override /*1*/ fun gav(/*0*/ y: kotlin.Int = ..., /*1*/ z: kotlin.Int = ...): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -679,6 +679,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("tailRecOverridden.kt")
|
||||
public void testTailRecOverridden() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/tailRecOverridden.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TraitOverrideObjectMethods.kt")
|
||||
public void testTraitOverrideObjectMethods() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/TraitOverrideObjectMethods.kt");
|
||||
@@ -19772,6 +19778,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultArgsOverridden.kt")
|
||||
public void testDefaultArgsOverridden() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/defaultArgsOverridden.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionTailCall.kt")
|
||||
public void testExtensionTailCall() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/extensionTailCall.kt");
|
||||
|
||||
@@ -5135,6 +5135,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultArgsOverridden.kt")
|
||||
public void testDefaultArgsOverridden() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/defaultArgsOverridden.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionTailCall.kt")
|
||||
public void testExtensionTailCall() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/extensionTailCall.kt");
|
||||
|
||||
Reference in New Issue
Block a user