Merge remote-tracking branch 'origin/master' clion/140.1814
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 19 Jan 2015 16:08:19 +0000 (19:08 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 19 Jan 2015 16:08:19 +0000 (19:08 +0300)
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java

index eaebe9c3be64d5441fbdcf27e21d6d9af7d87ceb..675b413ea83fa74525d2f584de482d706b121592 100644 (file)
@@ -221,20 +221,31 @@ public class TypesUtil {
                                            @NotNull PsiElement context,
                                            @NotNull ApplicableTo position) {
     if (actualType instanceof PsiIntersectionType) {
+      ConversionResult min = ConversionResult.ERROR;
       for (PsiType child : ((PsiIntersectionType)actualType).getConjuncts()) {
-        if (canAssign(targetType, child, context, position) == ConversionResult.OK) {
+        final ConversionResult result = canAssign(targetType, child, context, position);
+        if (result.ordinal() < min.ordinal()) {
+          min = result;
+        }
+        if (min == ConversionResult.OK) {
           return ConversionResult.OK;
         }
       }
-      return ConversionResult.ERROR;
+      return min;
     }
+    
     if (targetType instanceof PsiIntersectionType) {
+      ConversionResult max = ConversionResult.OK;
       for (PsiType child : ((PsiIntersectionType)targetType).getConjuncts()) {
-        if (canAssign(child, actualType, context, position) != ConversionResult.OK) {
+        final ConversionResult result = canAssign(child, actualType, context, position);
+        if (result.ordinal() > max.ordinal()) {
+          max = result;
+        }
+        if (max == ConversionResult.ERROR) {
           return ConversionResult.ERROR;
         }
       }
-      return ConversionResult.OK;
+      return max;
     }
 
     final ConversionResult result = areTypesConvertible(targetType, actualType, context, position);