From b23601eefe69542067b840af02274a4ec3578863 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 28 Nov 2012 15:02:37 +0400 Subject: [PATCH] EA-40964 Don't access elements of an empty array --- .../types/expressions/BasicExpressionTypingVisitor.java | 4 +++- .../testData/diagnostics/tests/regressions/ea40964.kt | 8 ++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/regressions/ea40964.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 8b51a08ba97..a5bc7060dc2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -1437,7 +1437,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { List indices = arrayAccessExpression.getIndexExpressions(); // The accumulated data flow info of all index expressions is saved on the last index - dataFlowInfo = facade.getTypeInfo(indices.get(indices.size() - 1), context).getDataFlowInfo(); + if (!indices.isEmpty()) { + dataFlowInfo = facade.getTypeInfo(indices.get(indices.size() - 1), context).getDataFlowInfo(); + } if (!isGet) { dataFlowInfo = facade.getTypeInfo(rightHandSide, context.replaceDataFlowInfo(dataFlowInfo)).getDataFlowInfo(); diff --git a/compiler/testData/diagnostics/tests/regressions/ea40964.kt b/compiler/testData/diagnostics/tests/regressions/ea40964.kt new file mode 100644 index 00000000000..105caef7106 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/ea40964.kt @@ -0,0 +1,8 @@ +package checkFiles + +import java.util.HashMap + +fun main(args: Array) { + val hashMap = HashMap() + hashMap[] +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 9d41815b24b..74dd1487883 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2955,6 +2955,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt"); } + @TestMetadata("ea40964.kt") + public void testEa40964() throws Exception { + doTest("compiler/testData/diagnostics/tests/regressions/ea40964.kt"); + } + @TestMetadata("ErrorsOnIbjectExpressionsAsParameters.kt") public void testErrorsOnIbjectExpressionsAsParameters() throws Exception { doTest("compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.kt");