| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -Wselector-type-mismatch %s |
| 2 |
|
| 3 |
@protocol ProtoDirectFail |
| 4 |
@property(nonatomic, direct) int protoProperty; // expected-error {{'objc_direct' attribute cannot be applied to properties declared in an Objective-C protocol}} |
| 5 |
@end |
| 6 |
|
| 7 |
__attribute__((objc_root_class)) |
| 8 |
@interface Root |
| 9 |
@property(nonatomic, direct) int propertyWithNonDirectGetter; // expected-note {{previous declaration is here}} |
| 10 |
- (int)propertyWithNonDirectGetter; |
| 11 |
- (int)propertyWithNonDirectGetter2; |
| 12 |
- (int)propertyWithNonDirectGetterInParent; |
| 13 |
- (int)propertyWithNonDirectGetterInParent2; |
| 14 |
|
| 15 |
@property(nonatomic, readonly, direct) int getDirect_setDynamic; // expected-note {{previous declaration is here}} |
| 16 |
@property(nonatomic, readonly, direct) int getDirect_setDirect; // expected-note {{previous declaration is here}} |
| 17 |
@property(nonatomic, readonly, direct) int getDirect_setDirectMembers; // expected-note {{previous declaration is here}} |
| 18 |
|
| 19 |
@property(nonatomic, readonly) int getDynamic_setDirect; |
| 20 |
@property(nonatomic, readonly) int getDynamic_setDirectMembers; |
| 21 |
|
| 22 |
@property(nonatomic, readonly) int dynamicProperty; |
| 23 |
@property(nonatomic, readonly) int synthDynamicProperty; |
| 24 |
|
| 25 |
@property(nonatomic, readonly, direct) int directProperty; // expected-note {{previous declaration is here}} |
| 26 |
@property(nonatomic, readonly, direct) int synthDirectProperty; // expected-note {{previous declaration is here}} |
| 27 |
@end |
| 28 |
|
| 29 |
__attribute__((objc_direct_members)) |
| 30 |
@interface |
| 31 |
Root() |
| 32 |
@property(nonatomic) int propertyWithNonDirectGetter2; // expected-note {{previous declaration is here}} |
| 33 |
|
| 34 |
@property(nonatomic, readwrite) int getDirect_setDirectMembers; // expected-note {{previous declaration is here}} |
| 35 |
@property(nonatomic, readwrite) int getDynamic_setDirectMembers; // expected-note {{previous declaration is here}} |
| 36 |
@end |
| 37 |
|
| 38 |
@interface Root () |
| 39 |
@property(nonatomic, readwrite) int getDirect_setDynamic; |
| 40 |
@property(nonatomic, readwrite, direct) int getDirect_setDirect; // expected-note {{previous declaration is here}} |
| 41 |
|
| 42 |
@property(nonatomic, readwrite, direct) int getDynamic_setDirect; // expected-note {{previous declaration is here}} |
| 43 |
@end |
| 44 |
|
| 45 |
@interface Sub : Root |
| 46 |
@property(nonatomic, direct) int propertyWithNonDirectGetterInParent; // expected-note {{previous declaration is here}} |
| 47 |
|
| 48 |
- (int)propertyWithNonDirectGetter; // no error: legal override |
| 49 |
- (int)propertyWithNonDirectGetter2; // no error: legal override |
| 50 |
- (int)propertyWithNonDirectGetterInParent; // no error: legal override |
| 51 |
- (int)propertyWithNonDirectGetterInParent2; // no error: legal override |
| 52 |
|
| 53 |
@end |
| 54 |
|
| 55 |
__attribute__((objc_direct_members)) |
| 56 |
@interface Sub () |
| 57 |
@property(nonatomic) int propertyWithNonDirectGetterInParent2; // expected-note {{previous declaration is here}} |
| 58 |
@end |
| 59 |
|
| 60 |
// make sure that the `directness` of methods stuck, |
| 61 |
// by observing errors trying to override the setter |
| 62 |
@interface SubWitness : Sub |
| 63 |
|
| 64 |
- (int)setPropertyWithNonDirectGetter:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 65 |
- (int)setPropertyWithNonDirectGetter2:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 66 |
- (int)setPropertyWithNonDirectGetterInParent:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 67 |
- (int)setPropertyWithNonDirectGetterInParent2:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 68 |
|
| 69 |
- (int)getDirect_setDynamic; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 70 |
- (int)setGetDirect_setDynamic:(int)value; |
| 71 |
- (int)getDirect_setDirect; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 72 |
- (int)setGetDirect_setDirect:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 73 |
- (int)getDirect_setDirectMembers; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 74 |
- (int)setGetDirect_setDirectMembers:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 75 |
|
| 76 |
- (int)getDynamic_setDirect; |
| 77 |
- (int)setGetDynamic_setDirect:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 78 |
- (int)getDynamic_setDirectMembers; |
| 79 |
- (int)setGetDynamic_setDirectMembers:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 80 |
@end |
| 81 |
|
| 82 |
__attribute__((objc_direct_members)) |
| 83 |
@implementation Root |
| 84 |
- (int)propertyWithNonDirectGetter { |
| 85 |
return 42; |
| 86 |
} |
| 87 |
- (int)propertyWithNonDirectGetter2 { |
| 88 |
return 42; |
| 89 |
} |
| 90 |
- (int)propertyWithNonDirectGetterInParent { |
| 91 |
return 42; |
| 92 |
} |
| 93 |
- (int)propertyWithNonDirectGetterInParent2 { |
| 94 |
return 42; |
| 95 |
} |
| 96 |
|
| 97 |
- (int)dynamicProperty { |
| 98 |
return 42; |
| 99 |
} |
| 100 |
- (int)directProperty { |
| 101 |
return 42; |
| 102 |
} |
| 103 |
@end |
| 104 |
|
| 105 |
@implementation Sub |
| 106 |
- (int)propertyWithNonDirectGetter { |
| 107 |
return 42; |
| 108 |
} |
| 109 |
- (int)propertyWithNonDirectGetter2 { |
| 110 |
return 42; |
| 111 |
} |
| 112 |
|
| 113 |
- (int)dynamicProperty { |
| 114 |
return 42; |
| 115 |
} |
| 116 |
- (int)synthDynamicProperty { |
| 117 |
return 42; |
| 118 |
} |
| 119 |
|
| 120 |
- (int)directProperty { // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 121 |
return 42; |
| 122 |
} |
| 123 |
- (int)synthDirectProperty { // expected-error {{cannot override a method that is declared direct by a superclass}} |
| 124 |
return 42; |
| 125 |
} |
| 126 |
@end |