fixed ArrayIndexOutOfBoundsException in quick fix util
(in 'getParameterCorrespondingToValueArgumentPassedInCall')
This commit is contained in:
@@ -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<JetParameter> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "???" "false"
|
||||
//ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.Array<jet.String></td></tr><tr><td>Found:</td><td>jet.Array<jet.Int></td></tr></table></html>
|
||||
|
||||
//this test checks that there is no ArrayIndexOutOfBoundsException when there are more arguments than parameters
|
||||
fun <T> array1(vararg a : T) = a
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val b = array1(1, 1)
|
||||
join(1, "4", *b, "3")
|
||||
}
|
||||
|
||||
fun join(x : Int, vararg t : String) : String = "$x$t"
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user