Fix <rdar://problem/6424347> clang on xcode: Assertion failed: (0 && "unexpected type"), function mergeTypes,


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60845 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index ba61332..241dce6 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2126,35 +2126,35 @@
   if (LHSClass == Type::ObjCQualifiedInterface) LHSClass = Type::ObjCInterface;
   if (RHSClass == Type::ObjCQualifiedInterface) RHSClass = Type::ObjCInterface;
 
+  // ID is compatible with all qualified id types.
+  if (LHS->isObjCQualifiedIdType()) {
+    if (const PointerType *PT = RHS->getAsPointerType()) {
+      QualType pType = PT->getPointeeType();
+      if (isObjCIdType(pType))
+        return LHS;
+      // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true).
+      // Unfortunately, this API is part of Sema (which we don't have access
+      // to. Need to refactor. The following check is insufficient, since we 
+      // need to make sure the class implements the protocol.
+      if (pType->isObjCInterfaceType())
+        return LHS;
+    }
+  }
+  if (RHS->isObjCQualifiedIdType()) {
+    if (const PointerType *PT = LHS->getAsPointerType()) {
+      QualType pType = PT->getPointeeType();
+      if (isObjCIdType(pType))
+        return RHS;
+      // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true).
+      // Unfortunately, this API is part of Sema (which we don't have access
+      // to. Need to refactor. The following check is insufficient, since we 
+      // need to make sure the class implements the protocol.
+      if (pType->isObjCInterfaceType())
+        return RHS;
+    }
+  }
   // If the canonical type classes don't match.
   if (LHSClass != RHSClass) {
-    // ID is compatible with all qualified id types.
-    if (LHS->isObjCQualifiedIdType()) {
-      if (const PointerType *PT = RHS->getAsPointerType()) {
-        QualType pType = PT->getPointeeType();
-        if (isObjCIdType(pType))
-          return LHS;
-        // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true).
-        // Unfortunately, this API is part of Sema (which we don't have access
-        // to. Need to refactor. The following check is insufficient, since we 
-        // need to make sure the class implements the protocol.
-        if (pType->isObjCInterfaceType())
-          return LHS;
-      }
-    }
-    if (RHS->isObjCQualifiedIdType()) {
-      if (const PointerType *PT = LHS->getAsPointerType()) {
-        QualType pType = PT->getPointeeType();
-        if (isObjCIdType(pType))
-          return RHS;
-        // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true).
-        // Unfortunately, this API is part of Sema (which we don't have access
-        // to. Need to refactor. The following check is insufficient, since we 
-        // need to make sure the class implements the protocol.
-        if (pType->isObjCInterfaceType())
-          return RHS;
-      }
-    }
 
     // C99 6.7.2.2p4: Each enumerated type shall be compatible with char,
     // a signed integer type, or an unsigned integer type. 
diff --git a/test/SemaObjC/method-conflict.m b/test/SemaObjC/method-conflict.m
new file mode 100644
index 0000000..c46f489
--- /dev/null
+++ b/test/SemaObjC/method-conflict.m
@@ -0,0 +1,53 @@
+// RUN: clang -fsyntax-only -verify %s
+
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+@protocol NSObject  - (BOOL)isEqual:(id)object;
+@end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
+@end  @protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone;
+@end  @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;
+@end    @interface NSObject <NSObject> {
+}
+@end    extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
+@interface NSValue : NSObject <NSCopying, NSCoding>  - (void)getValue:(void *)value;
+@end        @class NSString;
+typedef struct _NSRange {
+}
+  NSRange;
+@interface NSValue (NSValueRangeExtensions)  + (NSValue *)valueWithRange:(NSRange)range;
+@end  @interface NSAttributedString : NSObject <NSCopying, NSMutableCopying, NSCoding>  - (NSString *)string;
+@end  @interface NSMutableAttributedString : NSAttributedString  - (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str;
+@end       @class NSArray, NSDictionary, NSString, NSError;
+@interface NSScanner : NSObject <NSCopying>  - (NSString *)string;
+@end        typedef struct {
+}
+  CSSM_FIELDGROUP, *CSSM_FIELDGROUP_PTR;
+@protocol XDUMLClassifier;
+@protocol XDUMLClassInterfaceCommons <XDUMLClassifier>    @end  @protocol XDUMLImplementation;
+@protocol XDUMLElement <NSObject> - (NSArray *) ownedElements;
+@end @protocol XDUMLDataType;
+@protocol XDUMLNamedElement <XDUMLElement>     - (NSString *) name;
+@end enum _XDSourceLanguage {
+XDSourceUnknown=0,     XDSourceJava,     XDSourceC,     XDSourceCPP,     XDSourceObjectiveC };
+typedef NSUInteger XDSourceLanguage;
+@protocol XDSCClassifier <XDUMLClassInterfaceCommons> - (XDSourceLanguage)language;
+@end  @class XDSCDocController;
+@interface XDSCDisplaySpecification : NSObject <NSCoding>{
+}
+@end  @class XDSCOperation;
+@interface XDSCClassFormatter : NSObject {
+}
++ (NSUInteger) compartmentsForClassifier: (id <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec;
+@end  
+@class NSString;
+@implementation XDSCClassFormatter       
+
++ appendVisibility: (id <XDUMLNamedElement>) element withSpecification: (XDSCDisplaySpecification *) displaySpec to: (NSMutableAttributedString *) attributedString
+{
+}
+// FIXME: should we warn? (since the protocols are different). FWIW...GCC doesn't currently.
++ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec {
+}
+@end 
\ No newline at end of file