diff --git a/compiler/testData/codegen/box/functions/tailRecursion/insideElvis.kt b/compiler/testData/codegen/box/functions/tailRecursion/insideElvis.kt index bcc9bea5e99..396271f0923 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/insideElvis.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/insideElvis.kt @@ -1,12 +1,10 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(counter : Int, a : Any) : Int? { +tailRecursive fun test(counter : Int) : Int? { if (counter < 0) return null if (counter == 0) return 777 - return test(-1, "no tail") ?: test(-2, "no tail") ?: test(counter - 1, "tail") + return test(-1) ?: test(-2) ?: test(counter - 1) } fun box() : String = - if (test(100000, "test") == 777) "OK" + if (test(100000) == 777) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/labeledThisReferences.kt b/compiler/testData/codegen/box/functions/tailRecursion/labeledThisReferences.kt index ecabc86be8e..3ee17320796 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/labeledThisReferences.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/labeledThisReferences.kt @@ -2,9 +2,9 @@ class B { inner class C { - tailRecursive fun h(counter : Int, x : Any) { + tailRecursive fun h(counter : Int) { if (counter > 0) { - this@C.h(counter - 1, "tail") + this@C.h(counter - 1) } } @@ -21,7 +21,7 @@ class B { } fun box() : String { - B().makeC().h(1000000, "test") + B().makeC().h(1000000) B().makeC().h2(0) return "OK" } diff --git a/compiler/testData/codegen/box/functions/tailRecursion/loops.kt b/compiler/testData/codegen/box/functions/tailRecursion/loops.kt index 76e7901ab4a..0589d46f14c 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/loops.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/loops.kt @@ -1,16 +1,14 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(x : Int, a : Any) : Int { +tailRecursive fun test(x : Int) : Int { var z = if (x > 3) 3 else x while (z > 0) { if (z > 10) { - return test(x - 1, "tail") + return test(x - 1) } - test(0, "no tail") + test(0) z = z - 1 } return 1 } -fun box() : String = if (test(100000, "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(100000) == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/multilevelBlocks.kt b/compiler/testData/codegen/box/functions/tailRecursion/multilevelBlocks.kt index 9c53f3b992d..bc8532965c4 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/multilevelBlocks.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/multilevelBlocks.kt @@ -1,17 +1,15 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(x : Int, a : Any) : Int { +tailRecursive fun test(x : Int) : Int { if (x == 1) { if (x != 1) { - test(0, "no tail") - return test(0, "tail") + test(0) + return test(0) } else { - return test(x + test(0, "no tail"), "tail") + return test(x + test(0)) } } else if (x > 0) { - return test(x - 1, "tail") + return test(x - 1) } return -1 } -fun box() : String = if (test(1000000, "test") == -1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(1000000) == -1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/recursiveInnerFunction.kt b/compiler/testData/codegen/box/functions/tailRecursion/recursiveInnerFunction.kt index 56217109a22..7b5af7792dd 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/recursiveInnerFunction.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/recursiveInnerFunction.kt @@ -1,10 +1,8 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - fun test() { - [tailRecursive] fun g3(counter : Int, x : Any) { - if (counter > 0) { g3(counter - 1, "tail") } + [tailRecursive] fun g3(counter : Int) { + if (counter > 0) { g3(counter - 1) } } - g3(1000000, "test") + g3(1000000) } fun box() : String { diff --git a/compiler/testData/codegen/box/functions/tailRecursion/returnInCatch.kt b/compiler/testData/codegen/box/functions/tailRecursion/returnInCatch.kt index 95ad34901a7..ab6ea508b17 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/returnInCatch.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/returnInCatch.kt @@ -1,13 +1,11 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(counter : Int, a : Any) : Int { +tailRecursive fun test(counter : Int) : Int { if (counter == 0) return 0 try { throw Exception() } catch (e : Exception) { - return test(counter - 1, "no tail") + return test(counter - 1) } } -fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(3) == 0) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/returnInFinally.kt b/compiler/testData/codegen/box/functions/tailRecursion/returnInFinally.kt index ff5b412d261..d9f49071900 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/returnInFinally.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/returnInFinally.kt @@ -1,13 +1,11 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(counter : Int, a : Any) : Int { +tailRecursive fun test(counter : Int) : Int { if (counter == 0) return 0 try { // do nothing } finally { - return test(counter - 1, "no tail") + return test(counter - 1) } } -fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(3) == 0) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/returnInIfInFinally.kt b/compiler/testData/codegen/box/functions/tailRecursion/returnInIfInFinally.kt index b0101b8c7d2..bc009b1ab68 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/returnInIfInFinally.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/returnInIfInFinally.kt @@ -1,17 +1,15 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(counter : Int, a : Any) : Int { +tailRecursive fun test(counter : Int) : Int { if (counter == 0) return 0 try { // do nothing } finally { if (counter > 0) { - return test(counter - 1, "no tail") + return test(counter - 1) } } return -1 } -fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(3) == 0) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/returnInTry.kt b/compiler/testData/codegen/box/functions/tailRecursion/returnInTry.kt index f0193f37710..838b3566934 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/returnInTry.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/returnInTry.kt @@ -1,13 +1,11 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(counter : Int, a : Any) : Int { +tailRecursive fun test(counter : Int) : Int { if (counter == 0) return 0 try { - return test(counter - 1, "no tail") + return test(counter - 1) } catch (any : Throwable) { return -1 } } -fun box() : String = if (test(3, "test") == 0) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(3) == 0) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/simpleBlock.kt b/compiler/testData/codegen/box/functions/tailRecursion/simpleBlock.kt index 839cf9f342f..e80aa190cfb 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/simpleBlock.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/simpleBlock.kt @@ -1,13 +1,11 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(x : Int, a : Any) : Int = +tailRecursive fun test(x : Int) : Int = if (x == 1) { - test(x - 1, "no tail") - 1 + test(x - 1, "no tail") + test(x - 1) + 1 + test(x - 1) } else if (x > 0) { - test(x - 1, "tail") + test(x - 1) } else { 0 } -fun box() : String = if (test(1000000, "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(1000000) == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/simpleReturn.kt b/compiler/testData/codegen/box/functions/tailRecursion/simpleReturn.kt index 98b635508b3..a5f038742f5 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/simpleReturn.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/simpleReturn.kt @@ -1,13 +1,11 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(x : Int, z : Any) : Int { +tailRecursive fun test(x : Int) : Int { if (x == 10) { - return 1 + test(x - 1, "no tail") + return 1 + test(x - 1) } if (x > 0) { - return test(x - 1, "tail") + return test(x - 1) } return 0 } -fun box() : String = if (test(1000000, "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(1000000) == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/simpleReturnWithElse.kt b/compiler/testData/codegen/box/functions/tailRecursion/simpleReturnWithElse.kt index 6cd76f03112..631f3d20066 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/simpleReturnWithElse.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/simpleReturnWithElse.kt @@ -1,14 +1,12 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(x : Int, a : Any) : Int { +tailRecursive fun test(x : Int) : Int { if (x == 0) { return 0 } else if (x == 10) { - test(0, "no tail") - return 1 + test(x - 1, "no tail") + test(0) + return 1 + test(x - 1) } else { - return test(x - 1, "tail") + return test(x - 1) } } -fun box() : String = if (test(1000000, "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (test(1000000) == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/thisReferences.kt b/compiler/testData/codegen/box/functions/tailRecursion/thisReferences.kt index 102315ba347..14e8ec62ff9 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/thisReferences.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/thisReferences.kt @@ -1,25 +1,23 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - class A { - tailRecursive fun f1(c : Int, x : Any) { + tailRecursive fun f1(c : Int) { if (c > 0) { - this.f1(c - 1, "tail") + this.f1(c - 1) } } - tailRecursive fun f2(c : Int, x : Any) { + tailRecursive fun f2(c : Int) { if (c > 0) { - f2(c - 1, "tail 108") + f2(c - 1) } } - tailRecursive fun f3(a : A, x : Any) { - a.f3(a, "no tail") // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3() + tailRecursive fun f3(a : A) { + a.f3(a) // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3() } } fun box() : String { - A().f1(1000000, "test") - A().f2(1000000, "test") + A().f1(1000000) + A().f2(1000000) return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/unitBlocks.kt b/compiler/testData/codegen/box/functions/tailRecursion/unitBlocks.kt index ee62445a75c..fcce077c836 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/unitBlocks.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/unitBlocks.kt @@ -1,23 +1,21 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun test(x : Int, e : Any) : Unit { +tailRecursive fun test(x : Int) : Unit { if (x == 1) { - test(x - 1, "tail") + test(x - 1) } else if (x == 2) { - test(x - 1, "tail") + test(x - 1) return } else if (x == 3) { - test(x - 1, "no tail") + test(x - 1) if (x == 3) { - test(x - 1, "tail") + test(x - 1) } return } else if (x > 0) { - test(x - 1, "tail") + test(x - 1) } } fun box() : String { - test(1000000, "test") + test(1000000) return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/whenWithCondition.kt b/compiler/testData/codegen/box/functions/tailRecursion/whenWithCondition.kt index ef8f610cf42..05f60f6be52 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/whenWithCondition.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/whenWithCondition.kt @@ -1,10 +1,8 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun withWhen(counter : Int, x : Any) : Int = +tailRecursive fun withWhen(counter : Int) : Int = when (counter) { 0 -> counter - 50 -> 1 + withWhen(counter - 1, "no tail") - else -> withWhen(counter - 1, "tail") + 50 -> 1 + withWhen(counter - 1) + else -> withWhen(counter - 1) } -fun box() : String = if (withWhen(100000, "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (withWhen(100000) == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/whenWithInRange.kt b/compiler/testData/codegen/box/functions/tailRecursion/whenWithInRange.kt index dd4846cc3c2..6aaec2be201 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/whenWithInRange.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/whenWithInRange.kt @@ -1,13 +1,13 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -tailRecursive fun withWhen(counter : Int, d : Any, x : Any) : Int = +tailRecursive fun withWhen(counter : Int, d : Any) : Int = when (counter) { 0 -> counter - 1, 2 -> withWhen(counter - 1, "1,2", "tail") - in 3..49 -> withWhen(counter - 1, "3..49", "tail") - 50 -> 1 + withWhen(counter - 1, "50", "no tail") - !in 0..50 -> withWhen(counter - 1, "!0..50", "tail") - else -> withWhen(counter - 1, "else", "tail") + 1, 2 -> withWhen(counter - 1, "1,2") + in 3..49 -> withWhen(counter - 1, "3..49") + 50 -> 1 + withWhen(counter - 1, "50") + !in 0..50 -> withWhen(counter - 1, "!0..50") + else -> withWhen(counter - 1, "else") } -fun box() : String = if (withWhen(100000, "test", "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (withWhen(100000, "test") == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/testData/codegen/box/functions/tailRecursion/whenWithIs.kt b/compiler/testData/codegen/box/functions/tailRecursion/whenWithIs.kt index d98215bc61e..bed9765a9e1 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/whenWithIs.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/whenWithIs.kt @@ -1,17 +1,15 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun withWhen(counter : Int, d : Any, x : Any) : Int = +tailRecursive fun withWhen(counter : Int, d : Any) : Int = if (counter == 0) { 0 } else if (counter == 5) { - withWhen(counter - 1, 999, "tail") + withWhen(counter - 1, 999) } else when (d) { - is String -> withWhen(counter - 1, "is String", "tail") - is Number -> withWhen(counter, "is Number", "tail") + is String -> withWhen(counter - 1, "is String") + is Number -> withWhen(counter, "is Number") else -> throw IllegalStateException() } -fun box() : String = if (withWhen(100000, "test", "test") == 0) "OK" else "FAIL" +fun box() : String = if (withWhen(100000, "test") == 0) "OK" else "FAIL" diff --git a/compiler/testData/codegen/box/functions/tailRecursion/whenWithoutCondition.kt b/compiler/testData/codegen/box/functions/tailRecursion/whenWithoutCondition.kt index a129a017b98..019e71f9cd9 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/whenWithoutCondition.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/whenWithoutCondition.kt @@ -1,11 +1,9 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -tailRecursive fun withWhen2(counter : Int, x : Any) : Int = +tailRecursive fun withWhen2(counter : Int) : Int = when { counter == 0 -> counter - counter == 50 -> 1 + withWhen2(counter - 1, "no tail") - withWhen2(0, "no tail") == 0 -> withWhen2(counter - 1, "tail") + counter == 50 -> 1 + withWhen2(counter - 1) + withWhen2(0) == 0 -> withWhen2(counter - 1) else -> 1 } -fun box() : String = if (withWhen2(100000, "test") == 1) "OK" else "FAIL" \ No newline at end of file +fun box() : String = if (withWhen2(100000) == 1) "OK" else "FAIL" \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/AbstractTailRecursionTest.java b/compiler/tests/org/jetbrains/jet/checkers/AbstractTailRecursionTest.java deleted file mode 100644 index 407bd8ed18f..00000000000 --- a/compiler/tests/org/jetbrains/jet/checkers/AbstractTailRecursionTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.checkers; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Predicates; -import com.google.common.collect.Lists; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.ConfigurationKind; -import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport; -import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; -import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind; -import org.jetbrains.jet.lang.descriptors.CallableDescriptor; -import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; -import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.BindingTrace; -import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; -import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; -import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment; -import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -public abstract class AbstractTailRecursionTest extends KotlinTestWithEnvironment { - - @Override - protected JetCoreEnvironment createEnvironment() { - return createEnvironmentWithMockJdk(ConfigurationKind.JDK_AND_ANNOTATIONS); - } - - public void doTest(@NotNull String testFile) throws IOException { - JetFile file = JetPsiFactory.createFile(getProject(), FileUtil.loadFile(new File(testFile), true)); - List files = new ArrayList(Collections.singleton(file)); - - final BindingTrace trace = CliLightClassGenerationSupport.getInstanceForCli(getProject()).getTrace(); - assertNotNull("No binding trace found for test", trace); - - AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( - getProject(), files, trace, - Collections.emptyList(), Predicates.alwaysTrue(), false).getBindingContext(); - - file.acceptChildren(new JetTreeVisitor() { - - @Override - public Void visitNamedFunction(@NotNull JetNamedFunction function, @Nullable Data outerData) { - SimpleFunctionDescriptor descriptor = trace.get(BindingContext.FUNCTION, function); - assert descriptor != null : "can't get function descriptor from binding by function declaration node"; - - Data data = new Data(descriptor); - super.visitNamedFunction(function, data); - - if (data.isTail) { - List calls = trace.get(BindingContext.FUNCTION_RECURSIVE_CALL_EXPRESSIONS, descriptor); - if (calls == null) { - calls = Collections.emptyList(); - } - - List detectedRecursions = new ArrayList(calls); - List expectedRecursions = new ArrayList(data.visitedCalls); - - Collections.sort(detectedRecursions, new CallComparator()); - Collections.sort(expectedRecursions, new CallComparator()); - - assertEquals( - "Bad detected tail recursions list for " + descriptor, - stringListOfCallExpressions(expectedRecursions), - stringListOfCallExpressions(detectedRecursions) - ); - } - - return null; - } - - @Override - public Void visitCallExpression(@NotNull JetCallExpression expression, @Nullable Data data) { - if (data != null && data.isTail) { - ResolvedCall call = - trace.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression()); - - assert call != null : "call node is not yet resolved"; - if (data.functionDescriptor.equals(call.getCandidateDescriptor())) { - JetValueArgumentList argumentList = expression.getValueArgumentList(); - assert argumentList != null : "function call have no arguments list"; - - checkCall(data.functionDescriptor, expression, argumentList, trace); - data.visitedCalls.add(expression); - } - } - - super.visitCallExpression(expression, data); - return null; - } - }, null); - } - - private static String stringListOfCallExpressions(List expectedRecursions) { - return Joiner.on(",\n").skipNulls().join(Lists.transform(expectedRecursions, new CallExpressionToText())); - } - - private static class Data { - public final SimpleFunctionDescriptor functionDescriptor; - public final boolean isTail; - public final List visitedCalls = new ArrayList(); - - private Data(@NotNull SimpleFunctionDescriptor descriptor) { - functionDescriptor = descriptor; - isTail = KotlinBuiltIns.getInstance().isTailRecursive(descriptor); - } - } - - private static void checkCall( - SimpleFunctionDescriptor functionDescriptor, - JetCallExpression expression, - JetValueArgumentList argumentList, - BindingTrace trace - ) { - int size = argumentList.getArguments().size(); - boolean shouldBeTail = size == 0 || isLastArgumentTail(argumentList.getArguments()); - TailRecursionKind status = trace.get(BindingContext.TAIL_RECURSION_CALL, expression); - assertNotNull("Call is not checked for tail recursion", status); - assertEquals("Tail-recursion detection failed for " + functionDescriptor.getName().asString() + " at " + expression.getText(), - shouldBeTail, status.isDoGenerateTailRecursion()); - } - - private static boolean isLastArgumentTail(List arguments) { - JetValueArgument lastArgument = arguments.get(arguments.size() - 1); - JetExpression expression = lastArgument.getArgumentExpression(); - if (expression instanceof JetStringTemplateExpression) { - JetStringTemplateEntry[] entries = ((JetStringTemplateExpression) expression).getEntries(); - StringBuilder sb = new StringBuilder(); - for (JetStringTemplateEntry entry : entries) { - sb.append(entry.getText()); - } - - return !sb.toString().trim().equals("no tail"); - } - - return true; - } - - private static class CallComparator implements Comparator { - @Override - public int compare(@NotNull JetCallExpression o1, @NotNull JetCallExpression o2) { - return o1.getTextOffset() - o2.getTextOffset(); - } - } - - private static class CallExpressionToText implements Function { - @Override - public String apply(JetCallExpression input) { - if (input == null) return null; - return ("\"" + input.getText().replace("\"", "\\\"").trim() + "\""); - } - } -} diff --git a/compiler/tests/org/jetbrains/jet/checkers/TailRecursionDetectorTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/TailRecursionDetectorTestGenerated.java deleted file mode 100644 index 63f9e2377af..00000000000 --- a/compiler/tests/org/jetbrains/jet/checkers/TailRecursionDetectorTestGenerated.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.checkers; - -import junit.framework.Assert; -import junit.framework.Test; -import junit.framework.TestSuite; - -import java.io.File; -import java.util.regex.Pattern; -import org.jetbrains.jet.JetTestUtils; -import org.jetbrains.jet.test.InnerTestClasses; -import org.jetbrains.jet.test.TestMetadata; - -import org.jetbrains.jet.checkers.AbstractTailRecursionTest; - -/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("compiler/testData/codegen/box/functions/tailRecursion") -public class TailRecursionDetectorTestGenerated extends AbstractTailRecursionTest { - public void testAllFilesPresentInTailRecursion() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/functions/tailRecursion"), Pattern.compile("^(.+)\\.kt$"), true); - } - - @TestMetadata("defaultArgs.kt") - public void testDefaultArgs() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/defaultArgs.kt"); - } - - @TestMetadata("infixCall.kt") - public void testInfixCall() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/infixCall.kt"); - } - - @TestMetadata("insideElvis.kt") - public void testInsideElvis() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/insideElvis.kt"); - } - - @TestMetadata("labeledThisReferences.kt") - public void testLabeledThisReferences() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/labeledThisReferences.kt"); - } - - @TestMetadata("loops.kt") - public void testLoops() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/loops.kt"); - } - - @TestMetadata("multilevelBlocks.kt") - public void testMultilevelBlocks() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/multilevelBlocks.kt"); - } - - @TestMetadata("realIteratorFoldl.kt") - public void testRealIteratorFoldl() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/realIteratorFoldl.kt"); - } - - @TestMetadata("realStringEscape.kt") - public void testRealStringEscape() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/realStringEscape.kt"); - } - - @TestMetadata("realStringRepeat.kt") - public void testRealStringRepeat() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/realStringRepeat.kt"); - } - - @TestMetadata("recursiveInnerFunction.kt") - public void testRecursiveInnerFunction() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/recursiveInnerFunction.kt"); - } - - @TestMetadata("returnIf.kt") - public void testReturnIf() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/returnIf.kt"); - } - - @TestMetadata("returnInCatch.kt") - public void testReturnInCatch() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/returnInCatch.kt"); - } - - @TestMetadata("returnInFinally.kt") - public void testReturnInFinally() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/returnInFinally.kt"); - } - - @TestMetadata("returnInIfInFinally.kt") - public void testReturnInIfInFinally() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/returnInIfInFinally.kt"); - } - - @TestMetadata("returnInTry.kt") - public void testReturnInTry() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/returnInTry.kt"); - } - - @TestMetadata("simpleBlock.kt") - public void testSimpleBlock() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/simpleBlock.kt"); - } - - @TestMetadata("simpleReturn.kt") - public void testSimpleReturn() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/simpleReturn.kt"); - } - - @TestMetadata("simpleReturnWithElse.kt") - public void testSimpleReturnWithElse() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/simpleReturnWithElse.kt"); - } - - @TestMetadata("thisReferences.kt") - public void testThisReferences() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/thisReferences.kt"); - } - - @TestMetadata("unitBlocks.kt") - public void testUnitBlocks() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/unitBlocks.kt"); - } - - @TestMetadata("whenWithCondition.kt") - public void testWhenWithCondition() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/whenWithCondition.kt"); - } - - @TestMetadata("whenWithInRange.kt") - public void testWhenWithInRange() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/whenWithInRange.kt"); - } - - @TestMetadata("whenWithIs.kt") - public void testWhenWithIs() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/whenWithIs.kt"); - } - - @TestMetadata("whenWithoutCondition.kt") - public void testWhenWithoutCondition() throws Exception { - doTest("compiler/testData/codegen/box/functions/tailRecursion/whenWithoutCondition.kt"); - } - -}