@protocol NSObject
@end
__attribute__((objc_root_class))
@interface NSObject <NSObject>
+ (instancetype)alloc;
- (instancetype)init;
@end
@protocol NSCopying
@end
@interface NSString : NSObject <NSCopying>
@end
@interface NSMutableString : NSString
@end
@interface NSNumber : NSObject <NSCopying>
@end
@interface NSArray<T> : NSObject <NSCopying> {
@public
T *data; }
- (T)objectAtIndexedSubscript:(int)index;
+ (NSArray<T> *)array;
+ (void)setArray:(NSArray <T> *)array;
@property (copy,nonatomic) T lastObject;
@end
@interface NSMutableArray<T> : NSArray<T>
-(instancetype)initWithArray:(NSArray<T> *)array; - (void)setObject:(T)object atIndexedSubscript:(int)index; @end
@interface NSStringArray : NSArray<NSString *>
@end
@interface NSSet<T> : NSObject <NSCopying>
- (T)firstObject;
@property (nonatomic, copy) NSArray<T> *allObjects;
@end
@interface NSMutableSet<U : id<NSCopying>> : NSSet<U>
- (void)addObject:(U)object; @end
@interface Widget : NSObject <NSCopying>
@end
@interface WidgetSet : NSMutableSet<Widget *>
@end
@interface MutableSetOfArrays<T> : NSMutableSet<NSArray<T>*>
@end
@interface UntypedMutableSet : NSMutableSet
@end
@interface Window : NSObject
@end
@interface NSDictionary<K, V> : NSObject <NSCopying>
- (V)objectForKeyedSubscript:(K)key; @end
@interface NSMutableDictionary<K : id<NSCopying>, V> : NSDictionary<K, V>
- (void)setObject:(V)object forKeyedSubscript:(K)key;
@property (strong) K someRandomKey;
@end
@interface WindowArray : NSArray<Window *>
@end
@interface NSSet<T> (Searching)
- (T)findObject:(T)object;
@end
@interface NSView : NSObject
@end
@interface NSControl : NSView
- (void)toggle;
@end
@interface NSViewController<ViewType : NSView *> : NSObject
@property (nonatomic,retain) ViewType view;
@end
@interface TypedefTypeParam<T> : NSObject
typedef T AliasT;
- (void)test:(AliasT)object;
@end
typedef NSControl * _Nonnull Nonnull_NSControl;
@interface NSNullableTest<ViewType : NSView *> : NSObject
- (ViewType)view;
- (nullable ViewType)maybeView;
@end
@interface NSNullableTest2<ViewType : NSView * _Nullable> : NSObject @end
void test_nullability(void) {
NSControl * _Nonnull nonnull_NSControl;
NSNullableTest<NSControl *> *unspecifiedControl;
nonnull_NSControl = [unspecifiedControl view];
nonnull_NSControl = [unspecifiedControl maybeView];
NSNullableTest<Nonnull_NSControl> *nonnullControl;
nonnull_NSControl = [nonnullControl view];
nonnull_NSControl = [nonnullControl maybeView];
NSNullableTest<NSControl * _Nonnull> *nonnullControl2; }
void test_message_send_result(
NSSet<NSString *> *stringSet,
NSMutableSet<NSString *> *mutStringSet,
WidgetSet *widgetSet,
UntypedMutableSet *untypedMutSet,
MutableSetOfArrays<NSString *> *mutStringArraySet,
NSSet *set,
NSMutableSet *mutSet,
MutableSetOfArrays *mutArraySet,
NSArray<NSString *> *stringArray,
NSArray<__kindof NSString *> *kindofStringArray,
void (^block)(void)) {
int *ip;
ip = [stringSet firstObject]; ip = [mutStringSet firstObject]; ip = [widgetSet firstObject]; ip = [untypedMutSet firstObject]; ip = [mutStringArraySet firstObject]; ip = [set firstObject]; ip = [mutSet firstObject]; ip = [mutArraySet firstObject]; ip = [block firstObject];
ip = [stringSet findObject:@"blah"];
ip = [NSSet<NSString *> alloc]; ip = [NSSet alloc]; ip = [MutableSetOfArrays<NSString *> alloc]; ip = [MutableSetOfArrays alloc]; ip = [NSArray<NSString *> array]; ip = [NSArray<NSString *><NSCopying> array];
ip = [[NSMutableArray<NSString *> alloc] init];
[[NSMutableArray alloc] initWithArray: stringArray]; [[NSMutableArray<NSString *> alloc] initWithArray: stringArray]; [[NSMutableArray<NSNumber *> alloc] initWithArray: stringArray];
ip = [[[NSViewController alloc] init] view]; [[[[NSViewController alloc] init] view] toggle];
NSMutableString *mutStr = kindofStringArray[0];
NSNumber *number = kindofStringArray[0]; }
void test_message_send_param(
NSMutableSet<NSString *> *mutStringSet,
WidgetSet *widgetSet,
UntypedMutableSet *untypedMutSet,
MutableSetOfArrays<NSString *> *mutStringArraySet,
NSMutableSet *mutSet,
MutableSetOfArrays *mutArraySet,
TypedefTypeParam<NSString *> *typedefTypeParam,
void (^block)(void)) {
Window *window;
[mutStringSet addObject: window]; [widgetSet addObject: window]; [untypedMutSet addObject: window]; [mutStringArraySet addObject: window]; [mutSet addObject: window]; [mutArraySet addObject: window]; [typedefTypeParam test: window]; [block addObject: window]; }
void test_property_read(
NSSet<NSString *> *stringSet,
NSMutableSet<NSString *> *mutStringSet,
WidgetSet *widgetSet,
UntypedMutableSet *untypedMutSet,
MutableSetOfArrays<NSString *> *mutStringArraySet,
NSSet *set,
NSMutableSet *mutSet,
MutableSetOfArrays *mutArraySet,
NSMutableDictionary *mutDict) {
int *ip;
ip = stringSet.allObjects; ip = mutStringSet.allObjects; ip = widgetSet.allObjects; ip = untypedMutSet.allObjects; ip = mutStringArraySet.allObjects; ip = set.allObjects; ip = mutSet.allObjects; ip = mutArraySet.allObjects;
ip = mutDict.someRandomKey;
ip = [[NSViewController alloc] init].view; }
void test_property_write(
NSMutableSet<NSString *> *mutStringSet,
WidgetSet *widgetSet,
UntypedMutableSet *untypedMutSet,
MutableSetOfArrays<NSString *> *mutStringArraySet,
NSMutableSet *mutSet,
MutableSetOfArrays *mutArraySet,
NSMutableDictionary *mutDict) {
int *ip;
mutStringSet.allObjects = ip; widgetSet.allObjects = ip; untypedMutSet.allObjects = ip; mutStringArraySet.allObjects = ip; mutSet.allObjects = ip; mutArraySet.allObjects = ip;
mutDict.someRandomKey = ip; }
void test_subscripting(
NSArray<NSString *> *stringArray,
NSMutableArray<NSString *> *mutStringArray,
NSArray *array,
NSMutableArray *mutArray,
NSDictionary<NSString *, Widget *> *stringWidgetDict,
NSMutableDictionary<NSString *, Widget *> *mutStringWidgetDict,
NSDictionary *dict,
NSMutableDictionary *mutDict) {
int *ip;
NSString *string;
Widget *widget;
Window *window;
ip = stringArray[0];
ip = mutStringArray[0]; mutStringArray[0] = ip;
ip = array[0];
ip = mutArray[0]; mutArray[0] = ip;
ip = stringWidgetDict[string]; widget = stringWidgetDict[widget];
ip = mutStringWidgetDict[string]; widget = mutStringWidgetDict[widget]; mutStringWidgetDict[string] = ip; mutStringWidgetDict[widget] = widget;
ip = dict[string];
ip = mutDict[string]; mutDict[string] = ip;
widget = mutDict[window];
mutDict[window] = widget; }
void test_instance_variable(NSArray<NSString *> *stringArray,
NSArray *array) {
int *ip;
ip = stringArray->data; ip = array->data; }
@implementation WindowArray
- (void)testInstanceVariable {
int *ip;
ip = data; }
@end
void test_implicit_conversions(NSArray<NSString *> *stringArray,
NSArray<NSNumber *> *numberArray,
NSMutableArray<NSString *> *mutStringArray,
NSArray *array,
NSMutableArray *mutArray) {
array = stringArray;
stringArray = array;
stringArray = numberArray;
stringArray = mutStringArray;
numberArray = mutStringArray;
stringArray = mutArray;
array = mutStringArray;
}
@interface NSCovariant1<__covariant T>
@end
@interface NSContravariant1<__contravariant T>
@end
void test_variance(NSCovariant1<NSString *> *covariant1,
NSCovariant1<NSMutableString *> *covariant2,
NSCovariant1<NSString *(^)(void)> *covariant3,
NSCovariant1<NSMutableString *(^)(void)> *covariant4,
NSCovariant1<id> *covariant5,
NSCovariant1<id<NSCopying>> *covariant6,
NSContravariant1<NSString *> *contravariant1,
NSContravariant1<NSMutableString *> *contravariant2) {
covariant1 = covariant2; covariant2 = covariant1;
covariant3 = covariant4; covariant4 = covariant3;
covariant5 = covariant1; covariant1 = covariant5;
covariant5 = covariant3; covariant3 = covariant5;
contravariant1 = contravariant2; contravariant2 = contravariant1; }
void test_ternary_operator(NSArray<NSString *> *stringArray,
NSArray<NSNumber *> *numberArray,
NSMutableArray<NSString *> *mutStringArray,
NSStringArray *stringArray2,
NSArray *array,
NSMutableArray *mutArray,
int cond) {
int *ip;
id object;
ip = cond ? stringArray : mutStringArray; ip = cond ? mutStringArray : stringArray;
ip = cond ? stringArray2 : mutStringArray; ip = cond ? mutStringArray : stringArray2;
ip = cond ? stringArray : mutArray;
ip = cond ? stringArray2 : mutArray;
ip = cond ? mutArray : stringArray;
ip = cond ? mutArray : stringArray2;
object = cond ? stringArray : numberArray; }
@implementation NSStringArray
- (void)useSuperMethod {
int *ip;
ip = super.lastObject; super.lastObject = ip; ip = [super objectAtIndexedSubscript:0]; }
+ (void)useSuperMethod {
int *ip;
ip = super.array; super.array = ip; ip = [super array]; }
@end
typedef NSArray<NSObject> ArrayOfNSObjectWarning;
@interface MyMutableDictionary<KeyType, ObjectType> : NSObject
- (void)setObject:(ObjectType)obj forKeyedSubscript:(KeyType <NSCopying>)key; @end
void bar(MyMutableDictionary<NSString *, NSString *> *stringsByString,
NSNumber *n1, NSNumber *n2) {
stringsByString[n1] = n2; }
@interface MyTest<K, V> : NSObject <NSCopying>
- (V)test:(K)key;
- (V)test2:(K)key; - (void)mapUsingBlock:(id (^)(V))block;
- (void)mapUsingBlock2:(id (^)(V))block; @end
@implementation MyTest
- (id)test:(id)key {
return key;
}
- (int)test2:(id)key{ return 0;
}
- (void)mapUsingBlock:(id (^)(id))block {
}
- (void)mapUsingBlock2:(id)block { }
@end
@interface ParameterizedContainer<T : id<NSCopying>>
- (ParameterizedContainer<T> *)inInterface;
@end
@interface ParameterizedContainer<T> (Cat)
- (ParameterizedContainer<T> *)inCategory;
@end
@interface ParameterizedContainer<U> ()
- (ParameterizedContainer<U> *)inExtension;
@end