Douglas Gregor | f8b42d1 | 2011-11-16 15:22:03 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Douglas Gregor | 953a61f | 2013-02-07 19:01:24 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_top -emit-module %S/Inputs/module.map |
| 3 | // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_left -emit-module %S/Inputs/module.map |
| 4 | // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_right -emit-module %S/Inputs/module.map |
| 5 | // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_bottom -emit-module %S/Inputs/module.map |
| 6 | // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_other -emit-module %S/Inputs/module.map |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 7 | // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 8 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 9 | @import category_bottom; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 10 | |
Andy Gibbs | b42f200 | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 11 | // expected-note@Inputs/category_left.h:14 {{previous definition}} |
| 12 | // expected-warning@Inputs/category_right.h:11 {{duplicate definition of category}} |
Fariborz Jahanian | 1404014 | 2013-05-15 15:27:35 +0000 | [diff] [blame] | 13 | // expected-note@Inputs/category_top.h:1 {{receiver is instance of class declared here}} |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 14 | |
| 15 | @interface Foo(Source) |
Douglas Gregor | f8b42d1 | 2011-11-16 15:22:03 +0000 | [diff] [blame] | 16 | -(void)source; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 17 | @end |
| 18 | |
| 19 | void test(Foo *foo, LeftFoo *leftFoo) { |
| 20 | [foo source]; |
| 21 | [foo bottom]; |
| 22 | [foo left]; |
| 23 | [foo right1]; |
| 24 | [foo right2]; |
| 25 | [foo top]; |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 26 | [foo top2]; |
| 27 | [foo top3]; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 28 | |
| 29 | [leftFoo left]; |
| 30 | [leftFoo bottom]; |
| 31 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 32 | |
| 33 | // Load another module that also adds categories to Foo, verify that |
| 34 | // we see those categories. |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 35 | @import category_other; |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 36 | |
| 37 | void test_other(Foo *foo) { |
| 38 | [foo other]; |
| 39 | } |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 40 | |
| 41 | // Make sure we don't see categories that should be hidden |
| 42 | void test_hidden_all_errors(Foo *foo) { |
| 43 | [foo left_sub]; // expected-warning{{instance method '-left_sub' not found (return type defaults to 'id')}} |
| 44 | foo.right_sub_prop = foo; // expected-error{{property 'right_sub_prop' not found on object of type 'Foo *'}} |
| 45 | int i = foo->right_sub_ivar; // expected-error{{'Foo' does not have a member named 'right_sub_ivar'}} |
| 46 | id<P1> p1 = foo; // expected-warning{{initializing 'id<P1>' with an expression of incompatible type 'Foo *'}} |
| 47 | id<P2> p2 = foo; // expected-warning{{initializing 'id<P2>' with an expression of incompatible type 'Foo *'}} |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 48 | id<P3> p3; |
| 49 | [p3 p3_method]; // expected-warning{{instance method '-p3_method' not found (return type defaults to 'id')}} |
| 50 | id<P4> p4; |
| 51 | [p4 p4_method]; // expected-warning{{instance method '-p4_method' not found (return type defaults to 'id')}} |
| 52 | id p3p = p3.p3_prop; // expected-error{{property 'p3_prop' not found on object of type 'id<P3>'}} |
| 53 | p3p = foo.p3_prop; // expected-error{{property 'p3_prop' not found on object of type 'Foo *'}} |
| 54 | id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'id<P4>'}} |
| 55 | p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'Foo *'}} |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @import category_left.sub; |
| 59 | |
| 60 | void test_hidden_right_errors(Foo *foo) { |
| 61 | // These are okay |
| 62 | [foo left_sub]; // okay |
| 63 | id<P1> p1 = foo; |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 64 | id<P3> p3; |
| 65 | [p3 p3_method]; |
| 66 | id p3p = p3.p3_prop; |
| 67 | p3p = foo.p3_prop; |
| 68 | // These should fail |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 69 | foo.right_sub_prop = foo; // expected-error{{property 'right_sub_prop' not found on object of type 'Foo *'}} |
| 70 | int i = foo->right_sub_ivar; // expected-error{{'Foo' does not have a member named 'right_sub_ivar'}} |
| 71 | id<P2> p2 = foo; // expected-warning{{initializing 'id<P2>' with an expression of incompatible type 'Foo *'}} |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 72 | id<P4> p4; |
| 73 | [p4 p4_method]; // expected-warning{{instance method '-p4_method' not found (return type defaults to 'id')}} |
| 74 | id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'id<P4>'}} |
| 75 | p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'Foo *'; did you mean 'p3_prop'?}} |
Andy Gibbs | b42f200 | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 76 | // expected-note@Inputs/category_left_sub.h:7{{'p3_prop' declared here}} |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | @import category_right.sub; |
| 80 | |
| 81 | void test_hidden_okay(Foo *foo) { |
| 82 | [foo left_sub]; |
| 83 | foo.right_sub_prop = foo; |
| 84 | int i = foo->right_sub_ivar; |
| 85 | id<P1> p1 = foo; |
| 86 | id<P2> p2 = foo; |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 87 | id<P3> p3; |
| 88 | [p3 p3_method]; |
| 89 | id<P4> p4; |
| 90 | [p4 p4_method]; |
| 91 | id p3p = p3.p3_prop; |
| 92 | p3p = foo.p3_prop; |
| 93 | id p4p = p4.p4_prop; |
| 94 | p4p = foo.p4_prop; |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 95 | } |