diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.java index 7192a2027f1..ffce32c10e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.java @@ -117,19 +117,33 @@ public class SmartCastManager { @NotNull DeclarationDescriptor containingDeclarationOrModule, @NotNull DataFlowInfo dataFlowInfo, @NotNull ReceiverValue receiverToCast + ) { + DataFlowValue dataFlowValue = getDataFlowValueExcludingReceiver(bindingContext, containingDeclarationOrModule, receiverToCast); + + if (dataFlowValue != null) { + return dataFlowInfo.getPossibleTypes(dataFlowValue); + } + + return Collections.emptyList(); + } + + @Nullable + public static DataFlowValue getDataFlowValueExcludingReceiver( + @NotNull BindingContext bindingContext, + @NotNull DeclarationDescriptor containingDeclarationOrModule, + @NotNull ReceiverValue receiverToCast ) { if (receiverToCast instanceof ThisReceiver) { ThisReceiver receiver = (ThisReceiver) receiverToCast; assert receiver.exists(); - DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver); - return dataFlowInfo.getPossibleTypes(dataFlowValue); + return DataFlowValueFactory.createDataFlowValue(receiver); } else if (receiverToCast instanceof ExpressionReceiver) { - DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue( - receiverToCast, bindingContext, containingDeclarationOrModule); - return dataFlowInfo.getPossibleTypes(dataFlowValue); + return DataFlowValueFactory.createDataFlowValue( + receiverToCast, bindingContext, containingDeclarationOrModule + ); } - return Collections.emptyList(); + return null; } public boolean isSubTypeBySmartCastIgnoringNullability(