small fixes: case with function literal in a block
analyze function literals in 'independent' mode, todo comment added
This commit is contained in:
+2
-2
@@ -172,7 +172,7 @@ public class ArgumentTypeResolver {
|
|||||||
if (expression == null) {
|
if (expression == null) {
|
||||||
return JetTypeInfo.create(null, context.dataFlowInfo);
|
return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(expression, false);
|
JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(JetPsiUtil.unwrapFromBlock(expression), false);
|
||||||
if (deparenthesizedExpression instanceof JetFunctionLiteralExpression) {
|
if (deparenthesizedExpression instanceof JetFunctionLiteralExpression) {
|
||||||
return getFunctionLiteralTypeInfo(expression, (JetFunctionLiteralExpression) deparenthesizedExpression, context, resolveArgumentsMode);
|
return getFunctionLiteralTypeInfo(expression, (JetFunctionLiteralExpression) deparenthesizedExpression, context, resolveArgumentsMode);
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ public class ArgumentTypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private JetType getFunctionLiteralType(
|
public JetType getFunctionLiteralType(
|
||||||
@NotNull JetFunctionLiteralExpression expression,
|
@NotNull JetFunctionLiteralExpression expression,
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@NotNull BindingTrace trace
|
@NotNull BindingTrace trace
|
||||||
|
|||||||
@@ -476,12 +476,16 @@ public class CandidateResolver {
|
|||||||
) {
|
) {
|
||||||
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
||||||
if (argumentExpression == null) return;
|
if (argumentExpression == null) return;
|
||||||
JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(argumentExpression, false);
|
JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesizeWithNoTypeResolution(
|
||||||
|
JetPsiUtil.unwrapFromBlock(argumentExpression), false);
|
||||||
if (!(deparenthesizedExpression instanceof JetFunctionLiteralExpression)) return;
|
if (!(deparenthesizedExpression instanceof JetFunctionLiteralExpression)) return;
|
||||||
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) deparenthesizedExpression;
|
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) deparenthesizedExpression;
|
||||||
|
|
||||||
JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument);
|
JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument);
|
||||||
JetType expectedType = constraintSystem.getCurrentSubstitutor().substitute(effectiveExpectedType, Variance.INVARIANT);
|
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)
|
if (expectedType == null || !KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)
|
||||||
|| CallResolverUtil.hasUnknownFunctionParameter(expectedType)) {
|
|| CallResolverUtil.hasUnknownFunctionParameter(expectedType)) {
|
||||||
return;
|
return;
|
||||||
@@ -489,6 +493,7 @@ public class CandidateResolver {
|
|||||||
MutableDataFlowInfoForArguments dataFlowInfoForArguments = context.candidateCall.getDataFlowInfoForArguments();
|
MutableDataFlowInfoForArguments dataFlowInfoForArguments = context.candidateCall.getDataFlowInfoForArguments();
|
||||||
DataFlowInfo dataFlowInfoForArgument = dataFlowInfoForArguments.getInfo(valueArgument);
|
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);
|
boolean hasExpectedReturnType = !CallResolverUtil.hasUnknownReturnType(expectedType);
|
||||||
if (hasExpectedReturnType) {
|
if (hasExpectedReturnType) {
|
||||||
TemporaryTraceAndCache temporaryToResolveFunctionLiteral = TemporaryTraceAndCache.create(
|
TemporaryTraceAndCache temporaryToResolveFunctionLiteral = TemporaryTraceAndCache.create(
|
||||||
@@ -501,7 +506,8 @@ public class CandidateResolver {
|
|||||||
temporaryToResolveFunctionLiteral.trace, statementExpression, mismatch);
|
temporaryToResolveFunctionLiteral.trace, statementExpression, mismatch);
|
||||||
CallCandidateResolutionContext<D> newContext = context
|
CallCandidateResolutionContext<D> newContext = context
|
||||||
.replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType)
|
.replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType)
|
||||||
.replaceDataFlowInfo(dataFlowInfoForArgument).replaceResolutionResultsCache(temporaryToResolveFunctionLiteral.cache);
|
.replaceDataFlowInfo(dataFlowInfoForArgument).replaceResolutionResultsCache(temporaryToResolveFunctionLiteral.cache)
|
||||||
|
.replaceContextDependency(ContextDependency.INDEPENDENT);
|
||||||
JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo(
|
JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo(
|
||||||
argumentExpression, functionLiteralExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType();
|
argumentExpression, functionLiteralExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType();
|
||||||
if (!mismatch[0]) {
|
if (!mismatch[0]) {
|
||||||
@@ -512,8 +518,9 @@ public class CandidateResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
JetType expectedTypeWithoutReturnType = hasExpectedReturnType ? CallResolverUtil.replaceReturnTypeByUnknown(expectedType) : expectedType;
|
JetType expectedTypeWithoutReturnType = hasExpectedReturnType ? CallResolverUtil.replaceReturnTypeByUnknown(expectedType) : expectedType;
|
||||||
CallCandidateResolutionContext<D> newContext =
|
CallCandidateResolutionContext<D> newContext = context
|
||||||
context.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument);
|
.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument)
|
||||||
|
.replaceContextDependency(ContextDependency.INDEPENDENT);
|
||||||
JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo(argumentExpression, functionLiteralExpression, newContext,
|
JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo(argumentExpression, functionLiteralExpression, newContext,
|
||||||
RESOLVE_FUNCTION_ARGUMENTS).getType();
|
RESOLVE_FUNCTION_ARGUMENTS).getType();
|
||||||
constraintSystem.addSubtypeConstraint(
|
constraintSystem.addSubtypeConstraint(
|
||||||
|
|||||||
Reference in New Issue
Block a user