diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java index cd46f45e6be..cdd65a8b111 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java @@ -31,6 +31,10 @@ import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver; import org.jetbrains.kotlin.resolve.calls.CallResolver; 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.ResolvedValueArgument; import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; @@ -346,7 +350,11 @@ public class AnnotationResolver { CompileTimeConstant constant = ConstantExpressionEvaluator.OBJECT$.evaluate(argumentExpression, trace, expectedType); if (constant instanceof IntegerValueTypeConstant) { 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.newArrayList()), PartialBodyResolveProvider.NONE); + ArgumentTypeResolver.updateNumberType(defaultType, argumentExpression, context); } if (constant != null) { constants.add(constant); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PartialBodyResolveProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PartialBodyResolveProvider.kt index e3161fb8dd5..8dac01c5402 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PartialBodyResolveProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PartialBodyResolveProvider.kt @@ -17,8 +17,11 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.psi.JetElement +import org.jetbrains.kotlin.psi.JetBlockExpression +import org.jetbrains.kotlin.psi.JetPsiUtil public open class PartialBodyResolveProvider { + public open val filter: ((JetElement) -> Boolean)? get() = null @@ -26,3 +29,10 @@ public open class PartialBodyResolveProvider { public val NONE: PartialBodyResolveProvider = PartialBodyResolveProvider() } } + +fun PartialBodyResolveProvider.filterStatements(block: JetBlockExpression): List { + if (filter == null || block is JetPsiUtil.JetExpressionWrapper) return block.getStatements() + return block.getStatements().filter { filter!!(it) } +} + +fun PartialBodyResolveProvider.getLastStatementInABlock(block: JetBlockExpression) = filterStatements(block).lastOrNull() \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java index 09318f9176f..568ba6217a2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java @@ -20,7 +20,6 @@ import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; -import org.jetbrains.kotlin.descriptors.CallableDescriptor; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.diagnostics.Errors; import org.jetbrains.kotlin.psi.*; @@ -119,7 +118,7 @@ public class ArgumentTypeResolver { for (ValueArgument valueArgument : context.call.getValueArguments()) { JetExpression argumentExpression = valueArgument.getArgumentExpression(); - if (argumentExpression != null && isFunctionLiteralArgument(argumentExpression)) { + if (argumentExpression != null && isFunctionLiteralArgument(argumentExpression, context)) { checkArgumentTypeWithNoCallee(context, argumentExpression); } } @@ -130,20 +129,26 @@ public class ArgumentTypeResolver { updateResultArgumentTypeIfNotDenotable(context, argumentExpression); } - public static boolean isFunctionLiteralArgument(@NotNull JetExpression expression) { - return getFunctionLiteralArgumentIfAny(expression) != null; + public static boolean isFunctionLiteralArgument( + @NotNull JetExpression expression, @NotNull ResolutionContext context + ) { + return getFunctionLiteralArgumentIfAny(expression, context) != null; } @NotNull - public static JetFunctionLiteralExpression getFunctionLiteralArgument(@NotNull JetExpression expression) { - assert isFunctionLiteralArgument(expression); + public static JetFunctionLiteralExpression getFunctionLiteralArgument( + @NotNull JetExpression expression, @NotNull ResolutionContext context + ) { + assert isFunctionLiteralArgument(expression, context); //noinspection ConstantConditions - return getFunctionLiteralArgumentIfAny(expression); + return getFunctionLiteralArgumentIfAny(expression, context); } @Nullable - private static JetFunctionLiteralExpression getFunctionLiteralArgumentIfAny(@NotNull JetExpression expression) { - JetExpression deparenthesizedExpression = deparenthesizeArgument(expression); + private static JetFunctionLiteralExpression getFunctionLiteralArgumentIfAny( + @NotNull JetExpression expression, @NotNull ResolutionContext context + ) { + JetExpression deparenthesizedExpression = deparenthesizeArgument(expression, context); if (deparenthesizedExpression instanceof JetFunctionLiteralExpression) { return (JetFunctionLiteralExpression) deparenthesizedExpression; } @@ -151,16 +156,20 @@ public class ArgumentTypeResolver { } @Nullable - public static JetExpression deparenthesizeArgument(@Nullable JetExpression expression) { + public static JetExpression deparenthesizeArgument( + @Nullable JetExpression expression, + @NotNull ResolutionContext context + ) { JetExpression deparenthesizedExpression = JetPsiUtil.deparenthesize(expression, false); if (deparenthesizedExpression instanceof JetBlockExpression) { + JetBlockExpression blockExpression = (JetBlockExpression) deparenthesizedExpression; // todo // 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 // (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) { - return deparenthesizeArgument((JetExpression) lastStatementInABlock); + return deparenthesizeArgument((JetExpression) lastStatementInABlock, context); } } return deparenthesizedExpression; @@ -175,8 +184,8 @@ public class ArgumentTypeResolver { if (expression == null) { return JetTypeInfo.create(null, context.dataFlowInfo); } - if (isFunctionLiteralArgument(expression)) { - return getFunctionLiteralTypeInfo(expression, getFunctionLiteralArgument(expression), context, resolveArgumentsMode); + if (isFunctionLiteralArgument(expression, context)) { + return getFunctionLiteralTypeInfo(expression, getFunctionLiteralArgument(expression, context), context, resolveArgumentsMode); } JetTypeInfo recordedTypeInfo = getRecordedTypeInfo(expression, context.trace.getBindingContext()); if (recordedTypeInfo != null) { @@ -240,7 +249,7 @@ public class ArgumentTypeResolver { return defaultValue; } - public void analyzeArgumentsAndRecordTypes( + public void analyzeArgumentsAndRecordTypes( @NotNull CallResolutionContext context ) { MutableDataFlowInfoForArguments infoForArguments = context.dataFlowInfoForArguments; @@ -266,7 +275,7 @@ public class ArgumentTypeResolver { if (type.getConstructor() instanceof IntegerValueTypeConstructor) { IntegerValueTypeConstructor constructor = (IntegerValueTypeConstructor) type.getConstructor(); JetType primitiveType = TypeUtils.getPrimitiveNumberType(constructor, context.expectedType); - updateNumberType(primitiveType, expression, context.trace); + updateNumberType(primitiveType, expression, context); return primitiveType; } } @@ -276,19 +285,19 @@ public class ArgumentTypeResolver { public static void updateNumberType( @NotNull JetType numberType, @Nullable JetExpression expression, - @NotNull BindingTrace trace + @NotNull ResolutionContext context ) { if (expression == null) return; - BindingContextUtils.updateRecordedType(numberType, expression, trace, false); + BindingContextUtils.updateRecordedType(numberType, expression, context.trace, false); if (!(expression instanceof JetConstantExpression)) { - JetExpression deparenthesized = deparenthesizeArgument(expression); + JetExpression deparenthesized = deparenthesizeArgument(expression, context); if (deparenthesized != expression) { - updateNumberType(numberType, deparenthesized, trace); + updateNumberType(numberType, deparenthesized, context); } return; } - ConstantExpressionEvaluator.OBJECT$.evaluate(expression, trace, numberType); + ConstantExpressionEvaluator.OBJECT$.evaluate(expression, context.trace, numberType); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index a5858596d96..e6e74116fe1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -226,7 +226,7 @@ public class CallCompleter( if (valueArgument.isExternal()) return val expression = valueArgument.getArgumentExpression() - val deparenthesized = ArgumentTypeResolver.deparenthesizeArgument(expression) + val deparenthesized = ArgumentTypeResolver.deparenthesizeArgument(expression, context as ResolutionContext<*>) if (deparenthesized == null) return 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), // 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( - expression, ArgumentTypeResolver.getFunctionLiteralArgument(expression), + expression, ArgumentTypeResolver.getFunctionLiteralArgument(expression, context as ResolutionContext<*>), context as CallResolutionContext<*>, RESOLVE_FUNCTION_ARGUMENTS) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.java index f61d0f72606..83654be44ac 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.java @@ -279,9 +279,9 @@ public class CandidateResolver { ) { JetExpression argumentExpression = valueArgument.getArgumentExpression(); 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 expectedType = constraintSystem.getCurrentSubstitutor().substitute(effectiveExpectedType, Variance.INVARIANT); @@ -379,8 +379,8 @@ public class CandidateResolver { ? TypeUtils.makeNotNullable(receiverArgument.getType()) : receiverArgument.getType(); if (receiverArgument instanceof ExpressionReceiver) { - receiverType = updateResultTypeForSmartCasts(receiverType, ((ExpressionReceiver) receiverArgument).getExpression(), - context.dataFlowInfo, context.trace); + receiverType = updateResultTypeForSmartCasts( + receiverType, ((ExpressionReceiver) receiverArgument).getExpression(), context); } constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), RECEIVER_POSITION.position()); } @@ -424,7 +424,8 @@ public class CandidateResolver { argumentExpression, newContext, resolveFunctionArgumentBodies); 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( type, effectiveExpectedType, VALUE_PARAMETER_POSITION.position(valueParameterDescriptor.getIndex())); } @@ -433,16 +434,15 @@ public class CandidateResolver { private static JetType updateResultTypeForSmartCasts( @Nullable JetType type, @Nullable JetExpression argumentExpression, - @NotNull DataFlowInfo dataFlowInfoForArgument, - @NotNull BindingTrace trace + @NotNull ResolutionContext context ) { - JetExpression deparenthesizedArgument = deparenthesizeArgument(argumentExpression); + JetExpression deparenthesizedArgument = deparenthesizeArgument(argumentExpression, context); 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; - Set possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue); + Set possibleTypes = context.dataFlowInfo.getPossibleTypes(dataFlowValue); if (possibleTypes.isEmpty()) return type; return TypeUtils.intersect(JetTypeChecker.DEFAULT, possibleTypes); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/BasicCallResolutionContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/BasicCallResolutionContext.java index 5898913b183..b703557a252 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/BasicCallResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/BasicCallResolutionContext.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.psi.Call; 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.model.MutableDataFlowInfoForArguments; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; @@ -38,11 +39,12 @@ public class BasicCallResolutionContext extends CallResolutionContext @NotNull ResolutionResultsCache resolutionResultsCache, @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments, @NotNull CallChecker callChecker, + @NotNull PartialBodyResolveProvider partialBodyResolveProvider, @NotNull ReceiverValue explicitExtensionReceiverForInvoke, boolean isAnnotationContext, boolean collectAllCandidates ) { super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, - dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates); + dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates); this.candidateCall = candidateCall; this.tracing = tracing; this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke; @@ -71,7 +73,8 @@ public final class CallCandidateResolutionContext candidateCall, tracing, trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments, - context.callChecker, explicitExtensionReceiverForInvoke, context.isAnnotationContext, context.collectAllCandidates); + context.callChecker, context.partialBodyResolveProvider, explicitExtensionReceiverForInvoke, + context.isAnnotationContext, context.collectAllCandidates); } public static CallCandidateResolutionContext create( @@ -94,7 +97,7 @@ public final class CallCandidateResolutionContext return new CallCandidateResolutionContext( candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType, 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); } @@ -106,11 +109,12 @@ public final class CallCandidateResolutionContext @NotNull JetType expectedType, @NotNull ContextDependency contextDependency, @NotNull ResolutionResultsCache resolutionResultsCache, + @NotNull PartialBodyResolveProvider partialBodyResolveProvider, boolean collectAllCandidates ) { return new CallCandidateResolutionContext( candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, - resolutionResultsCache, dataFlowInfoForArguments, callChecker, explicitExtensionReceiverForInvoke, - isAnnotationContext, collectAllCandidates); + resolutionResultsCache, dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, + explicitExtensionReceiverForInvoke, isAnnotationContext, collectAllCandidates); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallResolutionContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallResolutionContext.java index bf2796a46bf..9e353848e69 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallResolutionContext.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.psi.Call; 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.model.DataFlowInfoForArgumentsImpl; import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments; @@ -47,11 +48,12 @@ public abstract class CallResolutionContext extends C @NotNull ResolutionResultsCache resolutionResultsCache, @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments, @NotNull CallChecker callChecker, + @NotNull PartialBodyResolveProvider partialBodyResolveProvider, @NotNull Collection> resolvedCalls, boolean isAnnotationContext, boolean collectAllCandidates ) { super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, - dataFlowInfoForArguments, callChecker, isAnnotationContext, collectAllCandidates); + dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, isAnnotationContext, collectAllCandidates); this.lazyCandidates = lazyCandidates; this.resolvedCalls = resolvedCalls; this.tracing = tracing; @@ -75,7 +77,8 @@ public class ResolutionTask extends C context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments, - context.callChecker, Lists.>newArrayList(), context.isAnnotationContext, context.collectAllCandidates); + context.callChecker, context.partialBodyResolveProvider, Lists.>newArrayList(), + context.isAnnotationContext, context.collectAllCandidates); } public ResolutionTask( @@ -113,12 +116,13 @@ public class ResolutionTask extends C @NotNull JetType expectedType, @NotNull ContextDependency contextDependency, @NotNull ResolutionResultsCache resolutionResultsCache, + @NotNull PartialBodyResolveProvider partialBodyResolveProvider, boolean collectAllCandidates ) { return new ResolutionTask( lazyCandidates, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, - resolutionResultsCache, dataFlowInfoForArguments, callChecker, resolvedCalls, isAnnotationContext, - collectAllCandidates); + resolutionResultsCache, dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, resolvedCalls, + isAnnotationContext, collectAllCandidates); } public ResolutionTask replaceContext(@NotNull BasicCallResolutionContext newContext) { @@ -128,7 +132,7 @@ public class ResolutionTask extends C public ResolutionTask replaceCall(@NotNull Call newCall) { return new ResolutionTask( lazyCandidates, tracing, trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, - resolutionResultsCache, dataFlowInfoForArguments, callChecker, resolvedCalls, + resolutionResultsCache, dataFlowInfoForArguments, callChecker, partialBodyResolveProvider, resolvedCalls, isAnnotationContext, collectAllCandidates); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt index abce4350f98..40aeba56577 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.BindingContext.RESOLVED_CALL import org.jetbrains.kotlin.utils.sure import org.jetbrains.kotlin.psi.psiUtil.getTextWithLocation import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext // resolved call @@ -63,12 +64,12 @@ public fun ResolvedCall.getParameterForArgument(valu // call -public fun Call.hasUnresolvedArguments(context: BindingContext): Boolean { +public fun > Call.hasUnresolvedArguments(context: ResolutionContext): Boolean { val arguments = getValueArguments().map { it?.getArgumentExpression() } return arguments.any { argument -> - val expressionType = context[BindingContext.EXPRESSION_TYPE, argument] - argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument) + val expressionType = context.trace.getBindingContext()[BindingContext.EXPRESSION_TYPE, argument] + argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument, context as ResolutionContext<*>) && (expressionType == null || expressionType.isError()) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 6d31c4f2c27..8492938bcc1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -763,7 +763,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { JetType expressionType = value.getType(KotlinBuiltIns.getInstance()); if (value instanceof IntegerValueTypeConstant && context.contextDependency == INDEPENDENT) { 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); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingContext.java index 43924fb268b..5df4595ecb5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingContext.java @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.types.expressions; import org.jetbrains.annotations.NotNull; 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.ResolutionContext; import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCache; @@ -40,15 +41,15 @@ public class ExpressionTypingContext extends ResolutionContext block = expression.getStatements(); - - Function1 filter = getPartialBodyResolveProvider().getFilter(); - if (filter != null && !(expression instanceof JetPsiUtil.JetExpressionWrapper)) { - block = KotlinPackage.filter(block, filter); - } + List block = ResolvePackage.filterStatements(getPartialBodyResolveProvider(), expression); // SCRIPT: get code descriptor for script declaration DeclarationDescriptor containingDescriptor = context.scope.getContainingDeclaration(); @@ -235,7 +228,8 @@ public class ExpressionTypingServices { r = DataFlowUtils.checkType(builtIns.getUnitType(), expression, context, context.dataFlowInfo); } else { - r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context); + r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, + context.replacePartialBodyResolveProvider(getPartialBodyResolveProvider())); } scope.changeLockLevel(WritableScope.LockLevel.READING);