aboutsummaryrefslogtreecommitdiff
path: root/test/SemaObjC/block-type-safety.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaObjC/block-type-safety.m')
-rw-r--r--test/SemaObjC/block-type-safety.m43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/SemaObjC/block-type-safety.m b/test/SemaObjC/block-type-safety.m
index 56342baae528..b2c4398dc3c5 100644
--- a/test/SemaObjC/block-type-safety.m
+++ b/test/SemaObjC/block-type-safety.m
@@ -23,6 +23,7 @@ void r1(Sub* (^f)()) { // expected-note{{passing argument to parameter 'f' here}
}
@protocol NSObject;
+@class NSObject;
void r2 (id<NSObject> (^f) (void)) {
id o = f();
@@ -155,3 +156,45 @@ void f() {
return NSOrderedSame;
}];
}
+
+// rdar://16739120
+@protocol P1 @end
+@protocol P2 @end
+
+void Test() {
+void (^aBlock)();
+id anId = aBlock; // OK
+
+id<P1,P2> anQualId = aBlock; // expected-error {{initializing 'id<P1,P2>' with an expression of incompatible type 'void (^)()'}}
+
+NSArray* anArray = aBlock; // expected-error {{initializing 'NSArray *' with an expression of incompatible type 'void (^)()'}}
+
+aBlock = anId; // OK
+
+id<P1,P2> anQualId1;
+aBlock = anQualId1; // expected-error {{assigning to 'void (^)()' from incompatible type 'id<P1,P2>'}}
+
+NSArray* anArray1;
+aBlock = anArray1; // expected-error {{assigning to 'void (^)()' from incompatible type 'NSArray *'}}
+}
+
+void Test2() {
+ void (^aBlock)();
+ id<NSObject> anQualId1 = aBlock; // Ok
+ id<NSObject, NSCopying> anQualId2 = aBlock; // Ok
+ id<NSObject, NSCopying, NSObject, NSCopying> anQualId3 = aBlock; // Ok
+ id <P1> anQualId4 = aBlock; // expected-error {{initializing 'id<P1>' with an expression of incompatible type 'void (^)()'}}
+ id<NSObject, P1, NSCopying> anQualId5 = aBlock; // expected-error {{initializing 'id<NSObject,P1,NSCopying>' with an expression of incompatible type 'void (^)()'}}
+ id<NSCopying> anQualId6 = aBlock; // Ok
+}
+
+void Test3() {
+ void (^aBlock)();
+ NSObject *NSO = aBlock; // Ok
+ NSObject<NSObject> *NSO1 = aBlock; // Ok
+ NSObject<NSObject, NSCopying> *NSO2 = aBlock; // Ok
+ NSObject<NSObject, NSCopying, NSObject, NSCopying> *NSO3 = aBlock; // Ok
+ NSObject <P1> *NSO4 = aBlock; // expected-error {{initializing 'NSObject<P1> *' with an expression of incompatible type 'void (^)()'}}
+ NSObject<NSObject, P1, NSCopying> *NSO5 = aBlock; // expected-error {{initializing 'NSObject<NSObject,P1,NSCopying> *' with an expression of incompatible type 'void (^)()'}}
+ NSObject<NSCopying> *NSO6 = aBlock; // Ok
+}