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) {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user