refactoring: invocation 'getArgumentTypeInfo' changed to 'getFunctionLiteralTypeInfo'

for function literals
This commit is contained in:
Svetlana Isakova
2013-02-20 12:39:46 +04:00
parent 6e51b83afc
commit 6739f7ca24
2 changed files with 21 additions and 6 deletions
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices; import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
@@ -163,14 +164,13 @@ public class ArgumentTypeResolver {
public TypeInfoForCall getArgumentTypeInfo( public TypeInfoForCall getArgumentTypeInfo(
@Nullable JetExpression expression, @Nullable JetExpression expression,
@NotNull CallResolutionContext context, @NotNull CallResolutionContext context,
@NotNull ResolveArgumentsMode resolveFunctionArgumentBodies @NotNull ResolveArgumentsMode resolveArgumentsMode
) { ) {
if (expression == null) { if (expression == null) {
return TypeInfoForCall.create(null, context.dataFlowInfo); return TypeInfoForCall.create(null, context.dataFlowInfo);
} }
if (expression instanceof JetFunctionLiteralExpression && resolveFunctionArgumentBodies == SKIP_FUNCTION_ARGUMENTS) { if (expression instanceof JetFunctionLiteralExpression) {
JetType type = getFunctionLiteralType((JetFunctionLiteralExpression) expression, context.scope, context.trace); return TypeInfoForCall.create(getFunctionLiteralTypeInfo((JetFunctionLiteralExpression) expression, context, resolveArgumentsMode));
return TypeInfoForCall.create(type, context.dataFlowInfo);
} }
TypeInfoForCall cachedTypeInfo = getRecordedTypeInfoForCall(expression, context); TypeInfoForCall cachedTypeInfo = getRecordedTypeInfoForCall(expression, context);
if (cachedTypeInfo != null) { if (cachedTypeInfo != null) {
@@ -200,6 +200,19 @@ public class ArgumentTypeResolver {
expressionTypingServices.getTypeInfo(context.scope, expression, context.expectedType, context.dataFlowInfo, context.trace)); expressionTypingServices.getTypeInfo(context.scope, expression, context.expectedType, context.dataFlowInfo, context.trace));
} }
@NotNull
public JetTypeInfo getFunctionLiteralTypeInfo(
@NotNull JetFunctionLiteralExpression functionLiteralExpression,
@NotNull CallResolutionContext context,
@NotNull ResolveArgumentsMode resolveArgumentsMode
) {
if (resolveArgumentsMode == SKIP_FUNCTION_ARGUMENTS) {
JetType type = getFunctionLiteralType(functionLiteralExpression, context.scope, context.trace);
return JetTypeInfo.create(type, context.dataFlowInfo);
}
return expressionTypingServices.getTypeInfo(context.scope, functionLiteralExpression, context.expectedType, context.dataFlowInfo, context.trace);
}
@Nullable @Nullable
private JetType getFunctionLiteralType( private JetType getFunctionLiteralType(
@NotNull JetFunctionLiteralExpression expression, @NotNull JetFunctionLiteralExpression expression,
@@ -335,7 +335,8 @@ public class CandidateResolver {
traceToResolveFunctionLiteral, statementExpression, mismatch); traceToResolveFunctionLiteral, statementExpression, mismatch);
CallCandidateResolutionContext<D> newContext = CallCandidateResolutionContext<D> newContext =
context.replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType); context.replaceBindingTrace(errorInterceptingTrace).replaceExpectedType(expectedType);
JetType type = argumentTypeResolver.getArgumentTypeInfo(argumentExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType(); JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo((JetFunctionLiteralExpression) argumentExpression, newContext,
RESOLVE_FUNCTION_ARGUMENTS).getType();
if (!mismatch[0]) { if (!mismatch[0]) {
constraintSystem.addSubtypeConstraint( constraintSystem.addSubtypeConstraint(
type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition(valueParameterDescriptor.getIndex())); type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition(valueParameterDescriptor.getIndex()));
@@ -346,7 +347,8 @@ public class CandidateResolver {
} }
JetType expectedTypeWithoutReturnType = hasExpectedReturnType ? CallResolverUtil.replaceReturnTypeByUnknown(expectedType) : expectedType; JetType expectedTypeWithoutReturnType = hasExpectedReturnType ? CallResolverUtil.replaceReturnTypeByUnknown(expectedType) : expectedType;
CallCandidateResolutionContext<D> newContext = context.replaceExpectedType(expectedTypeWithoutReturnType); CallCandidateResolutionContext<D> newContext = context.replaceExpectedType(expectedTypeWithoutReturnType);
JetType type = argumentTypeResolver.getArgumentTypeInfo(argumentExpression, newContext, RESOLVE_FUNCTION_ARGUMENTS).getType(); JetType type = argumentTypeResolver.getFunctionLiteralTypeInfo((JetFunctionLiteralExpression) argumentExpression, newContext,
RESOLVE_FUNCTION_ARGUMENTS).getType();
constraintSystem.addSubtypeConstraint( constraintSystem.addSubtypeConstraint(
type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition(valueParameterDescriptor.getIndex())); type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition(valueParameterDescriptor.getIndex()));
} }