small fixes: case with function literal in a block

analyze function literals in 'independent' mode, todo comment added
This commit is contained in:
Svetlana Isakova
2013-09-02 13:15:42 +04:00
parent c739632c57
commit 3f72c7a9e1
2 changed files with 13 additions and 6 deletions
@@ -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
@@ -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<D> 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<D> newContext =
context.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument);
CallCandidateResolutionContext<D> newContext = context
.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument)
.replaceContextDependency(ContextDependency.INDEPENDENT);
JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo(argumentExpression, functionLiteralExpression, newContext,
RESOLVE_FUNCTION_ARGUMENTS).getType();
constraintSystem.addSubtypeConstraint(