blob: 049a095ce37ca0a1b770f0dcbb63c0466ba38d08 [file] [log] [blame]
Patrick Beardb2f68202012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s
Steve Naroffaa73eec2008-05-31 22:33:45 +00002@protocol NSObject
3@end
4
5@protocol DTOutputStreams <NSObject>
6@end
7
8@interface DTFilterOutputStream <DTOutputStreams>
9- nextOutputStream;
10@end
11
12@implementation DTFilterOutputStream
13- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
14 id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
15 self = nextOutputStream;
16 return nextOutputStream ? nextOutputStream : self;
17}
18- nextOutputStream {
19 return self;
20}
21@end
Steve Naroff19b87d22008-05-31 23:10:15 +000022
23@interface DTFilterOutputStream2
Ted Kremenek8b43d2b2013-03-27 00:02:21 +000024- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}}
Steve Naroff19b87d22008-05-31 23:10:15 +000025@end
26
Ted Kremenek8b43d2b2013-03-27 00:02:21 +000027@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}}
Steve Naroff19b87d22008-05-31 23:10:15 +000028- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
29 id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
Douglas Gregord4eea832010-04-09 00:35:39 +000030 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}}
Steve Naroff4084c302009-07-23 01:01:38 +000031 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}}
Steve Naroff19b87d22008-05-31 23:10:15 +000032}
33@end
34
35// No @interface declaration for DTFilterOutputStream3
Fariborz Jahanian9f00b1d2013-05-14 23:24:17 +000036@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} \
Fariborz Jahanian14040142013-05-15 15:27:35 +000037 // expected-note {{receiver is instance of class declared here}}
Steve Naroff19b87d22008-05-31 23:10:15 +000038- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
Steve Naroff6b9dfd42009-03-04 15:11:40 +000039 id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}}
Douglas Gregord4eea832010-04-09 00:35:39 +000040 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}}
Steve Naroff4084c302009-07-23 01:01:38 +000041 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}}
Steve Naroff19b87d22008-05-31 23:10:15 +000042}
43@end
Daniel Dunbar1cdad9e2009-07-16 21:55:48 +000044
45//
46
47@protocol P0
48@property int intProp;
49@end
50@protocol P1
51@end
52@protocol P2
53@end
54
55@interface A <P0>
56@end
57
58@interface B : A
59@end
60
61@interface C
62@end
63
64@interface D
65@end
66
67void f0(id<P0> x) {
68 x.intProp = 1;
69}
70
71void f1(int cond, id<P0> x, id<P0> y) {
72 (cond ? x : y).intProp = 1;
73}
74
75void f2(int cond, id<P0> x, A *y) {
76 (cond ? x : y).intProp = 1;
77}
78
79void f3(int cond, id<P0> x, B *y) {
80 (cond ? x : y).intProp = 1;
81}
82
83void f4(int cond, id x, B *y) {
84 (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}}
85}
86
87void f5(int cond, id<P0> x, C *y) {
Steve Naroff4084c302009-07-23 01:01:38 +000088 (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types ('id<P0>' and 'C *')}} expected-error {{property 'intProp' not found on object of type 'id'}}
Daniel Dunbar1cdad9e2009-07-16 21:55:48 +000089}
90
91void f6(int cond, C *x, D *y) {
92 (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}}
93}
Daniel Dunbar8cbd38c2009-07-16 23:34:22 +000094
95id f7(int a, id<P0> x, A* p) {
96 return a ? x : p;
97}
98
99void f8(int a, A<P0> *x, A *y) {
100 [ (a ? x : y ) intProp ];
101}
102
103void f9(int a, A<P0> *x, A<P1> *y) {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +0000104 id l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
Daniel Dunbar8cbd38c2009-07-16 23:34:22 +0000105 A<P0> *l1 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
106 A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
107 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
108}
109
110void f10(int a, id<P0> x, id y) {
111 [ (a ? x : y ) intProp ];
112}
113
114void f11(int a, id<P0> x, id<P1> y) {
115 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}}
116}
117
118void f12(int a, A<P0> *x, A<P1> *y) {
119 A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
120}