blob: 53afe7257d2a00eff8965edc9d73fa195cb0a65f [file] [log] [blame]
Patrick Beardacfbe9e2012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -DNON_FIXITS -verify -Wno-objc-root-class %s
Douglas Gregor0e7dde52011-04-24 05:37:28 +00002// RUN: cp %s %t
Patrick Beardacfbe9e2012-04-06 18:12:22 +00003// RUN: not %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fixit -Wno-objc-root-class %t
4// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -pedantic -Werror -Wno-objc-root-class %t
Douglas Gregor0e7dde52011-04-24 05:37:28 +00005// RUN: grep "@implementation Sub3" %t
Douglas Gregor19ead872010-10-26 23:34:31 +00006
Douglas Gregor0e7dde52011-04-24 05:37:28 +00007@interface NSString // expected-note 2{{'NSString' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +00008+ (int)method:(int)x;
Douglas Gregor25363982010-01-01 00:15:04 +00009@end
10
11void test() {
Douglas Gregorae79fdf2011-04-27 04:02:56 +000012 NSstring *str = @"A string"; // expected-error{{unknown type name 'NSstring'; did you mean 'NSString'?}}
Douglas Gregor25363982010-01-01 00:15:04 +000013}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000014
15@protocol P1
Fariborz Jahanian98609b32010-01-20 01:51:55 +000016@optional
Douglas Gregor6da83622010-01-07 00:17:44 +000017@property int *sprop; // expected-note{{'sprop' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000018@end
19
20@interface A
21{
Douglas Gregor6da83622010-01-07 00:17:44 +000022 int his_ivar; // expected-note 2{{'his_ivar' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000023 float wibble;
24}
Douglas Gregor952cf942010-05-31 14:58:57 +000025- (void)methodA;
26+ (void)methodA;
Douglas Gregor6da83622010-01-07 00:17:44 +000027@property int his_prop; // expected-note{{'his_prop' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000028@end
29
30@interface B : A <P1>
31{
Douglas Gregor6da83622010-01-07 00:17:44 +000032 int her_ivar; // expected-note 2{{'her_ivar' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000033}
34
Douglas Gregor6da83622010-01-07 00:17:44 +000035@property int her_prop; // expected-note{{'her_prop' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000036- (void)inst_method1:(int)a;
37+ (void)class_method1;
38@end
39
40@implementation A
41@synthesize his_prop = his_ivar;
Douglas Gregor952cf942010-05-31 14:58:57 +000042- (void)methodA { }
43+ (void)methodA { }
Douglas Gregor35b0bac2010-01-03 18:01:57 +000044@end
45
46@implementation B
47@synthesize her_prop = her_ivar;
48
49-(void)inst_method1:(int)a {
50 herivar = a; // expected-error{{use of undeclared identifier 'herivar'; did you mean 'her_ivar'?}}
51 hisivar = a; // expected-error{{use of undeclared identifier 'hisivar'; did you mean 'his_ivar'?}}
52 self->herivar = a; // expected-error{{'B' does not have a member named 'herivar'; did you mean 'her_ivar'?}}
53 self->hisivar = a; // expected-error{{'B' does not have a member named 'hisivar'; did you mean 'his_ivar'?}}
54 self.hisprop = 0; // expected-error{{property 'hisprop' not found on object of type 'B *'; did you mean 'his_prop'?}}
55 self.herprop = 0; // expected-error{{property 'herprop' not found on object of type 'B *'; did you mean 'her_prop'?}}
56 self.s_prop = 0; // expected-error{{property 's_prop' not found on object of type 'B *'; did you mean 'sprop'?}}
57}
58
59+(void)class_method1 {
60}
61@end
62
63void test_message_send(B* b) {
Douglas Gregor8aa4ebf2010-04-14 02:46:37 +000064 [NSstring method:17]; // expected-error{{unknown receiver 'NSstring'; did you mean 'NSString'?}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000065}
66
Douglas Gregor6da83622010-01-07 00:17:44 +000067@interface Collide // expected-note{{'Collide' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000068{
69@public
Douglas Gregor6da83622010-01-07 00:17:44 +000070 int value; // expected-note{{'value' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000071}
72
Douglas Gregor6da83622010-01-07 00:17:44 +000073@property int value; // expected-note{{'value' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000074@end
75
76@implementation Collide
77@synthesize value = value;
78@end
79
80void test2(Collide *a) {
81 a.valu = 17; // expected-error{{property 'valu' not found on object of type 'Collide *'; did you mean 'value'?}}
82 a->vale = 17; // expected-error{{'Collide' does not have a member named 'vale'; did you mean 'value'?}}
83}
84
Ted Kremenek990783e2010-05-17 23:03:33 +000085#ifdef NON_FIXITS
Douglas Gregor35b0bac2010-01-03 18:01:57 +000086@interface Derived : Collid // expected-error{{cannot find interface declaration for 'Collid', superclass of 'Derived'; did you mean 'Collide'?}}
87@end
Ted Kremenek990783e2010-05-17 23:03:33 +000088#endif
Douglas Gregor35b0bac2010-01-03 18:01:57 +000089
Ted Kremenek990783e2010-05-17 23:03:33 +000090#ifdef NON_FIXITS
Douglas Gregor6da83622010-01-07 00:17:44 +000091@protocol NetworkSocket // expected-note{{'NetworkSocket' declared here}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000092- (int)send:(void*)buffer bytes:(int)bytes;
93@end
94
Douglas Gregor0c8a1722010-02-04 23:42:48 +000095@interface IPv6 <Network_Socket> // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}}
Douglas Gregor35b0bac2010-01-03 18:01:57 +000096@end
Ted Kremenek990783e2010-05-17 23:03:33 +000097#endif
Douglas Gregor280e1ee2010-04-14 20:04:41 +000098
99@interface Super
Ted Kremenek990783e2010-05-17 23:03:33 +0000100- (int)method; // expected-note{{using}}
Douglas Gregor5fd04d42010-05-18 16:14:23 +0000101- (int)method2;
Douglas Gregor2a1d72d2010-10-26 17:18:00 +0000102- (int)method3:(id)x;
Douglas Gregor280e1ee2010-04-14 20:04:41 +0000103@end
104
105@interface Sub : Super
Manman Ren71224532016-04-09 18:59:48 +0000106- (int)method; // expected-note{{also found}}
Douglas Gregor280e1ee2010-04-14 20:04:41 +0000107@end
108
109@implementation Sub
110- (int)method {
111 return [supper method]; // expected-error{{unknown receiver 'supper'; did you mean 'super'?}}
112}
113
114@end
Douglas Gregor0b59e802010-04-19 18:02:19 +0000115
Douglas Gregor5fd04d42010-05-18 16:14:23 +0000116@interface Sub2 : Super
117- (int)method2;
118@end
119
120@implementation Sub2
121- (int)method2 {
Douglas Gregor86ad0852010-05-18 16:30:22 +0000122 return [supper method2]; // expected-error{{unknown receiver 'supper'; did you mean 'super'?}}
Douglas Gregor5fd04d42010-05-18 16:14:23 +0000123}
124@end
Douglas Gregor5fd04d42010-05-18 16:14:23 +0000125
Douglas Gregor0b59e802010-04-19 18:02:19 +0000126@interface Ivar
127@end
128
129@protocol Proto
130@property (retain) id ivar;
131@end
132
Ted Kremenek990783e2010-05-17 23:03:33 +0000133#ifdef NON_FIXITS
Douglas Gregor0b59e802010-04-19 18:02:19 +0000134@interface User <Proto>
Ted Kremenek990783e2010-05-17 23:03:33 +0000135- (void)method; // expected-note{{also found}}
Douglas Gregor0b59e802010-04-19 18:02:19 +0000136@end
137
138@implementation User
Douglas Gregor8b6be162010-05-18 16:57:36 +0000139@synthesize ivar;
Douglas Gregor0b59e802010-04-19 18:02:19 +0000140
141- (void)method {
Ted Kremenek990783e2010-05-17 23:03:33 +0000142 // Test that we don't correct 'ivar' to 'Ivar' e
143 [ivar method]; // expected-warning{{multiple methods named 'method' found}}
Douglas Gregor0b59e802010-04-19 18:02:19 +0000144}
145@end
Ted Kremenek990783e2010-05-17 23:03:33 +0000146#endif
Douglas Gregor0b59e802010-04-19 18:02:19 +0000147
Douglas Gregor990ccac2010-05-31 14:40:22 +0000148void f(A *a) {
149 f(a) // expected-error{{expected ';' after expression}}
Douglas Gregor952cf942010-05-31 14:58:57 +0000150 [a methodA] // expected-error{{expected ';' after expression}}
151 [A methodA] // expected-error{{expected ';' after expression}}
Douglas Gregor990ccac2010-05-31 14:40:22 +0000152}
Douglas Gregor0b59e802010-04-19 18:02:19 +0000153
Douglas Gregor2a1d72d2010-10-26 17:18:00 +0000154#ifdef NON_FIXITS
Douglas Gregorfc0862d2010-10-26 18:25:19 +0000155@interface Sub3 : Super
156- (int)method3;
157@end
158
159@implementation Sub3
160- (int)method3 {
Douglas Gregor0e7dde52011-04-24 05:37:28 +0000161 int x = super; // expected-error{{use of undeclared identifier 'super'}}
Douglas Gregor2a1d72d2010-10-26 17:18:00 +0000162 return 0;
163}
164@end
165#endif