blob: ba4cce2db2851594293091ba64f4b37b4b9d8a5d [file] [log] [blame]
Douglas Gregorf8b42d12011-11-16 15:22:03 +00001// RUN: rm -rf %t
Douglas Gregor94ad28b2012-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 Gregorcff9f262012-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 Gregor94ad28b2012-01-03 18:24:14 +00007// RUN: %clang_cc1 -fmodules -fmodule-cache-path %t %s -verify
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +00008
Douglas Gregor1b257af2012-12-11 22:11:52 +00009@import category_bottom;
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000010
Douglas Gregor556ecc72011-09-01 19:02:18 +000011
Douglas Gregorcff9f262012-01-27 01:47:08 +000012
13
Douglas Gregorf8b42d12011-11-16 15:22:03 +000014// in category_left.h: expected-note {{previous definition}}
Jordan Rose7c304f52012-08-10 01:06:16 +000015// in category_right.h: expected-warning@11 {{duplicate definition of category}}
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000016
17@interface Foo(Source)
Douglas Gregorf8b42d12011-11-16 15:22:03 +000018-(void)source;
Argyrios Kyrtzidise6b8d682011-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 Gregorcff9f262012-01-27 01:47:08 +000028 [foo top2];
29 [foo top3];
Argyrios Kyrtzidise6b8d682011-09-01 00:58:55 +000030
31 [leftFoo left];
32 [leftFoo bottom];
33}
Douglas Gregorcff9f262012-01-27 01:47:08 +000034
35// Load another module that also adds categories to Foo, verify that
36// we see those categories.
Douglas Gregor1b257af2012-12-11 22:11:52 +000037@import category_other;
Douglas Gregorcff9f262012-01-27 01:47:08 +000038
39void test_other(Foo *foo) {
40 [foo other];
41}
Douglas Gregord3297242013-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 *'}}
Douglas Gregor0f9b9f32013-01-17 00:38:46 +000050 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 Gregord3297242013-01-16 23:00:23 +000058}
59
60@import category_left.sub;
61
62void test_hidden_right_errors(Foo *foo) {
63 // These are okay
64 [foo left_sub]; // okay
65 id<P1> p1 = foo;
Douglas Gregor0f9b9f32013-01-17 00:38:46 +000066 id<P3> p3;
67 [p3 p3_method];
68 id p3p = p3.p3_prop;
69 p3p = foo.p3_prop;
70 // These should fail
Douglas Gregord3297242013-01-16 23:00:23 +000071 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 Gregor0f9b9f32013-01-17 00:38:46 +000074 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 Gregord3297242013-01-16 23:00:23 +000079}
80
81@import category_right.sub;
82
83void 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 Gregor0f9b9f32013-01-17 00:38:46 +000089 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 Gregord3297242013-01-16 23:00:23 +000097}