blob: 05a66ca4ee5a02a08b49645897327ec6f011d6ca [file] [log] [blame]
Douglas Gregor4ba7c2a2011-11-16 15:22:03 +00001// RUN: rm -rf %t
Douglas Gregor0bf886d2012-01-03 18:24:14 +00002// 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 Gregor404cdde2012-01-27 01:47:08 +00006// RUN: %clang_cc1 -fmodules -fmodule-cache-path %t -x objective-c -fmodule-name=category_other -emit-module %S/Inputs/module.map
Douglas Gregor0bf886d2012-01-03 18:24:14 +00007// RUN: %clang_cc1 -fmodules -fmodule-cache-path %t %s -verify
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00008
Douglas Gregorc50d4922012-12-11 22:11:52 +00009@import category_bottom;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000010
Douglas Gregor6ac0b712011-09-01 19:02:18 +000011
Douglas Gregor404cdde2012-01-27 01:47:08 +000012
13
Douglas Gregor4ba7c2a2011-11-16 15:22:03 +000014// in category_left.h: expected-note {{previous definition}}
Jordan Roseb00073d2012-08-10 01:06:16 +000015// in category_right.h: expected-warning@11 {{duplicate definition of category}}
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000016
17@interface Foo(Source)
Douglas Gregor4ba7c2a2011-11-16 15:22:03 +000018-(void)source;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000019@end
20
21void test(Foo *foo, LeftFoo *leftFoo) {
22 [foo source];
23 [foo bottom];
24 [foo left];
25 [foo right1];
26 [foo right2];
27 [foo top];
Douglas Gregor404cdde2012-01-27 01:47:08 +000028 [foo top2];
29 [foo top3];
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000030
31 [leftFoo left];
32 [leftFoo bottom];
33}
Douglas Gregor404cdde2012-01-27 01:47:08 +000034
35// Load another module that also adds categories to Foo, verify that
36// we see those categories.
Douglas Gregorc50d4922012-12-11 22:11:52 +000037@import category_other;
Douglas Gregor404cdde2012-01-27 01:47:08 +000038
39void test_other(Foo *foo) {
40 [foo other];
41}
Douglas Gregor048fbfa2013-01-16 23:00:23 +000042
43// Make sure we don't see categories that should be hidden
44void 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 *'}}
50}
51
52@import category_left.sub;
53
54void test_hidden_right_errors(Foo *foo) {
55 // These are okay
56 [foo left_sub]; // okay
57 id<P1> p1 = foo;
58 // FIXME: these should fail
59 foo.right_sub_prop = foo; // expected-error{{property 'right_sub_prop' not found on object of type 'Foo *'}}
60 int i = foo->right_sub_ivar; // expected-error{{'Foo' does not have a member named 'right_sub_ivar'}}
61 id<P2> p2 = foo; // expected-warning{{initializing 'id<P2>' with an expression of incompatible type 'Foo *'}}
62}
63
64@import category_right.sub;
65
66void test_hidden_okay(Foo *foo) {
67 [foo left_sub];
68 foo.right_sub_prop = foo;
69 int i = foo->right_sub_ivar;
70 id<P1> p1 = foo;
71 id<P2> p2 = foo;
72}