blob: 74ab59bdb9ed92f90bdab01d6dcf0e77ec013994 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %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
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +000024- nextOutputStream; // expected-note {{{{method definition for 'nextOutputStream' not found}}
Steve Naroff19b87d22008-05-31 23:10:15 +000025@end
26
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +000027@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}}
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
36@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}}
37- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
Steve Naroff6b9dfd42009-03-04 15:11:40 +000038 id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}}
Douglas Gregord4eea832010-04-09 00:35:39 +000039 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}}
Steve Naroff4084c302009-07-23 01:01:38 +000040 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}}
Steve Naroff19b87d22008-05-31 23:10:15 +000041}
42@end
Daniel Dunbar1cdad9e2009-07-16 21:55:48 +000043
44//
45
46@protocol P0
47@property int intProp;
48@end
49@protocol P1
50@end
51@protocol P2
52@end
53
54@interface A <P0>
55@end
56
57@interface B : A
58@end
59
60@interface C
61@end
62
63@interface D
64@end
65
66void f0(id<P0> x) {
67 x.intProp = 1;
68}
69
70void f1(int cond, id<P0> x, id<P0> y) {
71 (cond ? x : y).intProp = 1;
72}
73
74void f2(int cond, id<P0> x, A *y) {
75 (cond ? x : y).intProp = 1;
76}
77
78void f3(int cond, id<P0> x, B *y) {
79 (cond ? x : y).intProp = 1;
80}
81
82void f4(int cond, id x, B *y) {
83 (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}}
84}
85
86void f5(int cond, id<P0> x, C *y) {
Steve Naroff4084c302009-07-23 01:01:38 +000087 (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 +000088}
89
90void f6(int cond, C *x, D *y) {
91 (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}}
92}
Daniel Dunbar8cbd38c2009-07-16 23:34:22 +000093
94id f7(int a, id<P0> x, A* p) {
95 return a ? x : p;
96}
97
98void f8(int a, A<P0> *x, A *y) {
99 [ (a ? x : y ) intProp ];
100}
101
102void f9(int a, A<P0> *x, A<P1> *y) {
103 id l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')'}}
104 A<P0> *l1 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
105 A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
106 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
107}
108
109void f10(int a, id<P0> x, id y) {
110 [ (a ? x : y ) intProp ];
111}
112
113void f11(int a, id<P0> x, id<P1> y) {
114 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}}
115}
116
117void f12(int a, A<P0> *x, A<P1> *y) {
118 A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
119}