blob: 81fb28bafb2a3223420a57737541cc4e8659e155 [file] [log] [blame]
Douglas Gregor4ba7c2a2011-11-16 15:22:03 +00001// RUN: rm -rf %t
Douglas Gregor35b04d62013-02-07 19:01:24 +00002// 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
7// RUN: %clang_cc1 -fmodules -fmodules-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
Andy Gibbsfcc699a2013-04-17 08:06:46 +000011// expected-note@Inputs/category_left.h:14 {{previous definition}}
12// expected-warning@Inputs/category_right.h:11 {{duplicate definition of category}}
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000013
14@interface Foo(Source)
Douglas Gregor4ba7c2a2011-11-16 15:22:03 +000015-(void)source;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000016@end
17
18void test(Foo *foo, LeftFoo *leftFoo) {
19 [foo source];
20 [foo bottom];
21 [foo left];
22 [foo right1];
23 [foo right2];
24 [foo top];
Douglas Gregor404cdde2012-01-27 01:47:08 +000025 [foo top2];
26 [foo top3];
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000027
28 [leftFoo left];
29 [leftFoo bottom];
30}
Douglas Gregor404cdde2012-01-27 01:47:08 +000031
32// Load another module that also adds categories to Foo, verify that
33// we see those categories.
Douglas Gregorc50d4922012-12-11 22:11:52 +000034@import category_other;
Douglas Gregor404cdde2012-01-27 01:47:08 +000035
36void test_other(Foo *foo) {
37 [foo other];
38}
Douglas Gregor048fbfa2013-01-16 23:00:23 +000039
40// Make sure we don't see categories that should be hidden
41void test_hidden_all_errors(Foo *foo) {
42 [foo left_sub]; // expected-warning{{instance method '-left_sub' not found (return type defaults to 'id')}}
43 foo.right_sub_prop = foo; // expected-error{{property 'right_sub_prop' not found on object of type 'Foo *'}}
44 int i = foo->right_sub_ivar; // expected-error{{'Foo' does not have a member named 'right_sub_ivar'}}
45 id<P1> p1 = foo; // expected-warning{{initializing 'id<P1>' with an expression of incompatible type 'Foo *'}}
46 id<P2> p2 = foo; // expected-warning{{initializing 'id<P2>' with an expression of incompatible type 'Foo *'}}
Douglas Gregoreed49792013-01-17 00:38:46 +000047 id<P3> p3;
48 [p3 p3_method]; // expected-warning{{instance method '-p3_method' not found (return type defaults to 'id')}}
49 id<P4> p4;
50 [p4 p4_method]; // expected-warning{{instance method '-p4_method' not found (return type defaults to 'id')}}
51 id p3p = p3.p3_prop; // expected-error{{property 'p3_prop' not found on object of type 'id<P3>'}}
52 p3p = foo.p3_prop; // expected-error{{property 'p3_prop' not found on object of type 'Foo *'}}
53 id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'id<P4>'}}
54 p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'Foo *'}}
Douglas Gregor048fbfa2013-01-16 23:00:23 +000055}
56
57@import category_left.sub;
58
59void test_hidden_right_errors(Foo *foo) {
60 // These are okay
61 [foo left_sub]; // okay
62 id<P1> p1 = foo;
Douglas Gregoreed49792013-01-17 00:38:46 +000063 id<P3> p3;
64 [p3 p3_method];
65 id p3p = p3.p3_prop;
66 p3p = foo.p3_prop;
67 // These should fail
Douglas Gregor048fbfa2013-01-16 23:00:23 +000068 foo.right_sub_prop = foo; // expected-error{{property 'right_sub_prop' not found on object of type 'Foo *'}}
69 int i = foo->right_sub_ivar; // expected-error{{'Foo' does not have a member named 'right_sub_ivar'}}
70 id<P2> p2 = foo; // expected-warning{{initializing 'id<P2>' with an expression of incompatible type 'Foo *'}}
Douglas Gregoreed49792013-01-17 00:38:46 +000071 id<P4> p4;
72 [p4 p4_method]; // expected-warning{{instance method '-p4_method' not found (return type defaults to 'id')}}
73 id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'id<P4>'}}
74 p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object of type 'Foo *'; did you mean 'p3_prop'?}}
Andy Gibbsfcc699a2013-04-17 08:06:46 +000075 // expected-note@Inputs/category_left_sub.h:7{{'p3_prop' declared here}}
Douglas Gregor048fbfa2013-01-16 23:00:23 +000076}
77
78@import category_right.sub;
79
80void test_hidden_okay(Foo *foo) {
81 [foo left_sub];
82 foo.right_sub_prop = foo;
83 int i = foo->right_sub_ivar;
84 id<P1> p1 = foo;
85 id<P2> p2 = foo;
Douglas Gregoreed49792013-01-17 00:38:46 +000086 id<P3> p3;
87 [p3 p3_method];
88 id<P4> p4;
89 [p4 p4_method];
90 id p3p = p3.p3_prop;
91 p3p = foo.p3_prop;
92 id p4p = p4.p4_prop;
93 p4p = foo.p4_prop;
Douglas Gregor048fbfa2013-01-16 23:00:23 +000094}