From 358c1d6f710fd374c981701e41221d79789a53f8 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 12 Aug 2013 15:34:35 +0400 Subject: [PATCH] fixed ArrayIndexOutOfBoundsException in quick fix util (in 'getParameterCorrespondingToValueArgumentPassedInCall') --- .../jetbrains/jet/plugin/quickfix/QuickFixUtil.java | 8 ++++++-- .../typeMismatch/beforeTooManyArgumentsException.kt | 12 ++++++++++++ .../jet/plugin/quickfix/QuickFixTestGenerated.java | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 idea/testData/quickfix/typeMismatch/beforeTooManyArgumentsException.kt diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java index 11380a56cc4..004ebc88284 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java @@ -36,6 +36,8 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver; +import java.util.List; + public class QuickFixUtil { private QuickFixUtil() { } @@ -132,6 +134,7 @@ public class QuickFixUtil { JetCallExpression callExpression = (JetCallExpression) valueArgumentList.getParent(); JetParameterList parameterList = getParameterListOfCallee(callExpression); if (parameterList == null) return null; + List parameters = parameterList.getParameters(); int position = valueArgumentList.getArguments().indexOf(valueArgument); if (position == -1) return null; @@ -141,7 +144,7 @@ public class QuickFixUtil { String valueArgumentNameAsString = referenceExpression == null ? null : referenceExpression.getReferencedName(); if (valueArgumentNameAsString == null) return null; - for (JetParameter parameter: parameterList.getParameters()) { + for (JetParameter parameter: parameters) { if (valueArgumentNameAsString.equals(parameter.getName())) { return parameter; } @@ -149,7 +152,8 @@ public class QuickFixUtil { return null; } else { - return parameterList.getParameters().get(position); + if (position >= parameters.size()) return null; + return parameters.get(position); } } diff --git a/idea/testData/quickfix/typeMismatch/beforeTooManyArgumentsException.kt b/idea/testData/quickfix/typeMismatch/beforeTooManyArgumentsException.kt new file mode 100644 index 00000000000..710ab0ef006 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/beforeTooManyArgumentsException.kt @@ -0,0 +1,12 @@ +// "???" "false" +//ERROR: Type mismatch.
Required:jet.Array<jet.String>
Found:jet.Array<jet.Int>
+ +//this test checks that there is no ArrayIndexOutOfBoundsException when there are more arguments than parameters +fun array1(vararg a : T) = a + +fun main(args : Array) { + val b = array1(1, 1) + join(1, "4", *b, "3") +} + +fun join(x : Int, vararg t : String) : String = "$x$t" diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index 8ff76ff6135..59f12f60150 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -1539,6 +1539,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest("idea/testData/quickfix/typeMismatch/beforeReturnTypeMismatch.kt"); } + @TestMetadata("beforeTooManyArgumentsException.kt") + public void testTooManyArgumentsException() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/beforeTooManyArgumentsException.kt"); + } + @TestMetadata("idea/testData/quickfix/typeMismatch/casts") public static class Casts extends AbstractQuickFixTest { public void testAllFilesPresentInCasts() throws Exception {