Minor, remove some obsolete usages of ResolutionContext#replaceScope

This commit is contained in:
Alexander Udalov
2016-07-01 16:23:29 +03:00
parent 59b932a815
commit 288c2b5dc9
3 changed files with 15 additions and 20 deletions
@@ -176,7 +176,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (innerExpression == null) { if (innerExpression == null) {
return TypeInfoFactoryKt.noTypeInfo(context); return TypeInfoFactoryKt.noTypeInfo(context);
} }
KotlinTypeInfo result = facade.getTypeInfo(innerExpression, context.replaceScope(context.scope)); KotlinTypeInfo result = facade.getTypeInfo(innerExpression, context);
KotlinType resultType = result.getType(); KotlinType resultType = result.getType();
if (resultType != null) { if (resultType != null) {
DataFlowValue innerValue = DataFlowValueFactory.createDataFlowValue(innerExpression, resultType, context); DataFlowValue innerValue = DataFlowValueFactory.createDataFlowValue(innerExpression, resultType, context);
@@ -1454,7 +1454,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
@NotNull @NotNull
public KotlinTypeInfo getTypeInfoForBinaryCall( private KotlinTypeInfo getTypeInfoForBinaryCall(
@NotNull Name name, @NotNull Name name,
@NotNull ExpressionTypingContext context, @NotNull ExpressionTypingContext context,
@NotNull KtBinaryExpression binaryExpression @NotNull KtBinaryExpression binaryExpression
@@ -1473,10 +1473,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
OverloadResolutionResults<FunctionDescriptor> resolutionResults; OverloadResolutionResults<FunctionDescriptor> resolutionResults;
if (left != null) { if (left != null) {
ExpressionReceiver receiver = safeGetExpressionReceiver(facade, left, context); ExpressionReceiver receiver = safeGetExpressionReceiver(facade, left, context);
resolutionResults = components.callResolver.resolveBinaryCall( resolutionResults = components.callResolver.resolveBinaryCall(contextWithDataFlow, receiver, binaryExpression, name);
contextWithDataFlow.replaceScope(context.scope),
receiver, binaryExpression, name
);
} }
else { else {
resolutionResults = OverloadResolutionResultsImpl.nameNotFound(); resolutionResults = OverloadResolutionResultsImpl.nameNotFound();
@@ -64,17 +64,17 @@ import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.*;
public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
public static final String RETURN_NOT_ALLOWED_MESSAGE = "Return not allowed"; private static final String RETURN_NOT_ALLOWED_MESSAGE = "Return not allowed";
protected ControlStructureTypingVisitor(@NotNull ExpressionTypingInternals facade) { protected ControlStructureTypingVisitor(@NotNull ExpressionTypingInternals facade) {
super(facade); super(facade);
} }
@NotNull @NotNull
private DataFlowInfo checkCondition(@NotNull LexicalScope scope, @Nullable KtExpression condition, ExpressionTypingContext context) { private DataFlowInfo checkCondition(@Nullable KtExpression condition, @NotNull ExpressionTypingContext context) {
if (condition != null) { if (condition != null) {
ExpressionTypingContext conditionContext = context.replaceScope(scope) ExpressionTypingContext conditionContext =
.replaceExpectedType(components.builtIns.getBooleanType()).replaceContextDependency(INDEPENDENT); context.replaceExpectedType(components.builtIns.getBooleanType()).replaceContextDependency(INDEPENDENT);
KotlinTypeInfo typeInfo = facade.getTypeInfo(condition, conditionContext); KotlinTypeInfo typeInfo = facade.getTypeInfo(condition, conditionContext);
return components.dataFlowAnalyzer.checkType(typeInfo, condition, conditionContext).getDataFlowInfo(); return components.dataFlowAnalyzer.checkType(typeInfo, condition, conditionContext).getDataFlowInfo();
@@ -95,7 +95,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE); ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
KtExpression condition = ifExpression.getCondition(); KtExpression condition = ifExpression.getCondition();
DataFlowInfo conditionDataFlowInfo = checkCondition(context.scope, condition, context); DataFlowInfo conditionDataFlowInfo = checkCondition(condition, context);
boolean loopBreakContinuePossibleInCondition = condition != null && containsJumpOutOfLoop(condition, context); boolean loopBreakContinuePossibleInCondition = condition != null && containsJumpOutOfLoop(condition, context);
KtExpression elseBranch = ifExpression.getElse(); KtExpression elseBranch = ifExpression.getElse();
@@ -236,7 +236,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
KtExpression condition = expression.getCondition(); KtExpression condition = expression.getCondition();
// Extract data flow info from condition itself without taking value into account // Extract data flow info from condition itself without taking value into account
DataFlowInfo dataFlowInfo = checkCondition(context.scope, condition, context); DataFlowInfo dataFlowInfo = checkCondition(condition, context);
KtExpression body = expression.getBody(); KtExpression body = expression.getBody();
KotlinTypeInfo bodyTypeInfo; KotlinTypeInfo bodyTypeInfo;
@@ -334,7 +334,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
KotlinTypeInfo bodyTypeInfo; KotlinTypeInfo bodyTypeInfo;
if (body instanceof KtLambdaExpression) { if (body instanceof KtLambdaExpression) {
// As a matter of fact, function literal is always unused at this point // As a matter of fact, function literal is always unused at this point
bodyTypeInfo = facade.getTypeInfo(body, context.replaceScope(context.scope)); bodyTypeInfo = facade.getTypeInfo(body, context);
} }
else if (body != null) { else if (body != null) {
LexicalWritableScope writableScope = newWritableScopeImpl(context, LexicalScopeKind.DO_WHILE_BODY, components.overloadChecker); LexicalWritableScope writableScope = newWritableScopeImpl(context, LexicalScopeKind.DO_WHILE_BODY, components.overloadChecker);
@@ -353,7 +353,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
bodyTypeInfo = TypeInfoFactoryKt.noTypeInfo(context); bodyTypeInfo = TypeInfoFactoryKt.noTypeInfo(context);
} }
KtExpression condition = expression.getCondition(); KtExpression condition = expression.getCondition();
DataFlowInfo conditionDataFlowInfo = checkCondition(conditionScope, condition, context); DataFlowInfo conditionDataFlowInfo = checkCondition(condition, context.replaceScope(conditionScope));
DataFlowInfo dataFlowInfo; DataFlowInfo dataFlowInfo;
// Without jumps out, condition is entered and false, with jumps out, we know nothing about it // Without jumps out, condition is entered and false, with jumps out, we know nothing about it
if (!containsJumpOutOfLoop(expression, context)) { if (!containsJumpOutOfLoop(expression, context)) {
@@ -397,7 +397,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
KotlinType expectedParameterType = null; KotlinType expectedParameterType = null;
KotlinTypeInfo loopRangeInfo; KotlinTypeInfo loopRangeInfo;
if (loopRange != null) { if (loopRange != null) {
ExpressionReceiver loopRangeReceiver = getExpressionReceiver(facade, loopRange, context.replaceScope(context.scope)); ExpressionReceiver loopRangeReceiver = getExpressionReceiver(facade, loopRange, context);
loopRangeInfo = facade.getTypeInfo(loopRange, context); loopRangeInfo = facade.getTypeInfo(loopRange, context);
if (loopRangeReceiver != null) { if (loopRangeReceiver != null) {
expectedParameterType = components.forLoopConventionsChecker.checkIterableConvention(loopRangeReceiver, context); expectedParameterType = components.forLoopConventionsChecker.checkIterableConvention(loopRangeReceiver, context);
@@ -573,8 +573,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
KtExpression thrownExpression = expression.getThrownExpression(); KtExpression thrownExpression = expression.getThrownExpression();
if (thrownExpression != null) { if (thrownExpression != null) {
KotlinType throwableType = components.builtIns.getThrowable().getDefaultType(); KotlinType throwableType = components.builtIns.getThrowable().getDefaultType();
facade.getTypeInfo(thrownExpression, context facade.getTypeInfo(thrownExpression, context.replaceExpectedType(throwableType).replaceContextDependency(INDEPENDENT));
.replaceExpectedType(throwableType).replaceScope(context.scope).replaceContextDependency(INDEPENDENT));
} }
return components.dataFlowAnalyzer.createCheckedTypeInfo(components.builtIns.getNothingType(), context, expression); return components.dataFlowAnalyzer.createCheckedTypeInfo(components.builtIns.getNothingType(), context, expression);
} }
@@ -636,8 +635,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
} }
if (returnedExpression != null) { if (returnedExpression != null) {
facade.getTypeInfo(returnedExpression, context.replaceExpectedType(expectedType).replaceScope(context.scope) facade.getTypeInfo(returnedExpression, context.replaceExpectedType(expectedType).replaceContextDependency(INDEPENDENT));
.replaceContextDependency(INDEPENDENT));
} }
else { else {
// for lambda with implicit return type Unit // for lambda with implicit return type Unit
@@ -47,7 +47,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
override fun visitIsExpression(expression: KtIsExpression, contextWithExpectedType: ExpressionTypingContext): KotlinTypeInfo { override fun visitIsExpression(expression: KtIsExpression, contextWithExpectedType: ExpressionTypingContext): KotlinTypeInfo {
val context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT) val context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT)
val leftHandSide = expression.leftHandSide val leftHandSide = expression.leftHandSide
val typeInfo = facade.safeGetTypeInfo(leftHandSide, context.replaceScope(context.scope)) val typeInfo = facade.safeGetTypeInfo(leftHandSide, context)
val knownType = typeInfo.type val knownType = typeInfo.type
val typeReference = expression.typeReference val typeReference = expression.typeReference
if (typeReference != null && knownType != null) { if (typeReference != null && knownType != null) {