diff --git a/idea/src/org/jetbrains/jet/lang/types/DataFlowInfo.java b/idea/src/org/jetbrains/jet/lang/types/DataFlowInfo.java index 7a150bf0a89..2de1d738c35 100644 --- a/idea/src/org/jetbrains/jet/lang/types/DataFlowInfo.java +++ b/idea/src/org/jetbrains/jet/lang/types/DataFlowInfo.java @@ -13,18 +13,6 @@ import java.util.*; */ public class DataFlowInfo { - private static DataFlowInfo EMPTY = new DataFlowInfo(ImmutableMap.of(), Multimaps.forMap(Collections.emptyMap())); - public static final Supplier> ARRAY_LIST_SUPPLIER = new Supplier>() { - @Override - public List get() { - return Lists.newArrayList(); - } - }; - - public static DataFlowInfo getEmpty() { - return EMPTY; - } - public static abstract class CompositionOperator { public abstract DataFlowInfo compose(DataFlowInfo a, DataFlowInfo b); } @@ -43,12 +31,24 @@ public class DataFlowInfo { } }; + public static final Supplier> ARRAY_LIST_SUPPLIER = new Supplier>() { + @Override + public List get() { + return Lists.newArrayList(); + } + }; + private static DataFlowInfo EMPTY = new DataFlowInfo(ImmutableMap.of(), Multimaps.newListMultimap(Collections.>emptyMap(), ARRAY_LIST_SUPPLIER)); + + public static DataFlowInfo getEmpty() { + return EMPTY; + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private final ImmutableMap nullabilityInfo; - private final Multimap typeInfo; + private final ListMultimap typeInfo; - public DataFlowInfo(ImmutableMap nullabilityInfo, Multimap typeInfo) { + private DataFlowInfo(ImmutableMap nullabilityInfo, ListMultimap typeInfo) { this.nullabilityInfo = nullabilityInfo; this.typeInfo = typeInfo; } @@ -66,7 +66,7 @@ public class DataFlowInfo { } @NotNull - public Collection getPossibleTypes(VariableDescriptor variableDescriptor) { + public List getPossibleTypes(VariableDescriptor variableDescriptor) { return typeInfo.get(variableDescriptor); } @@ -81,7 +81,7 @@ public class DataFlowInfo { } public DataFlowInfo isInstanceOf(@NotNull VariableDescriptor variableDescriptor, @NotNull JetType type) { - Multimap newTypeInfo = copyTypeInfo(); + ListMultimap newTypeInfo = copyTypeInfo(); newTypeInfo.put(variableDescriptor, type); return new DataFlowInfo(getEqualsToNullMap(variableDescriptor, !type.isNullable()), newTypeInfo); } @@ -101,13 +101,13 @@ public class DataFlowInfo { } } - Multimap newTypeInfo = copyTypeInfo(); + ListMultimap newTypeInfo = copyTypeInfo(); newTypeInfo.putAll(other.typeInfo); return new DataFlowInfo(ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo); } - private Multimap copyTypeInfo() { - Multimap newTypeInfo = Multimaps.newListMultimap(Maps.>newHashMap(), ARRAY_LIST_SUPPLIER); + private ListMultimap copyTypeInfo() { + ListMultimap newTypeInfo = Multimaps.newListMultimap(Maps.>newHashMap(), ARRAY_LIST_SUPPLIER); newTypeInfo.putAll(typeInfo); return newTypeInfo; } @@ -123,7 +123,7 @@ public class DataFlowInfo { builder.put(variableDescriptor, thisFlags.or(otherFlags)); } - Multimap newTypeInfo = copyTypeInfo(); + ListMultimap newTypeInfo = copyTypeInfo(); Set keys = newTypeInfo.keySet(); keys.retainAll(other.typeInfo.keySet()); diff --git a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index c92354a6ee8..15aeb87316e 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -1657,7 +1657,8 @@ public class JetTypeInferrer { VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(receiverExpression); if (variableDescriptor != null) { - Collection possibleTypes = dataFlowInfo.getPossibleTypes(variableDescriptor); + List possibleTypes = Lists.newArrayList(dataFlowInfo.getPossibleTypes(variableDescriptor)); + Collections.reverse(possibleTypes); for (JetType possibleType : possibleTypes) { errorHandler.openRegion(); selectorReturnType = getSelectorReturnType(possibleType, selectorExpression); @@ -1801,7 +1802,9 @@ public class JetTypeInferrer { } } else { - trace.getErrorHandler().genericError(pattern.getNode(), "Unsupported [JetTypeInferrer]"); + if (pattern != null) { + trace.getErrorHandler().genericError(pattern.getNode(), "Unsupported [JetTypeInferrer]"); + } } result = semanticServices.getStandardLibrary().getBooleanType(); } diff --git a/idea/testData/checker/infos/Autocasts.jet b/idea/testData/checker/infos/Autocasts.jet index b1b7d3f3bfe..83f21da42ee 100644 --- a/idea/testData/checker/infos/Autocasts.jet +++ b/idea/testData/checker/infos/Autocasts.jet @@ -39,3 +39,17 @@ fun f10() { return; } } + +class C() : A() { + fun bar() { + + } +} + +fun f10(a : A?) { + if (a is B) { + if (a is C) { + a.bar(); + } + } +}