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