Do not rely on JetCallExpressions in tail-call detection

Calls come in other forms too
This commit is contained in:
Andrey Breslav
2013-12-05 21:10:34 +04:00
parent 9ed0b009d4
commit 6d369b985f
5 changed files with 12 additions and 11 deletions
@@ -1595,9 +1595,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (returnedExpression != null) {
if (returnedExpression instanceof JetCallExpression) {
JetCallExpression callExpression = (JetCallExpression) returnedExpression;
if (tailRecursionGeneratorUtil.isTailRecursion(callExpression) && callExpression.getCalleeExpression() != null) {
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
if (resolvedCall != null) {
JetExpression calleeExpression = callExpression.getCalleeExpression();
if (calleeExpression != null) {
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, calleeExpression);
if (resolvedCall != null && tailRecursionGeneratorUtil.isTailRecursion(resolvedCall)) {
return tailRecursionGeneratorUtil.generateTailRecursion(resolvedCall, callExpression);
}
}
@@ -1932,7 +1933,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
}
if (tailRecursionGeneratorUtil.isTailRecursion(expression)) {
if (tailRecursionGeneratorUtil.isTailRecursion(resolvedCall)) {
return tailRecursionGeneratorUtil.generateTailRecursion(resolvedCall, expression);
}
@@ -61,8 +61,8 @@ public class TailRecursionGeneratorUtil {
this.state = state;
}
public boolean isTailRecursion(@NotNull JetCallExpression expression) {
TailRecursionKind status = state.getBindingContext().get(TAIL_RECURSION_CALL, expression);
public boolean isTailRecursion(@NotNull ResolvedCall<?> resolvedCall) {
TailRecursionKind status = state.getBindingContext().get(TAIL_RECURSION_CALL, resolvedCall);
return status != null && status.isDoGenerateTailRecursion();
}