Merge pull request #10912 from xedin/rdar-33044867-4.0

[4.0] [QoI] Don't try to lookup members on incorrect type during Objective-C KeyPath validation
diff --git a/lib/Sema/TypeCheckExprObjC.cpp b/lib/Sema/TypeCheckExprObjC.cpp
index 9d0fe4c..7a15e38 100644
--- a/lib/Sema/TypeCheckExprObjC.cpp
+++ b/lib/Sema/TypeCheckExprObjC.cpp
@@ -166,6 +166,8 @@
       return lookupUnqualified(dc, componentName, componentNameLoc);
 
     assert(currentType && "Non-beginning state must have a type");
+    if (!currentType->mayHaveMembers())
+      return LookupResult();
 
     // Determine the type in which the lookup should occur. If we have
     // a bridged value type, this will be the Objective-C class to
diff --git a/validation-test/compiler_crashers_2_fixed/0113-rdar33044867.swift b/validation-test/compiler_crashers_2_fixed/0113-rdar33044867.swift
new file mode 100644
index 0000000..c1dd118
--- /dev/null
+++ b/validation-test/compiler_crashers_2_fixed/0113-rdar33044867.swift
@@ -0,0 +1,15 @@
+// RUN: not %target-swift-frontend %s -typecheck
+
+public class A {
+  var property: UndeclaredType
+  var keyPath: Any {
+    return #keyPath(property.foo)
+  }
+}
+
+public class B {
+  var property: UndeclaredType
+  var keyPath: Any {
+    return [#keyPath(property.foo)]
+  }
+}