1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s 2*67e74705SXin Li@protocol NSObject 3*67e74705SXin Li@end 4*67e74705SXin Li 5*67e74705SXin Li@protocol DTOutputStreams <NSObject> 6*67e74705SXin Li@end 7*67e74705SXin Li 8*67e74705SXin Li@interface DTFilterOutputStream <DTOutputStreams> 9*67e74705SXin Li- nextOutputStream; 10*67e74705SXin Li@end 11*67e74705SXin Li 12*67e74705SXin Li@implementation DTFilterOutputStream 13*67e74705SXin Li- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { 14*67e74705SXin Li id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; 15*67e74705SXin Li self = nextOutputStream; 16*67e74705SXin Li return nextOutputStream ? nextOutputStream : self; 17*67e74705SXin Li} 18*67e74705SXin Li- nextOutputStream { 19*67e74705SXin Li return self; 20*67e74705SXin Li} 21*67e74705SXin Li@end 22*67e74705SXin Li 23*67e74705SXin Li@interface DTFilterOutputStream2 24*67e74705SXin Li- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}} 25*67e74705SXin Li@end 26*67e74705SXin Li 27*67e74705SXin Li@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}} 28*67e74705SXin Li- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { 29*67e74705SXin Li id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; 30*67e74705SXin Li self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}} 31*67e74705SXin Li return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}} 32*67e74705SXin Li} 33*67e74705SXin Li@end 34*67e74705SXin Li 35*67e74705SXin Li// No @interface declaration for DTFilterOutputStream3 36*67e74705SXin Li@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} \ 37*67e74705SXin Li // expected-note {{receiver is instance of class declared here}} 38*67e74705SXin Li- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { 39*67e74705SXin Li id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}} 40*67e74705SXin Li self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}} 41*67e74705SXin Li return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}} 42*67e74705SXin Li} 43*67e74705SXin Li@end 44*67e74705SXin Li 45*67e74705SXin Li// 46*67e74705SXin Li 47*67e74705SXin Li@protocol P0 48*67e74705SXin Li@property int intProp; 49*67e74705SXin Li@end 50*67e74705SXin Li@protocol P1 51*67e74705SXin Li@end 52*67e74705SXin Li@protocol P2 53*67e74705SXin Li@end 54*67e74705SXin Li@protocol P3 <P1> 55*67e74705SXin Li@end 56*67e74705SXin Li@protocol P4 <P1> 57*67e74705SXin Li@end 58*67e74705SXin Li 59*67e74705SXin Li@interface A <P0> 60*67e74705SXin Li@end 61*67e74705SXin Li 62*67e74705SXin Li@interface B : A 63*67e74705SXin Li@end 64*67e74705SXin Li 65*67e74705SXin Li@interface C 66*67e74705SXin Li@end 67*67e74705SXin Li 68*67e74705SXin Li@interface D 69*67e74705SXin Li@end 70*67e74705SXin Li 71*67e74705SXin Li@interface E : A 72*67e74705SXin Li@end 73*67e74705SXin Li 74*67e74705SXin Livoid f0(id<P0> x) { 75*67e74705SXin Li x.intProp = 1; 76*67e74705SXin Li} 77*67e74705SXin Li 78*67e74705SXin Livoid f1(int cond, id<P0> x, id<P0> y) { 79*67e74705SXin Li (cond ? x : y).intProp = 1; 80*67e74705SXin Li} 81*67e74705SXin Li 82*67e74705SXin Livoid f2(int cond, id<P0> x, A *y) { 83*67e74705SXin Li (cond ? x : y).intProp = 1; 84*67e74705SXin Li} 85*67e74705SXin Li 86*67e74705SXin Livoid f3(int cond, id<P0> x, B *y) { 87*67e74705SXin Li (cond ? x : y).intProp = 1; 88*67e74705SXin Li} 89*67e74705SXin Li 90*67e74705SXin Livoid f4(int cond, id x, B *y) { 91*67e74705SXin Li (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}} 92*67e74705SXin Li} 93*67e74705SXin Li 94*67e74705SXin Livoid f5(int cond, id<P0> x, C *y) { 95*67e74705SXin Li (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'}} 96*67e74705SXin Li} 97*67e74705SXin Li 98*67e74705SXin Livoid f6(int cond, C *x, D *y) { 99*67e74705SXin Li (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}} 100*67e74705SXin Li} 101*67e74705SXin Li 102*67e74705SXin Liid f7(int a, id<P0> x, A* p) { 103*67e74705SXin Li return a ? x : p; 104*67e74705SXin Li} 105*67e74705SXin Li 106*67e74705SXin Liint f8(int a, A<P0> *x, A *y) { 107*67e74705SXin Li return [ (a ? x : y ) intProp ]; 108*67e74705SXin Li} 109*67e74705SXin Li 110*67e74705SXin Livoid f9(int a, A<P0> *x, A<P1> *y) { 111*67e74705SXin Li id l0 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0. 112*67e74705SXin Li A<P0> *l1 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0. 113*67e74705SXin Li A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}} 114*67e74705SXin Li (void)[ (a ? x : y ) intProp ]; // Ok. Common type is A<P0> * and P0's property intProp is accessed. 115*67e74705SXin Li} 116*67e74705SXin Li 117*67e74705SXin Livoid f10(int a, id<P0> x, id y) { 118*67e74705SXin Li [ (a ? x : y ) intProp ]; 119*67e74705SXin Li} 120*67e74705SXin Li 121*67e74705SXin Livoid f11(int a, id<P0> x, id<P1> y) { 122*67e74705SXin Li [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}} 123*67e74705SXin Li} 124*67e74705SXin Li 125*67e74705SXin Livoid f12(int a, A<P0> *x, A<P1> *y) { 126*67e74705SXin Li A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}} 127*67e74705SXin Li} 128*67e74705SXin Li 129*67e74705SXin Livoid f13(int a, B<P3, P0> *x, E<P0, P4> *y) { 130*67e74705SXin Li int *ip = a ? x : y; // expected-warning{{expression of type 'A<P1> *'}} 131*67e74705SXin Li} 132