Implemented when static typing is combined with protocols and use as receiver
type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44685 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index e7102aa..8c5ef43 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -2232,14 +2232,32 @@
         static_cast<PointerType*>(receiverType.getTypePtr());
       receiverType = pointerType->getPointeeType();
     }
-    assert(ObjcInterfaceType::classof(receiverType.getTypePtr()) &&
-           "bad receiver type");
-    ObjcInterfaceDecl* ClassDecl = static_cast<ObjcInterfaceType*>(
-                                     receiverType.getTypePtr())->getDecl();
-    // FIXME: consider using InstanceMethodPool, since it will be faster
-    // than the following method (which can do *many* linear searches). The
-    // idea is to add class info to InstanceMethodPool...
-    Method = ClassDecl->lookupInstanceMethod(Sel);
+    ObjcInterfaceDecl* ClassDecl;
+    if (ObjcQualifiedInterfaceType *QIT = 
+        dyn_cast<ObjcQualifiedInterfaceType>(receiverType)) {
+      ObjcInterfaceType * OITypePtr = QIT->getInterfaceType();
+      
+      ClassDecl = OITypePtr->getDecl();
+      Method = ClassDecl->lookupInstanceMethod(Sel);
+      if (!Method) {
+        // search protocols
+        for (unsigned i = 0; i < QIT->getNumProtocols(); i++) {
+          ObjcProtocolDecl *PDecl = QIT->getProtocols(i);
+          if (PDecl && (Method = PDecl->lookupInstanceMethod(Sel)))
+            break;
+        }
+      }
+    }
+    else {
+      assert(ObjcInterfaceType::classof(receiverType.getTypePtr()) &&
+             "bad receiver type");
+      ClassDecl = static_cast<ObjcInterfaceType*>(
+                    receiverType.getTypePtr())->getDecl();
+      // FIXME: consider using InstanceMethodPool, since it will be faster
+      // than the following method (which can do *many* linear searches). The
+      // idea is to add class info to InstanceMethodPool...
+      Method = ClassDecl->lookupInstanceMethod(Sel);
+    }
     if (!Method) {
       // If we have an implementation in scope, check "private" methods.
       if (ObjcImplementationDecl *ImpDecl =