From 52848f6aa4d8a02a85fbd000d205d70f27de6750 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 16 Aug 2013 18:55:44 +0400 Subject: [PATCH] Use temporary cache when resolve function literals twice --- .../lang/resolve/calls/CandidateResolver.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index 6bae36483f6..40870e98777 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -536,29 +536,34 @@ public class CandidateResolver { || CallResolverUtil.hasUnknownFunctionParameter(expectedType)) { return; } + MutableDataFlowInfoForArguments dataFlowInfoForArguments = context.candidateCall.getDataFlowInfoForArguments(); + DataFlowInfo dataFlowInfoForArgument = dataFlowInfoForArguments.getInfo(valueArgument); + boolean hasExpectedReturnType = !CallResolverUtil.hasUnknownReturnType(expectedType); if (hasExpectedReturnType) { - TemporaryBindingTrace traceToResolveFunctionLiteral = TemporaryBindingTrace.create( - context.trace, "trace to resolve function literal with expected return type", argumentExpression); + TemporaryTraceAndCache temporaryToResolveFunctionLiteral = TemporaryTraceAndCache.create( + context, "trace to resolve function literal with expected return type", argumentExpression); JetElement statementExpression = JetPsiUtil.getLastStatementInABlock(((JetFunctionLiteralExpression) argumentExpression).getBodyExpression()); if (statementExpression == null) return; boolean[] mismatch = new boolean[1]; ObservableBindingTrace errorInterceptingTrace = ExpressionTypingUtils.makeTraceInterceptingTypeMismatch( - traceToResolveFunctionLiteral, statementExpression, mismatch); - CallCandidateResolutionContext newContext = - context.replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType); + temporaryToResolveFunctionLiteral.trace, statementExpression, mismatch); + CallCandidateResolutionContext newContext = context + .replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType) + .replaceDataFlowInfo(dataFlowInfoForArgument).replaceResolutionResultsCache(temporaryToResolveFunctionLiteral.cache); JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo( (JetFunctionLiteralExpression) argumentExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType(); if (!mismatch[0]) { constraintSystem.addSubtypeConstraint( type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition(valueParameterDescriptor.getIndex())); - traceToResolveFunctionLiteral.commit(); + temporaryToResolveFunctionLiteral.commit(); return; } } JetType expectedTypeWithoutReturnType = hasExpectedReturnType ? CallResolverUtil.replaceReturnTypeByUnknown(expectedType) : expectedType; - CallCandidateResolutionContext newContext = context.replaceExpectedType(expectedTypeWithoutReturnType); + CallCandidateResolutionContext newContext = + context.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument); JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo((JetFunctionLiteralExpression) argumentExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType(); constraintSystem.addSubtypeConstraint(