From bd40ce18ff575a49110df11f5e560abdc6027050 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 18 Jul 2012 20:48:30 +0400 Subject: [PATCH] added class ValueArgumentsCheckingResult instead of null for List in arguments --- .../jet/lang/resolve/calls/CallResolver.java | 67 +++++++++++-------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index c1c05d5edea..6d96098ced6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -297,7 +297,7 @@ public class CallResolver { @NotNull BasicResolutionContext context, @NotNull OverloadResolutionResults results, @Nullable TracingStrategy tracing) { - if (results.getResultCode() != OverloadResolutionResults.Code.DIRTY) return results; + if (results.getResultCode() != OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE) return results; Set> successful = Sets.newLinkedHashSet(); Set> failed = Sets.newLinkedHashSet(); for (ResolvedCall call : results.getResultingCalls()) { @@ -357,8 +357,7 @@ public class CallResolver { if (!constraintsSystem.isSuccessful()) { - List argumentTypes = Lists.newArrayList(); - checkValueArgumentTypes(context, resolvedCall, context.trace, argumentTypes); + List argumentTypes = checkValueArgumentTypes(context, resolvedCall, context.trace).argumentTypes; JetType receiverType = resolvedCall.getReceiverArgument().exists() ? resolvedCall.getReceiverArgument().getType() : null; reportTypeInferenceFailed(context.trace, context.call, InferenceErrorData.create(descriptor, constraintsSystem, argumentTypes, receiverType)); @@ -373,7 +372,7 @@ public class CallResolver { resolvedCall.setResultingDescriptor(substitute); //replacement // Here we type check the arguments with inferred types expected - checkValueArgumentTypes(context, resolvedCall, context.trace, null); + checkValueArgumentTypes(context, resolvedCall, context.trace); checkBounds(resolvedCall, constraintsSystem, context); resolvedCall.setHasUnknownTypeParameters(false); @@ -466,7 +465,7 @@ public class CallResolver { return results; } - if (results.getResultCode() == OverloadResolutionResults.Code.DIRTY) { + if (results.getResultCode() == OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE) { results.setTrace(taskTrace); return results; } @@ -588,7 +587,7 @@ public class CallResolver { OverloadResolutionResultsImpl results = computeResultAndReportErrors(task.trace, task.tracing, successfulCandidates, failedCandidates); - if (!results.isSingleResult() && results.getResultCode() != OverloadResolutionResults.Code.DIRTY) { + if (!results.isSingleResult() && results.getResultCode() != OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE) { checkTypesWithNoCallee(task.toBasic()); } return results; @@ -638,7 +637,7 @@ public class CallResolver { candidateCall.addStatus(status); } else { - candidateCall.addStatus(checkAllValueArguments(context, null)); + candidateCall.addStatus(checkAllValueArguments(context).status); } } else { @@ -674,7 +673,7 @@ public class CallResolver { TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i); candidateCall.recordTypeArgument(typeParameterDescriptor, typeArguments.get(i)); } - candidateCall.addStatus(checkAllValueArguments(context, null)); + candidateCall.addStatus(checkAllValueArguments(context).status); } else { candidateCall.addStatus(OTHER_ERROR); @@ -765,8 +764,9 @@ public class CallResolver { return SUCCESS; } else { - List argumentTypes = Lists.newArrayList(); - ResolutionStatus argumentsStatus = checkAllValueArguments(context, argumentTypes); + ValueArgumentsCheckingResult checkingResult = checkAllValueArguments(context); + ResolutionStatus argumentsStatus = checkingResult.status; + List argumentTypes = checkingResult.argumentTypes; JetType receiverType = candidateCall.getReceiverArgument().exists() ? candidateCall.getReceiverArgument().getType() : null; reportTypeInferenceFailed(context.trace, context.call, InferenceErrorData.create(candidate, constraintsBuilderWithRightTypeParameters, argumentTypes, receiverType)); @@ -862,8 +862,9 @@ public class CallResolver { } } - private ResolutionStatus checkAllValueArguments(CallResolutionContext context, @Nullable List argumentTypes) { - ResolutionStatus result = checkValueArgumentTypes(context, context.candidateCall, argumentTypes); + private ValueArgumentsCheckingResult checkAllValueArguments(CallResolutionContext context) { + ValueArgumentsCheckingResult checkingResult = checkValueArgumentTypes(context, context.candidateCall); + ResolutionStatus resultStatus = checkingResult.status; ResolvedCall candidateCall = context.candidateCall; // Comment about a very special case. @@ -871,14 +872,14 @@ public class CallResolver { // both 'b' (receiver) and 'foo' (this object) might be nullable. In the first case we mark dot, in the second 'foo'. // Class 'CallForImplicitInvoke' helps up to recognise this case, and parameter 'implicitInvokeCheck' helps us to distinguish whether we check receiver or this object. - result = result.combine(checkReceiver(context, candidateCall, candidateCall.getResultingDescriptor().getReceiverParameter(), candidateCall.getReceiverArgument(), + resultStatus = resultStatus.combine(checkReceiver(context, candidateCall, candidateCall.getResultingDescriptor().getReceiverParameter(), candidateCall.getReceiverArgument(), candidateCall.getExplicitReceiverKind().isReceiver(), false)); - result = result.combine(checkReceiver(context, candidateCall, candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(), + resultStatus = resultStatus.combine(checkReceiver(context, candidateCall, candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(), candidateCall.getExplicitReceiverKind().isThisObject(), // for the invocation 'foo(1)' where foo is a variable of function type we should mark 'foo' if there is unsafe call error context.call instanceof CallTransformer.CallForImplicitInvoke)); - return result; + return new ValueArgumentsCheckingResult(resultStatus, checkingResult.argumentTypes); } private ResolutionStatus checkReceiver(CallResolutionContext context, ResolvedCall candidateCall, @@ -913,14 +914,24 @@ public class CallResolver { return result; } - private ResolutionStatus checkValueArgumentTypes(ResolutionContext context, ResolvedCallImpl candidateCall, List argumentTypes) { - return checkValueArgumentTypes(context, candidateCall, candidateCall.getTrace(), argumentTypes); + private static class ValueArgumentsCheckingResult { + public final List argumentTypes; + public final ResolutionStatus status; + + private ValueArgumentsCheckingResult(@NotNull ResolutionStatus status, @NotNull List argumentTypes) { + this.status = status; + this.argumentTypes = argumentTypes; + } } - private ResolutionStatus checkValueArgumentTypes(ResolutionContext context, ResolvedCallImpl candidateCall, BindingTrace trace, - @Nullable List argumentTypes) { - ResolutionStatus result = SUCCESS; + private ValueArgumentsCheckingResult checkValueArgumentTypes(ResolutionContext context, ResolvedCallImpl candidateCall) { + return checkValueArgumentTypes(context, candidateCall, candidateCall.getTrace()); + } + + private ValueArgumentsCheckingResult checkValueArgumentTypes(ResolutionContext context, ResolvedCallImpl candidateCall, BindingTrace trace) { + ResolutionStatus resultStatus = SUCCESS; DataFlowInfo dataFlowInfo = context.dataFlowInfo; + List argumentTypes = Lists.newArrayList(); for (Map.Entry entry : candidateCall.getValueArguments().entrySet()) { ValueParameterDescriptor parameterDescriptor = entry.getKey(); ResolvedValueArgument resolvedArgument = entry.getValue(); @@ -936,9 +947,7 @@ public class CallResolver { } JetTypeInfo typeInfo = expressionTypingServices.getTypeInfo(context.scope, expression, expectedType, dataFlowInfo, trace); JetType type = typeInfo.getType(); - if (argumentTypes != null) { - argumentTypes.add(type); - } + argumentTypes.add(type); dataFlowInfo = dataFlowInfo.and(typeInfo.getDataFlowInfo()); if (type == null || ErrorUtils.isErrorType(type)) { candidateCall.argumentHasNoType(); @@ -959,16 +968,16 @@ public class CallResolver { // } // else { // temporaryTrace.report(AUTOCAST_IMPOSSIBLE.on(argument, autoCastType, variableDescriptor)); -// result = false; +// resultStatus = false; // } // } // } // else { - result = OTHER_ERROR; + resultStatus = OTHER_ERROR; } } } - return result; + return new ValueArgumentsCheckingResult(resultStatus, argumentTypes); } @NotNull @@ -1056,7 +1065,7 @@ public class CallResolver { ResolvedCallWithTrace failed = failedCandidates.iterator().next(); failed.getTrace().commit(); if (failed.getStatus() != ResolutionStatus.STRONG_ERROR && failed.hasUnknownTypeParameters()) { - return OverloadResolutionResultsImpl.dirty(failed); + return OverloadResolutionResultsImpl.incompleteTypeInference(failed); } return OverloadResolutionResultsImpl.singleFailedCandidate(failed); } @@ -1105,7 +1114,7 @@ public class CallResolver { Set> noOverrides = OverridingUtil.filterOverrides(candidates, MAP_TO_RESULT); if (dirty) { - return OverloadResolutionResultsImpl.dirty(candidates); + return OverloadResolutionResultsImpl.incompleteTypeInference(candidates); } return OverloadResolutionResultsImpl.ambiguity(noOverrides); @@ -1116,7 +1125,7 @@ public class CallResolver { TemporaryBindingTrace temporaryTrace = result.getTrace(); temporaryTrace.commit(); if (result.hasUnknownTypeParameters()) { - return OverloadResolutionResultsImpl.dirty(result); + return OverloadResolutionResultsImpl.incompleteTypeInference(result); } return OverloadResolutionResultsImpl.success(result);