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