Used partial resolve filter to find the last statement in a block
This commit is contained in:
@@ -31,6 +31,10 @@ import org.jetbrains.kotlin.psi.*;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
|
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.checkers.CompositeChecker;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.context.SimpleResolutionContext;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
||||||
@@ -346,7 +350,11 @@ public class AnnotationResolver {
|
|||||||
CompileTimeConstant<?> constant = ConstantExpressionEvaluator.OBJECT$.evaluate(argumentExpression, trace, expectedType);
|
CompileTimeConstant<?> constant = ConstantExpressionEvaluator.OBJECT$.evaluate(argumentExpression, trace, expectedType);
|
||||||
if (constant instanceof IntegerValueTypeConstant) {
|
if (constant instanceof IntegerValueTypeConstant) {
|
||||||
JetType defaultType = ((IntegerValueTypeConstant) constant).getType(expectedType);
|
JetType defaultType = ((IntegerValueTypeConstant) constant).getType(expectedType);
|
||||||
ArgumentTypeResolver.updateNumberType(defaultType, argumentExpression, trace);
|
SimpleResolutionContext context =
|
||||||
|
new SimpleResolutionContext(trace, JetScope.Empty.INSTANCE$, NO_EXPECTED_TYPE, DataFlowInfo.EMPTY,
|
||||||
|
ContextDependency.INDEPENDENT,
|
||||||
|
new CompositeChecker(Lists.<CallChecker>newArrayList()), PartialBodyResolveProvider.NONE);
|
||||||
|
ArgumentTypeResolver.updateNumberType(defaultType, argumentExpression, context);
|
||||||
}
|
}
|
||||||
if (constant != null) {
|
if (constant != null) {
|
||||||
constants.add(constant);
|
constants.add(constant);
|
||||||
|
|||||||
@@ -17,8 +17,11 @@
|
|||||||
package org.jetbrains.kotlin.resolve
|
package org.jetbrains.kotlin.resolve
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.JetElement
|
import org.jetbrains.kotlin.psi.JetElement
|
||||||
|
import org.jetbrains.kotlin.psi.JetBlockExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
|
||||||
public open class PartialBodyResolveProvider {
|
public open class PartialBodyResolveProvider {
|
||||||
|
|
||||||
public open val filter: ((JetElement) -> Boolean)?
|
public open val filter: ((JetElement) -> Boolean)?
|
||||||
get() = null
|
get() = null
|
||||||
|
|
||||||
@@ -26,3 +29,10 @@ public open class PartialBodyResolveProvider {
|
|||||||
public val NONE: PartialBodyResolveProvider = PartialBodyResolveProvider()
|
public val NONE: PartialBodyResolveProvider = PartialBodyResolveProvider()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun PartialBodyResolveProvider.filterStatements(block: JetBlockExpression): List<JetElement> {
|
||||||
|
if (filter == null || block is JetPsiUtil.JetExpressionWrapper) return block.getStatements()
|
||||||
|
return block.getStatements().filter { filter!!(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PartialBodyResolveProvider.getLastStatementInABlock(block: JetBlockExpression) = filterStatements(block).lastOrNull()
|
||||||
+30
-21
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
@@ -119,7 +118,7 @@ public class ArgumentTypeResolver {
|
|||||||
|
|
||||||
for (ValueArgument valueArgument : context.call.getValueArguments()) {
|
for (ValueArgument valueArgument : context.call.getValueArguments()) {
|
||||||
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
||||||
if (argumentExpression != null && isFunctionLiteralArgument(argumentExpression)) {
|
if (argumentExpression != null && isFunctionLiteralArgument(argumentExpression, context)) {
|
||||||
checkArgumentTypeWithNoCallee(context, argumentExpression);
|
checkArgumentTypeWithNoCallee(context, argumentExpression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,20 +129,26 @@ public class ArgumentTypeResolver {
|
|||||||
updateResultArgumentTypeIfNotDenotable(context, argumentExpression);
|
updateResultArgumentTypeIfNotDenotable(context, argumentExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFunctionLiteralArgument(@NotNull JetExpression expression) {
|
public static boolean isFunctionLiteralArgument(
|
||||||
return getFunctionLiteralArgumentIfAny(expression) != null;
|
@NotNull JetExpression expression, @NotNull ResolutionContext context
|
||||||
|
) {
|
||||||
|
return getFunctionLiteralArgumentIfAny(expression, context) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetFunctionLiteralExpression getFunctionLiteralArgument(@NotNull JetExpression expression) {
|
public static JetFunctionLiteralExpression getFunctionLiteralArgument(
|
||||||
assert isFunctionLiteralArgument(expression);
|
@NotNull JetExpression expression, @NotNull ResolutionContext context
|
||||||
|
) {
|
||||||
|
assert isFunctionLiteralArgument(expression, context);
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return getFunctionLiteralArgumentIfAny(expression);
|
return getFunctionLiteralArgumentIfAny(expression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetFunctionLiteralExpression getFunctionLiteralArgumentIfAny(@NotNull JetExpression expression) {
|
private static JetFunctionLiteralExpression getFunctionLiteralArgumentIfAny(
|
||||||
JetExpression deparenthesizedExpression = deparenthesizeArgument(expression);
|
@NotNull JetExpression expression, @NotNull ResolutionContext context
|
||||||
|
) {
|
||||||
|
JetExpression deparenthesizedExpression = deparenthesizeArgument(expression, context);
|
||||||
if (deparenthesizedExpression instanceof JetFunctionLiteralExpression) {
|
if (deparenthesizedExpression instanceof JetFunctionLiteralExpression) {
|
||||||
return (JetFunctionLiteralExpression) deparenthesizedExpression;
|
return (JetFunctionLiteralExpression) deparenthesizedExpression;
|
||||||
}
|
}
|
||||||
@@ -151,16 +156,20 @@ public class ArgumentTypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetExpression deparenthesizeArgument(@Nullable JetExpression expression) {
|
public static JetExpression deparenthesizeArgument(
|
||||||
|
@Nullable JetExpression expression,
|
||||||
|
@NotNull ResolutionContext context
|
||||||
|
) {
|
||||||
JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesize(expression, false);
|
JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesize(expression, false);
|
||||||
if (deparenthesizedExpression instanceof JetBlockExpression) {
|
if (deparenthesizedExpression instanceof JetBlockExpression) {
|
||||||
|
JetBlockExpression blockExpression = (JetBlockExpression) deparenthesizedExpression;
|
||||||
// todo
|
// todo
|
||||||
// This case is a temporary hack for 'if' branches.
|
// This case is a temporary hack for 'if' branches.
|
||||||
// The right way to implement this logic is to interpret 'if' branches as function literals with explicitly-typed signatures
|
// The right way to implement this logic is to interpret 'if' branches as function literals with explicitly-typed signatures
|
||||||
// (no arguments and no receiver) and therefore analyze them straight away (not in the 'complete' phase).
|
// (no arguments and no receiver) and therefore analyze them straight away (not in the 'complete' phase).
|
||||||
JetElement lastStatementInABlock = JetPsiUtil.getLastStatementInABlock((JetBlockExpression) deparenthesizedExpression);
|
JetElement lastStatementInABlock = ResolvePackage.getLastStatementInABlock(context.partialBodyResolveProvider, blockExpression);
|
||||||
if (lastStatementInABlock instanceof JetExpression) {
|
if (lastStatementInABlock instanceof JetExpression) {
|
||||||
return deparenthesizeArgument((JetExpression) lastStatementInABlock);
|
return deparenthesizeArgument((JetExpression) lastStatementInABlock, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deparenthesizedExpression;
|
return deparenthesizedExpression;
|
||||||
@@ -175,8 +184,8 @@ public class ArgumentTypeResolver {
|
|||||||
if (expression == null) {
|
if (expression == null) {
|
||||||
return JetTypeInfo.create(null, context.dataFlowInfo);
|
return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
if (isFunctionLiteralArgument(expression)) {
|
if (isFunctionLiteralArgument(expression, context)) {
|
||||||
return getFunctionLiteralTypeInfo(expression, getFunctionLiteralArgument(expression), context, resolveArgumentsMode);
|
return getFunctionLiteralTypeInfo(expression, getFunctionLiteralArgument(expression, context), context, resolveArgumentsMode);
|
||||||
}
|
}
|
||||||
JetTypeInfo recordedTypeInfo = getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
JetTypeInfo recordedTypeInfo = getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||||
if (recordedTypeInfo != null) {
|
if (recordedTypeInfo != null) {
|
||||||
@@ -240,7 +249,7 @@ public class ArgumentTypeResolver {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <D extends CallableDescriptor> void analyzeArgumentsAndRecordTypes(
|
public void analyzeArgumentsAndRecordTypes(
|
||||||
@NotNull CallResolutionContext<?> context
|
@NotNull CallResolutionContext<?> context
|
||||||
) {
|
) {
|
||||||
MutableDataFlowInfoForArguments infoForArguments = context.dataFlowInfoForArguments;
|
MutableDataFlowInfoForArguments infoForArguments = context.dataFlowInfoForArguments;
|
||||||
@@ -266,7 +275,7 @@ public class ArgumentTypeResolver {
|
|||||||
if (type.getConstructor() instanceof IntegerValueTypeConstructor) {
|
if (type.getConstructor() instanceof IntegerValueTypeConstructor) {
|
||||||
IntegerValueTypeConstructor constructor = (IntegerValueTypeConstructor) type.getConstructor();
|
IntegerValueTypeConstructor constructor = (IntegerValueTypeConstructor) type.getConstructor();
|
||||||
JetType primitiveType = TypeUtils.getPrimitiveNumberType(constructor, context.expectedType);
|
JetType primitiveType = TypeUtils.getPrimitiveNumberType(constructor, context.expectedType);
|
||||||
updateNumberType(primitiveType, expression, context.trace);
|
updateNumberType(primitiveType, expression, context);
|
||||||
return primitiveType;
|
return primitiveType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,19 +285,19 @@ public class ArgumentTypeResolver {
|
|||||||
public static void updateNumberType(
|
public static void updateNumberType(
|
||||||
@NotNull JetType numberType,
|
@NotNull JetType numberType,
|
||||||
@Nullable JetExpression expression,
|
@Nullable JetExpression expression,
|
||||||
@NotNull BindingTrace trace
|
@NotNull ResolutionContext context
|
||||||
) {
|
) {
|
||||||
if (expression == null) return;
|
if (expression == null) return;
|
||||||
BindingContextUtils.updateRecordedType(numberType, expression, trace, false);
|
BindingContextUtils.updateRecordedType(numberType, expression, context.trace, false);
|
||||||
|
|
||||||
if (!(expression instanceof JetConstantExpression)) {
|
if (!(expression instanceof JetConstantExpression)) {
|
||||||
JetExpression deparenthesized = deparenthesizeArgument(expression);
|
JetExpression deparenthesized = deparenthesizeArgument(expression, context);
|
||||||
if (deparenthesized != expression) {
|
if (deparenthesized != expression) {
|
||||||
updateNumberType(numberType, deparenthesized, trace);
|
updateNumberType(numberType, deparenthesized, context);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantExpressionEvaluator.OBJECT$.evaluate(expression, trace, numberType);
|
ConstantExpressionEvaluator.OBJECT$.evaluate(expression, context.trace, numberType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ public class CallCompleter(
|
|||||||
if (valueArgument.isExternal()) return
|
if (valueArgument.isExternal()) return
|
||||||
|
|
||||||
val expression = valueArgument.getArgumentExpression()
|
val expression = valueArgument.getArgumentExpression()
|
||||||
val deparenthesized = ArgumentTypeResolver.deparenthesizeArgument(expression)
|
val deparenthesized = ArgumentTypeResolver.deparenthesizeArgument(expression, context as ResolutionContext<*>)
|
||||||
if (deparenthesized == null) return
|
if (deparenthesized == null) return
|
||||||
|
|
||||||
val recordedType = context.trace[BindingContext.EXPRESSION_TYPE, expression]
|
val recordedType = context.trace[BindingContext.EXPRESSION_TYPE, expression]
|
||||||
@@ -248,9 +248,9 @@ public class CallCompleter(
|
|||||||
|
|
||||||
// While the expected type is not known, the function literal arguments are not analyzed (to analyze function literal bodies once),
|
// While the expected type is not known, the function literal arguments are not analyzed (to analyze function literal bodies once),
|
||||||
// but they should be analyzed when the expected type is known (during the call completion).
|
// but they should be analyzed when the expected type is known (during the call completion).
|
||||||
if (ArgumentTypeResolver.isFunctionLiteralArgument(expression)) {
|
if (ArgumentTypeResolver.isFunctionLiteralArgument(expression, context as ResolutionContext<*>)) {
|
||||||
argumentTypeResolver.getFunctionLiteralTypeInfo(
|
argumentTypeResolver.getFunctionLiteralTypeInfo(
|
||||||
expression, ArgumentTypeResolver.getFunctionLiteralArgument(expression),
|
expression, ArgumentTypeResolver.getFunctionLiteralArgument(expression, context as ResolutionContext<*>),
|
||||||
context as CallResolutionContext<*>, RESOLVE_FUNCTION_ARGUMENTS)
|
context as CallResolutionContext<*>, RESOLVE_FUNCTION_ARGUMENTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -279,9 +279,9 @@ public class CandidateResolver {
|
|||||||
) {
|
) {
|
||||||
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
||||||
if (argumentExpression == null) return;
|
if (argumentExpression == null) return;
|
||||||
if (!ArgumentTypeResolver.isFunctionLiteralArgument(argumentExpression)) return;
|
if (!ArgumentTypeResolver.isFunctionLiteralArgument(argumentExpression, context)) return;
|
||||||
|
|
||||||
JetFunctionLiteralExpression functionLiteralExpression = ArgumentTypeResolver.getFunctionLiteralArgument(argumentExpression);
|
JetFunctionLiteralExpression functionLiteralExpression = ArgumentTypeResolver.getFunctionLiteralArgument(argumentExpression, context);
|
||||||
|
|
||||||
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);
|
||||||
@@ -379,8 +379,8 @@ public class CandidateResolver {
|
|||||||
? TypeUtils.makeNotNullable(receiverArgument.getType())
|
? TypeUtils.makeNotNullable(receiverArgument.getType())
|
||||||
: receiverArgument.getType();
|
: receiverArgument.getType();
|
||||||
if (receiverArgument instanceof ExpressionReceiver) {
|
if (receiverArgument instanceof ExpressionReceiver) {
|
||||||
receiverType = updateResultTypeForSmartCasts(receiverType, ((ExpressionReceiver) receiverArgument).getExpression(),
|
receiverType = updateResultTypeForSmartCasts(
|
||||||
context.dataFlowInfo, context.trace);
|
receiverType, ((ExpressionReceiver) receiverArgument).getExpression(), context);
|
||||||
}
|
}
|
||||||
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), RECEIVER_POSITION.position());
|
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), RECEIVER_POSITION.position());
|
||||||
}
|
}
|
||||||
@@ -424,7 +424,8 @@ public class CandidateResolver {
|
|||||||
argumentExpression, newContext, resolveFunctionArgumentBodies);
|
argumentExpression, newContext, resolveFunctionArgumentBodies);
|
||||||
context.candidateCall.getDataFlowInfoForArguments().updateInfo(valueArgument, typeInfoForCall.getDataFlowInfo());
|
context.candidateCall.getDataFlowInfoForArguments().updateInfo(valueArgument, typeInfoForCall.getDataFlowInfo());
|
||||||
|
|
||||||
JetType type = updateResultTypeForSmartCasts(typeInfoForCall.getType(), argumentExpression, dataFlowInfoForArgument, context.trace);
|
JetType type = updateResultTypeForSmartCasts(
|
||||||
|
typeInfoForCall.getType(), argumentExpression, context.replaceDataFlowInfo(dataFlowInfoForArgument));
|
||||||
constraintSystem.addSubtypeConstraint(
|
constraintSystem.addSubtypeConstraint(
|
||||||
type, effectiveExpectedType, VALUE_PARAMETER_POSITION.position(valueParameterDescriptor.getIndex()));
|
type, effectiveExpectedType, VALUE_PARAMETER_POSITION.position(valueParameterDescriptor.getIndex()));
|
||||||
}
|
}
|
||||||
@@ -433,16 +434,15 @@ public class CandidateResolver {
|
|||||||
private static JetType updateResultTypeForSmartCasts(
|
private static JetType updateResultTypeForSmartCasts(
|
||||||
@Nullable JetType type,
|
@Nullable JetType type,
|
||||||
@Nullable JetExpression argumentExpression,
|
@Nullable JetExpression argumentExpression,
|
||||||
@NotNull DataFlowInfo dataFlowInfoForArgument,
|
@NotNull ResolutionContext context
|
||||||
@NotNull BindingTrace trace
|
|
||||||
) {
|
) {
|
||||||
JetExpression deparenthesizedArgument = deparenthesizeArgument(argumentExpression);
|
JetExpression deparenthesizedArgument = deparenthesizeArgument(argumentExpression, context);
|
||||||
if (deparenthesizedArgument == null || type == null) return type;
|
if (deparenthesizedArgument == null || type == null) return type;
|
||||||
|
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(deparenthesizedArgument, type, trace.getBindingContext());
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(deparenthesizedArgument, type, context.trace.getBindingContext());
|
||||||
if (!dataFlowValue.isStableIdentifier()) return type;
|
if (!dataFlowValue.isStableIdentifier()) return type;
|
||||||
|
|
||||||
Set<JetType> possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue);
|
Set<JetType> possibleTypes = context.dataFlowInfo.getPossibleTypes(dataFlowValue);
|
||||||
if (possibleTypes.isEmpty()) return type;
|
if (possibleTypes.isEmpty()) return type;
|
||||||
|
|
||||||
return TypeUtils.intersect(JetTypeChecker.DEFAULT, possibleTypes);
|
return TypeUtils.intersect(JetTypeChecker.DEFAULT, possibleTypes);
|
||||||
|
|||||||
+11
-7
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.psi.Call;
|
import org.jetbrains.kotlin.psi.Call;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||||
@@ -38,11 +39,12 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
|
|||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
||||||
dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates);
|
dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -59,7 +61,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
|
|||||||
) {
|
) {
|
||||||
return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
||||||
new ResolutionResultsCacheImpl(), null,
|
new ResolutionResultsCacheImpl(), null,
|
||||||
callChecker, isAnnotationContext, false);
|
callChecker, PartialBodyResolveProvider.NONE, isAnnotationContext, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -67,9 +69,10 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
|
|||||||
@NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckValueArgumentsMode checkArguments,
|
@NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckValueArgumentsMode checkArguments,
|
||||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
|
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
|
||||||
) {
|
) {
|
||||||
return new BasicCallResolutionContext(context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
|
return new BasicCallResolutionContext(
|
||||||
context.resolutionResultsCache, dataFlowInfoForArguments, context.callChecker,
|
context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
|
||||||
context.isAnnotationContext, context.collectAllCandidates);
|
context.resolutionResultsCache, dataFlowInfoForArguments, context.callChecker, context.partialBodyResolveProvider,
|
||||||
|
context.isAnnotationContext, context.collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -87,17 +90,18 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
return new BasicCallResolutionContext(
|
return new BasicCallResolutionContext(
|
||||||
trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
||||||
dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates);
|
dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public BasicCallResolutionContext replaceCall(@NotNull Call newCall) {
|
public BasicCallResolutionContext replaceCall(@NotNull Call newCall) {
|
||||||
return new BasicCallResolutionContext(
|
return new BasicCallResolutionContext(
|
||||||
trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
||||||
dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates);
|
dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-5
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.Call;
|
import org.jetbrains.kotlin.psi.Call;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
|
||||||
@@ -51,12 +52,13 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
|||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
@NotNull ReceiverValue explicitExtensionReceiverForInvoke,
|
@NotNull ReceiverValue explicitExtensionReceiverForInvoke,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
||||||
dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates);
|
dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
this.candidateCall = candidateCall;
|
this.candidateCall = candidateCall;
|
||||||
this.tracing = tracing;
|
this.tracing = tracing;
|
||||||
this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
|
this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
|
||||||
@@ -71,7 +73,8 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
|||||||
candidateCall, tracing, trace, context.scope, call, context.expectedType,
|
candidateCall, tracing, trace, context.scope, call, context.expectedType,
|
||||||
context.dataFlowInfo, context.contextDependency, context.checkArguments,
|
context.dataFlowInfo, context.contextDependency, context.checkArguments,
|
||||||
context.resolutionResultsCache, context.dataFlowInfoForArguments,
|
context.resolutionResultsCache, context.dataFlowInfoForArguments,
|
||||||
context.callChecker, explicitExtensionReceiverForInvoke, context.isAnnotationContext, context.collectAllCandidates);
|
context.callChecker, context.partialBodyResolveProvider, explicitExtensionReceiverForInvoke,
|
||||||
|
context.isAnnotationContext, context.collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
|
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
|
||||||
@@ -94,7 +97,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
|||||||
return new CallCandidateResolutionContext<D>(
|
return new CallCandidateResolutionContext<D>(
|
||||||
candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
|
candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
|
||||||
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
|
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
|
||||||
context.dataFlowInfoForArguments, context.callChecker, ReceiverValue.NO_RECEIVER,
|
context.dataFlowInfoForArguments, context.callChecker, context.partialBodyResolveProvider, ReceiverValue.NO_RECEIVER,
|
||||||
context.isAnnotationContext, context.collectAllCandidates);
|
context.isAnnotationContext, context.collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,11 +109,12 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
return new CallCandidateResolutionContext<D>(
|
return new CallCandidateResolutionContext<D>(
|
||||||
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
||||||
resolutionResultsCache, dataFlowInfoForArguments, callChecker, explicitExtensionReceiverForInvoke,
|
resolutionResultsCache, dataFlowInfoForArguments, callChecker, partialBodyResolveProvider,
|
||||||
isAnnotationContext, collectAllCandidates);
|
explicitExtensionReceiverForInvoke, isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.psi.Call;
|
import org.jetbrains.kotlin.psi.Call;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
|
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||||
@@ -47,11 +48,12 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
|
|||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
|
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
|
||||||
isAnnotationContext, collectAllCandidates);
|
partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
this.call = call;
|
this.call = call;
|
||||||
this.checkArguments = checkArguments;
|
this.checkArguments = checkArguments;
|
||||||
if (dataFlowInfoForArguments != null) {
|
if (dataFlowInfoForArguments != null) {
|
||||||
|
|||||||
+26
-7
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.context;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
@@ -40,6 +41,8 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
|||||||
public final ResolutionResultsCache resolutionResultsCache;
|
public final ResolutionResultsCache resolutionResultsCache;
|
||||||
@NotNull
|
@NotNull
|
||||||
public final CallChecker callChecker;
|
public final CallChecker callChecker;
|
||||||
|
@NotNull
|
||||||
|
public final PartialBodyResolveProvider partialBodyResolveProvider;
|
||||||
|
|
||||||
public final boolean isAnnotationContext;
|
public final boolean isAnnotationContext;
|
||||||
|
|
||||||
@@ -53,6 +56,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
|||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
@@ -63,6 +67,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
|||||||
this.contextDependency = contextDependency;
|
this.contextDependency = contextDependency;
|
||||||
this.resolutionResultsCache = resolutionResultsCache;
|
this.resolutionResultsCache = resolutionResultsCache;
|
||||||
this.callChecker = callChecker;
|
this.callChecker = callChecker;
|
||||||
|
this.partialBodyResolveProvider = partialBodyResolveProvider;
|
||||||
this.isAnnotationContext = isAnnotationContext;
|
this.isAnnotationContext = isAnnotationContext;
|
||||||
this.collectAllCandidates = collectAllCandidates;
|
this.collectAllCandidates = collectAllCandidates;
|
||||||
}
|
}
|
||||||
@@ -74,6 +79,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -86,38 +92,44 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
|||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceBindingTrace(@NotNull BindingTrace trace) {
|
public Context replaceBindingTrace(@NotNull BindingTrace trace) {
|
||||||
if (this.trace == trace) return self();
|
if (this.trace == trace) return self();
|
||||||
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, collectAllCandidates);
|
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) {
|
public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) {
|
||||||
if (newDataFlowInfo == dataFlowInfo) return self();
|
if (newDataFlowInfo == dataFlowInfo) return self();
|
||||||
return create(trace, scope, newDataFlowInfo, expectedType, contextDependency, resolutionResultsCache, collectAllCandidates);
|
return create(trace, scope, newDataFlowInfo, expectedType, contextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceExpectedType(@Nullable JetType newExpectedType) {
|
public Context replaceExpectedType(@Nullable JetType newExpectedType) {
|
||||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||||
if (expectedType == newExpectedType) return self();
|
if (expectedType == newExpectedType) return self();
|
||||||
return create(trace, scope, dataFlowInfo, newExpectedType, contextDependency, resolutionResultsCache, collectAllCandidates);
|
return create(trace, scope, dataFlowInfo, newExpectedType, contextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceScope(@NotNull JetScope newScope) {
|
public Context replaceScope(@NotNull JetScope newScope) {
|
||||||
if (newScope == scope) return self();
|
if (newScope == scope) return self();
|
||||||
return create(trace, newScope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, collectAllCandidates);
|
return create(trace, newScope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceContextDependency(@NotNull ContextDependency newContextDependency) {
|
public Context replaceContextDependency(@NotNull ContextDependency newContextDependency) {
|
||||||
if (newContextDependency == contextDependency) return self();
|
if (newContextDependency == contextDependency) return self();
|
||||||
return create(trace, scope, dataFlowInfo, expectedType, newContextDependency, resolutionResultsCache, collectAllCandidates);
|
return create(trace, scope, dataFlowInfo, expectedType, newContextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceResolutionResultsCache(@NotNull ResolutionResultsCache newResolutionResultsCache) {
|
public Context replaceResolutionResultsCache(@NotNull ResolutionResultsCache newResolutionResultsCache) {
|
||||||
if (newResolutionResultsCache == resolutionResultsCache) return self();
|
if (newResolutionResultsCache == resolutionResultsCache) return self();
|
||||||
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, newResolutionResultsCache, collectAllCandidates);
|
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, newResolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -127,6 +139,13 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Context replaceCollectAllCandidates(boolean newCollectAllCandidates) {
|
public Context replaceCollectAllCandidates(boolean newCollectAllCandidates) {
|
||||||
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, newCollectAllCandidates);
|
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
newCollectAllCandidates);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Context replacePartialBodyResolveProvider(@NotNull PartialBodyResolveProvider partialBodyResolveProvider) {
|
||||||
|
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, partialBodyResolveProvider,
|
||||||
|
collectAllCandidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-4
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.context;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
@@ -32,10 +33,11 @@ public class SimpleResolutionContext extends ResolutionContext<SimpleResolutionC
|
|||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
|
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker, partialBodyResolveProvider,
|
||||||
isAnnotationContext, collectAllCandidates);
|
isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,10 +47,11 @@ public class SimpleResolutionContext extends ResolutionContext<SimpleResolutionC
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull DataFlowInfo dataFlowInfo,
|
@NotNull DataFlowInfo dataFlowInfo,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull CallChecker callChecker
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider
|
||||||
) {
|
) {
|
||||||
this(trace, scope, expectedType, dataFlowInfo, contextDependency, new ResolutionResultsCacheImpl(),
|
this(trace, scope, expectedType, dataFlowInfo, contextDependency, new ResolutionResultsCacheImpl(),
|
||||||
callChecker, false, false);
|
callChecker, partialBodyResolveProvider, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,10 +62,11 @@ public class SimpleResolutionContext extends ResolutionContext<SimpleResolutionC
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
return new SimpleResolutionContext(
|
return new SimpleResolutionContext(
|
||||||
trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
|
trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker, partialBodyResolveProvider,
|
||||||
isAnnotationContext, collectAllCandidates);
|
isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ public class ResolutionResultsHandler {
|
|||||||
// This check is needed for the following case:
|
// This check is needed for the following case:
|
||||||
// x.foo(unresolved) -- if there are multiple foo's, we'd report an ambiguity, and it does not make sense here
|
// x.foo(unresolved) -- if there are multiple foo's, we'd report an ambiguity, and it does not make sense here
|
||||||
if (task.checkArguments == CheckValueArgumentsMode.DISABLED ||
|
if (task.checkArguments == CheckValueArgumentsMode.DISABLED ||
|
||||||
!CallUtilPackage.hasUnresolvedArguments(task.call, task.trace.getBindingContext())) {
|
!CallUtilPackage.hasUnresolvedArguments(task.call, task)) {
|
||||||
if (allCandidatesIncomplete) {
|
if (allCandidatesIncomplete) {
|
||||||
task.tracing.cannotCompleteResolve(task.trace, results.getResultingCalls());
|
task.tracing.cannotCompleteResolve(task.trace, results.getResultingCalls());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
|||||||
import org.jetbrains.kotlin.psi.Call;
|
import org.jetbrains.kotlin.psi.Call;
|
||||||
import org.jetbrains.kotlin.psi.JetReferenceExpression;
|
import org.jetbrains.kotlin.psi.JetReferenceExpression;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.*;
|
import org.jetbrains.kotlin.resolve.calls.context.*;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||||
@@ -55,12 +56,13 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
|||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
@NotNull Collection<MutableResolvedCall<F>> resolvedCalls,
|
@NotNull Collection<MutableResolvedCall<F>> resolvedCalls,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
|
||||||
dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates);
|
dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
this.lazyCandidates = lazyCandidates;
|
this.lazyCandidates = lazyCandidates;
|
||||||
this.resolvedCalls = resolvedCalls;
|
this.resolvedCalls = resolvedCalls;
|
||||||
this.tracing = tracing;
|
this.tracing = tracing;
|
||||||
@@ -75,7 +77,8 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
|||||||
context.trace, context.scope, context.call,
|
context.trace, context.scope, context.call,
|
||||||
context.expectedType, context.dataFlowInfo, context.contextDependency, context.checkArguments,
|
context.expectedType, context.dataFlowInfo, context.contextDependency, context.checkArguments,
|
||||||
context.resolutionResultsCache, context.dataFlowInfoForArguments,
|
context.resolutionResultsCache, context.dataFlowInfoForArguments,
|
||||||
context.callChecker, Lists.<MutableResolvedCall<F>>newArrayList(), context.isAnnotationContext, context.collectAllCandidates);
|
context.callChecker, context.partialBodyResolveProvider, Lists.<MutableResolvedCall<F>>newArrayList(),
|
||||||
|
context.isAnnotationContext, context.collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolutionTask(
|
public ResolutionTask(
|
||||||
@@ -113,12 +116,13 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
return new ResolutionTask<D, F>(
|
return new ResolutionTask<D, F>(
|
||||||
lazyCandidates, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
lazyCandidates, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
||||||
resolutionResultsCache, dataFlowInfoForArguments, callChecker, resolvedCalls, isAnnotationContext,
|
resolutionResultsCache, dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, resolvedCalls,
|
||||||
collectAllCandidates);
|
isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolutionTask<D, F> replaceContext(@NotNull BasicCallResolutionContext newContext) {
|
public ResolutionTask<D, F> replaceContext(@NotNull BasicCallResolutionContext newContext) {
|
||||||
@@ -128,7 +132,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
|||||||
public ResolutionTask<D, F> replaceCall(@NotNull Call newCall) {
|
public ResolutionTask<D, F> replaceCall(@NotNull Call newCall) {
|
||||||
return new ResolutionTask<D, F>(
|
return new ResolutionTask<D, F>(
|
||||||
lazyCandidates, tracing, trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
lazyCandidates, tracing, trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments,
|
||||||
resolutionResultsCache, dataFlowInfoForArguments, callChecker, resolvedCalls,
|
resolutionResultsCache, dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, resolvedCalls,
|
||||||
isAnnotationContext, collectAllCandidates);
|
isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.BindingContext.RESOLVED_CALL
|
|||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getTextWithLocation
|
import org.jetbrains.kotlin.psi.psiUtil.getTextWithLocation
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
|
|
||||||
// resolved call
|
// resolved call
|
||||||
|
|
||||||
@@ -63,12 +64,12 @@ public fun <D : CallableDescriptor> ResolvedCall<D>.getParameterForArgument(valu
|
|||||||
|
|
||||||
// call
|
// call
|
||||||
|
|
||||||
public fun Call.hasUnresolvedArguments(context: BindingContext): Boolean {
|
public fun <C: ResolutionContext<C>> Call.hasUnresolvedArguments(context: ResolutionContext<C>): Boolean {
|
||||||
val arguments = getValueArguments().map { it?.getArgumentExpression() }
|
val arguments = getValueArguments().map { it?.getArgumentExpression() }
|
||||||
return arguments.any {
|
return arguments.any {
|
||||||
argument ->
|
argument ->
|
||||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, argument]
|
val expressionType = context.trace.getBindingContext()[BindingContext.EXPRESSION_TYPE, argument]
|
||||||
argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument)
|
argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument, context as ResolutionContext<*>)
|
||||||
&& (expressionType == null || expressionType.isError())
|
&& (expressionType == null || expressionType.isError())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -763,7 +763,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType expressionType = value.getType(KotlinBuiltIns.getInstance());
|
JetType expressionType = value.getType(KotlinBuiltIns.getInstance());
|
||||||
if (value instanceof IntegerValueTypeConstant && context.contextDependency == INDEPENDENT) {
|
if (value instanceof IntegerValueTypeConstant && context.contextDependency == INDEPENDENT) {
|
||||||
expressionType = ((IntegerValueTypeConstant) value).getType(context.expectedType);
|
expressionType = ((IntegerValueTypeConstant) value).getType(context.expectedType);
|
||||||
ArgumentTypeResolver.updateNumberType(expressionType, expression, context.trace);
|
ArgumentTypeResolver.updateNumberType(expressionType, expression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DataFlowUtils.checkType(expressionType, expression, context, context.dataFlowInfo);
|
return DataFlowUtils.checkType(expressionType, expression, context, context.dataFlowInfo);
|
||||||
|
|||||||
+11
-7
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.types.expressions;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.PartialBodyResolveProvider;
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
|
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCache;
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCache;
|
||||||
@@ -40,15 +41,15 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
|||||||
) {
|
) {
|
||||||
return newContext(trace, scope, dataFlowInfo, expectedType,
|
return newContext(trace, scope, dataFlowInfo, expectedType,
|
||||||
ContextDependency.INDEPENDENT, new ResolutionResultsCacheImpl(),
|
ContextDependency.INDEPENDENT, new ResolutionResultsCacheImpl(),
|
||||||
expressionTypingServices.getCallChecker(), false);
|
expressionTypingServices.getCallChecker(), PartialBodyResolveProvider.NONE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ExpressionTypingContext newContext(@NotNull ResolutionContext context) {
|
public static ExpressionTypingContext newContext(@NotNull ResolutionContext context) {
|
||||||
return new ExpressionTypingContext(
|
return new ExpressionTypingContext(
|
||||||
context.trace, context.scope, context.dataFlowInfo, context.expectedType,
|
context.trace, context.scope, context.dataFlowInfo, context.expectedType,
|
||||||
context.contextDependency, context.resolutionResultsCache, context.callChecker, context.isAnnotationContext,
|
context.contextDependency, context.resolutionResultsCache, context.callChecker, context.partialBodyResolveProvider,
|
||||||
context.collectAllCandidates
|
context.isAnnotationContext, context.collectAllCandidates
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,11 +62,12 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
|||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean isAnnotationContext
|
boolean isAnnotationContext
|
||||||
) {
|
) {
|
||||||
return new ExpressionTypingContext(
|
return new ExpressionTypingContext(
|
||||||
trace, scope, dataFlowInfo, expectedType, contextDependency,
|
trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, callChecker,
|
||||||
resolutionResultsCache, callChecker, isAnnotationContext, false);
|
partialBodyResolveProvider, isAnnotationContext, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompileTimeConstantChecker compileTimeConstantChecker;
|
private CompileTimeConstantChecker compileTimeConstantChecker;
|
||||||
@@ -78,11 +80,12 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
|||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
@NotNull CallChecker callChecker,
|
@NotNull CallChecker callChecker,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean isAnnotationContext,
|
boolean isAnnotationContext,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
|
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
|
||||||
isAnnotationContext, collectAllCandidates);
|
partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,11 +96,12 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull ContextDependency contextDependency,
|
@NotNull ContextDependency contextDependency,
|
||||||
@NotNull ResolutionResultsCache resolutionResultsCache,
|
@NotNull ResolutionResultsCache resolutionResultsCache,
|
||||||
|
@NotNull PartialBodyResolveProvider partialBodyResolveProvider,
|
||||||
boolean collectAllCandidates
|
boolean collectAllCandidates
|
||||||
) {
|
) {
|
||||||
return new ExpressionTypingContext(trace, scope, dataFlowInfo,
|
return new ExpressionTypingContext(trace, scope, dataFlowInfo,
|
||||||
expectedType, contextDependency, resolutionResultsCache, callChecker,
|
expectedType, contextDependency, resolutionResultsCache, callChecker,
|
||||||
isAnnotationContext, collectAllCandidates);
|
partialBodyResolveProvider, isAnnotationContext, collectAllCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////// LAZY ACCESSORS
|
///////////// LAZY ACCESSORS
|
||||||
|
|||||||
+3
-9
@@ -19,8 +19,6 @@ package org.jetbrains.kotlin.types.expressions;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import kotlin.Function1;
|
|
||||||
import kotlin.KotlinPackage;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
||||||
@@ -210,12 +208,7 @@ public class ExpressionTypingServices {
|
|||||||
@NotNull CoercionStrategy coercionStrategyForLastExpression,
|
@NotNull CoercionStrategy coercionStrategyForLastExpression,
|
||||||
@NotNull ExpressionTypingContext context
|
@NotNull ExpressionTypingContext context
|
||||||
) {
|
) {
|
||||||
List<JetElement> block = expression.getStatements();
|
List<JetElement> block = ResolvePackage.filterStatements(getPartialBodyResolveProvider(), expression);
|
||||||
|
|
||||||
Function1<JetElement, Boolean> filter = getPartialBodyResolveProvider().getFilter();
|
|
||||||
if (filter != null && !(expression instanceof JetPsiUtil.JetExpressionWrapper)) {
|
|
||||||
block = KotlinPackage.filter(block, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SCRIPT: get code descriptor for script declaration
|
// SCRIPT: get code descriptor for script declaration
|
||||||
DeclarationDescriptor containingDescriptor = context.scope.getContainingDeclaration();
|
DeclarationDescriptor containingDescriptor = context.scope.getContainingDeclaration();
|
||||||
@@ -235,7 +228,8 @@ public class ExpressionTypingServices {
|
|||||||
r = DataFlowUtils.checkType(builtIns.getUnitType(), expression, context, context.dataFlowInfo);
|
r = DataFlowUtils.checkType(builtIns.getUnitType(), expression, context, context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
|
r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression,
|
||||||
|
context.replacePartialBodyResolveProvider(getPartialBodyResolveProvider()));
|
||||||
}
|
}
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user