From 3f72c7a9e127df5b8948d4c146082958107e49d4 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 2 Sep 2013 13:15:42 +0400 Subject: [PATCH] small fixes: case with function literal in a block analyze function literals in 'independent' mode, todo comment added --- .../lang/resolve/calls/ArgumentTypeResolver.java | 4 ++-- .../jet/lang/resolve/calls/CandidateResolver.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java index 5e6132e002e..0de68454ffa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ArgumentTypeResolver.java @@ -172,7 +172,7 @@ public class ArgumentTypeResolver { if (expression == null) { return JetTypeInfo.create(null, context.dataFlowInfo); } - JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(expression, false); + JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(JetPsiUtil.unwrapFromBlock(expression), false); if (deparenthesizedExpression instanceof JetFunctionLiteralExpression) { return getFunctionLiteralTypeInfo(expression, (JetFunctionLiteralExpression) deparenthesizedExpression, context, resolveArgumentsMode); } @@ -201,7 +201,7 @@ public class ArgumentTypeResolver { } @Nullable - private JetType getFunctionLiteralType( + public JetType getFunctionLiteralType( @NotNull JetFunctionLiteralExpression expression, @NotNull JetScope scope, @NotNull BindingTrace trace 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 16fb2c34697..3fd5b0d6635 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 @@ -476,12 +476,16 @@ public class CandidateResolver { ) { JetExpression argumentExpression = valueArgument.getArgumentExpression(); if (argumentExpression == null) return; - JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(argumentExpression, false); + JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution( + JetPsiUtil.unwrapFromBlock(argumentExpression), false); if (!(deparenthesizedExpression instanceof JetFunctionLiteralExpression)) return; JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) deparenthesizedExpression; JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument); JetType expectedType = constraintSystem.getCurrentSubstitutor().substitute(effectiveExpectedType, Variance.INVARIANT); + if (expectedType == null || expectedType == DONT_CARE) { + expectedType = argumentTypeResolver.getFunctionLiteralType(functionLiteralExpression, context.scope, context.trace); + } if (expectedType == null || !KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType) || CallResolverUtil.hasUnknownFunctionParameter(expectedType)) { return; @@ -489,6 +493,7 @@ public class CandidateResolver { MutableDataFlowInfoForArguments dataFlowInfoForArguments = context.candidateCall.getDataFlowInfoForArguments(); DataFlowInfo dataFlowInfoForArgument = dataFlowInfoForArguments.getInfo(valueArgument); + //todo analyze function literal body once in 'dependent' mode, then complete it with respect to expected type boolean hasExpectedReturnType = !CallResolverUtil.hasUnknownReturnType(expectedType); if (hasExpectedReturnType) { TemporaryTraceAndCache temporaryToResolveFunctionLiteral = TemporaryTraceAndCache.create( @@ -501,7 +506,8 @@ public class CandidateResolver { temporaryToResolveFunctionLiteral.trace, statementExpression, mismatch); CallCandidateResolutionContext newContext = context .replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType) - .replaceDataFlowInfo(dataFlowInfoForArgument).replaceResolutionResultsCache(temporaryToResolveFunctionLiteral.cache); + .replaceDataFlowInfo(dataFlowInfoForArgument).replaceResolutionResultsCache(temporaryToResolveFunctionLiteral.cache) + .replaceContextDependency(ContextDependency.INDEPENDENT); JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo( argumentExpression, functionLiteralExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType(); if (!mismatch[0]) { @@ -512,8 +518,9 @@ public class CandidateResolver { } } JetType expectedTypeWithoutReturnType = hasExpectedReturnType ? CallResolverUtil.replaceReturnTypeByUnknown(expectedType) : expectedType; - CallCandidateResolutionContext newContext = - context.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument); + CallCandidateResolutionContext newContext = context + .replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument) + .replaceContextDependency(ContextDependency.INDEPENDENT); JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo(argumentExpression, functionLiteralExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType(); constraintSystem.addSubtypeConstraint(