blob: f9fd57f2dae2d7fe4e32af4d032d5745432475b6 [file] [log] [blame]
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// rdar://11062080
Fariborz Jahaniane1e33f82013-11-01 21:58:17 +00003// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-macosx10.9.0 -fobjc-runtime=macosx-fragile-10.9.0 -fobjc-subscripting-legacy-runtime -verify %s
4// rdar://15363492
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00005
Fariborz Jahaniand13951f2014-09-10 20:55:31 +00006#define nil ((void *)0)
7
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00008@interface NSNumber
9+ (NSNumber *)numberWithChar:(char)value;
10+ (NSNumber *)numberWithInt:(int)value;
11@end
12
13@protocol NSCopying @end
14typedef unsigned long NSUInteger;
15typedef long NSInteger;
16
17@interface NSDictionary
18+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
19- (void)setObject:(id)object forKeyedSubscript:(id)key;
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000020- (id)objectForKeyedSubscript:(id)key;
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000021@end
22
23@interface NSString<NSCopying>
24@end
25
26@interface NSArray
27- (id)objectAtIndexedSubscript:(NSInteger)index;
28- (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
29@end
30
Fariborz Jahaniana00a6522014-09-10 22:12:13 +000031void *pvoid;
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000032int main() {
33 NSDictionary *dict = @{ @"name":@666 };
34 dict[@"name"] = @666;
35
Jordan Rose96c496862012-07-19 18:10:18 +000036 dict["name"] = @666; // expected-error {{indexing expression is invalid because subscript type 'char *' is not an Objective-C pointer}}
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000037
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000038 // rdar://18254621
39 [@{@"foo" : @"bar"} objectForKeyedSubscript:nil];
40 (void)@{@"foo" : @"bar"}[nil];
Fariborz Jahaniana00a6522014-09-10 22:12:13 +000041 [@{@"foo" : @"bar"} objectForKeyedSubscript:pvoid];
42 (void)@{@"foo" : @"bar"}[pvoid];
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000043
44 [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"];
45 @{@"foo" : @"bar"}[nil] = @"gorf";
Fariborz Jahaniana00a6522014-09-10 22:12:13 +000046 [@{@"foo" : @"bar"} setObject:pvoid forKeyedSubscript:@"gorf"];
47 @{@"foo" : @"bar"}[pvoid] = @"gorf";
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000048
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000049 return 0;
50}
51