]> granicus.if.org Git - clang/commitdiff
[ObjC][Modules] Don't perform property lookup in hidden class extensions
authorAlex Lorenz <arphaman@gmail.com>
Wed, 22 Feb 2017 23:18:49 +0000 (23:18 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 22 Feb 2017 23:18:49 +0000 (23:18 +0000)
rdar://30603803

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295903 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclObjC.cpp
test/Modules/Inputs/category_right_sub.h
test/Modules/objc-categories.m

index 60d05f682e6e0f3341a081f97f30f59e9f758afb..9218eb537a60b66bfd3233b359c34105adc351d0 100644 (file)
@@ -162,10 +162,10 @@ ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
         return nullptr;
   }
 
-  // If context is class, then lookup property in its extensions.
+  // If context is class, then lookup property in its visible extensions.
   // This comes before property is looked up in primary class.
   if (auto *IDecl = dyn_cast<ObjCInterfaceDecl>(DC)) {
-    for (const auto *Ext : IDecl->known_extensions())
+    for (const auto *Ext : IDecl->visible_extensions())
       if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext,
                                                        propertyID,
                                                        queryKind))
index 231f65ffe0adcdc31aa6c25127e46eee9f91e4ca..c8ba7937f561e24edec0344465e415376219f565 100644 (file)
@@ -15,3 +15,8 @@
 
 @interface Foo(LeftP4) <P4>
 @end
+
+// A hidden extension
+@interface Foo ()
+@property (assign) int hiddenPropertyFromExtension;
+@end
index 42baf352fbf591cdb31bdcd11992330312a9fc4b..fcffe3cc962003cabab84a3ef3175ebf1c93f884 100644 (file)
@@ -53,6 +53,9 @@ void test_hidden_all_errors(Foo *foo) {
   p3p = foo.p3_prop; // expected-error{{property 'p3_prop' not found on object of type 'Foo *'}}
   id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'id<P4>'}}
   p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'Foo *'}}
+
+  if (foo.hiddenPropertyFromExtension) { // expected-error {{property 'hiddenPropertyFromExtension' not found on object of type 'Foo *'}}
+  }
 }
 
 @import category_left.sub;
@@ -74,6 +77,7 @@ void test_hidden_right_errors(Foo *foo) {
   id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'id<P4>'}}
   p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'Foo *'; did you mean 'p3_prop'?}}
   // expected-note@Inputs/category_left_sub.h:7{{'p3_prop' declared here}}
+  int hiddenFromExtension = foo.hiddenPropertyFromExtension; // expected-error {{property 'hiddenPropertyFromExtension' not found on object of type 'Foo *'}}
 }
 
 @import category_right.sub;
@@ -92,4 +96,6 @@ void test_hidden_okay(Foo *foo) {
   p3p = foo.p3_prop;
   id p4p = p4.p4_prop;
   p4p = foo.p4_prop;
+  if (foo.hiddenPropertyFromExtension) {
+  }
 }