diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index 86788fec7af..288e92da85c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -47,10 +47,7 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT; import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION; @@ -520,9 +517,8 @@ public class CandidateResolver { @NotNull ResolutionContext context ) { ExpressionReceiver receiverToCast = new ExpressionReceiver(JetPsiUtil.safeDeparenthesize(expression, false), actualType); - List variants = - SmartCastUtils.getSmartCastVariantsExcludingReceiver(context.trace.getBindingContext(), context.dataFlowInfo, - receiverToCast); + Collection variants = SmartCastUtils.getSmartCastVariantsExcludingReceiver( + context.trace.getBindingContext(), context.dataFlowInfo, receiverToCast); for (JetType possibleType : variants) { if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) { return possibleType; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/smartcasts/SmartCastUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/smartcasts/SmartCastUtils.java index ded256bef5d..cd90343982d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/smartcasts/SmartCastUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/smartcasts/SmartCastUtils.java @@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; @@ -68,7 +69,7 @@ public class SmartCastUtils { * @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included */ @NotNull - public static List getSmartCastVariantsExcludingReceiver( + public static Collection getSmartCastVariantsExcludingReceiver( @NotNull BindingContext bindingContext, @NotNull DataFlowInfo dataFlowInfo, @NotNull ReceiverValue receiverToCast @@ -77,23 +78,15 @@ public class SmartCastUtils { ThisReceiver receiver = (ThisReceiver) receiverToCast; assert receiver.exists(); DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver); - return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue); + return dataFlowInfo.getPossibleTypes(dataFlowValue); } else if (receiverToCast instanceof ExpressionReceiver) { DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverToCast, bindingContext); - return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue); + return dataFlowInfo.getPossibleTypes(dataFlowValue); } return Collections.emptyList(); } - @NotNull - private static List collectSmartCastReceiverValues( - @NotNull DataFlowInfo dataFlowInfo, - @NotNull DataFlowValue dataFlowValue - ) { - return Lists.newArrayList(dataFlowInfo.getPossibleTypes(dataFlowValue)); - } - public static boolean isSubTypeBySmartCastIgnoringNullability( @NotNull ReceiverValue receiverArgument, @NotNull JetType receiverParameterType, @@ -106,7 +99,7 @@ public class SmartCastUtils { @Nullable private static JetType getSmartCastSubType( @NotNull JetType receiverParameterType, - @NotNull List smartCastTypes + @NotNull Collection smartCastTypes ) { Set subTypes = Sets.newHashSet(); for (JetType smartCastType : smartCastTypes) { @@ -136,7 +129,7 @@ public class SmartCastUtils { return false; } - List smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver( + Collection smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver( context.trace.getBindingContext(), context.dataFlowInfo, receiver); JetType smartCastSubType = getSmartCastSubType(receiverParameterType, smartCastTypesExcludingReceiver); if (smartCastSubType == null) return false;