blob: 718658e8c9b1020de77cfb183bbf7328a2009c2a [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
31int main() {
32 NSDictionary *dict = @{ @"name":@666 };
33 dict[@"name"] = @666;
34
Jordan Rose96c496862012-07-19 18:10:18 +000035 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 +000036
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000037 // rdar://18254621
38 [@{@"foo" : @"bar"} objectForKeyedSubscript:nil];
39 (void)@{@"foo" : @"bar"}[nil];
40
41 [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"];
42 @{@"foo" : @"bar"}[nil] = @"gorf";
43
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000044 return 0;
45}
46