complete resolve for array access expression

This commit is contained in:
Svetlana Isakova
2013-08-01 16:12:10 +04:00
parent 051055896d
commit 46cb6b3242
6 changed files with 36 additions and 9 deletions
@@ -344,7 +344,7 @@ public class CandidateResolver {
JetExpression keyExpression = getDeferredComputationKeyExpression(expression);
CallCandidateResolutionContext<FunctionDescriptor> storedContextForArgument =
context.resolutionResultsCache.getDeferredComputation(CallKey.create(Call.CallType.DEFAULT, keyExpression));
context.resolutionResultsCache.getDeferredComputation(keyExpression);
if (storedContextForArgument == null) {
PsiElement parent = expression.getParent();
@@ -16,12 +16,14 @@
package org.jetbrains.jet.lang.resolve.calls.context;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.CallKey;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
@@ -30,6 +32,8 @@ import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
import org.jetbrains.jet.util.slicedmap.Slices;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import static org.jetbrains.jet.lang.psi.Call.CallType;
public class ResolutionResultsCache {
public static class MemberType<D extends CallableDescriptor> {}
@@ -81,8 +85,15 @@ public class ResolutionResultsCache {
}
@Nullable
public CallCandidateResolutionContext<FunctionDescriptor> getDeferredComputation(@NotNull CallKey callKey) {
return trace.get(DEFERRED_COMPUTATION_FOR_CALL, callKey);
public CallCandidateResolutionContext<FunctionDescriptor> getDeferredComputation(@NotNull JetExpression expression) {
for (CallType callType : Lists.newArrayList(CallType.DEFAULT, CallType.ARRAY_GET_METHOD, CallType.ARRAY_SET_METHOD)) {
CallKey callKey = CallKey.create(callType, expression);
CallCandidateResolutionContext<FunctionDescriptor> context = trace.get(DEFERRED_COMPUTATION_FOR_CALL, callKey);
if (context != null) {
return context;
}
}
return null;
}
@NotNull
@@ -1139,7 +1139,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@Override
public JetTypeInfo visitArrayAccessExpression(JetArrayAccessExpression expression, ExpressionTypingContext context) {
JetTypeInfo typeInfo = resolveArrayAccessGetMethod(expression, context.replaceExpectedType(NO_EXPECTED_TYPE));
JetTypeInfo typeInfo = resolveArrayAccessGetMethod(expression, context);
return DataFlowUtils.checkType(typeInfo.getType(), expression, context, typeInfo.getDataFlowInfo());
}
@@ -1289,7 +1289,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetExpression arrayExpression = arrayAccessExpression.getArrayExpression();
if (arrayExpression == null) return JetTypeInfo.create(null, oldContext.dataFlowInfo);
JetTypeInfo arrayTypeInfo = facade.getTypeInfo(arrayExpression, oldContext);
JetTypeInfo arrayTypeInfo = facade.getTypeInfo(arrayExpression, oldContext.replaceExpectedType(NO_EXPECTED_TYPE));
JetType arrayType = arrayTypeInfo.getType();
if (arrayType == null) return arrayTypeInfo;
@@ -1315,7 +1315,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
dataFlowInfo = facade.getTypeInfo(rightHandSide, context.replaceDataFlowInfo(dataFlowInfo)).getDataFlowInfo();
}
if (!functionResults.isSuccess()) {
if (!functionResults.isSingleResult()) {
traceForResolveResult.report(isGet ? NO_GET_METHOD.on(arrayAccessExpression) : NO_SET_METHOD.on(arrayAccessExpression));
return JetTypeInfo.create(null, dataFlowInfo);
}
@@ -4,10 +4,10 @@ fun foo() {
val x: Int? = null
val a = Array<Int>(3, {0})
if (x != null) bar(a[x]) else bar(a<!NO_GET_METHOD!>[<!TYPE_MISMATCH!>x<!>]<!>)
if (x != null) bar(a[x]) else bar(a[<!TYPE_MISMATCH!>x<!>])
bar(a[if (x == null) 0 else x])
bar(a<!NO_GET_METHOD!>[<!TYPE_MISMATCH!>x<!>]<!>)
bar(a[<!TYPE_MISMATCH!>x<!>])
"123"<!NO_GET_METHOD!>[<!TYPE_MISMATCH!>x<!>]<!>;
"123"[<!TYPE_MISMATCH!>x<!>];
if (x != null) "123"[x];
}
@@ -0,0 +1,11 @@
package b
class A {
fun <T> get(i: Int): List<T> = throw Exception("$i")
}
fun bar(l: List<Int>) = l
fun test(a: A) {
bar(a[12])
}
@@ -2846,6 +2846,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/inference/nestedCalls"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("arrayAccess.kt")
public void testArrayAccess() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/nestedCalls/arrayAccess.kt");
}
@TestMetadata("checkTypesForQualifiedProperties.kt")
public void testCheckTypesForQualifiedProperties() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.kt");