blob: ce301a0c73afffbeb79c8397e85c32ffa46520f4 [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
Alex Denisov10c45462015-02-17 06:43:10 +00008void checkNSDictionaryUnavailableDiagnostic() {
9 id key;
10 id value;
Alex Denisovb7d85632015-07-24 05:09:40 +000011 id dict = @{ key : value }; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}}
Alex Denisov10c45462015-02-17 06:43:10 +000012}
13
Alex Denisovb7d85632015-07-24 05:09:40 +000014@class NSDictionary; // expected-note {{forward declaration of class here}}
Alex Denisov10c45462015-02-17 06:43:10 +000015
16void checkNSDictionaryFDDiagnostic() {
17 id key;
18 id value;
Alex Denisovb7d85632015-07-24 05:09:40 +000019 id dic = @{ key : value }; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}}
Alex Denisov10c45462015-02-17 06:43:10 +000020}
21
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000022@interface NSNumber
23+ (NSNumber *)numberWithChar:(char)value;
24+ (NSNumber *)numberWithInt:(int)value;
25@end
26
27@protocol NSCopying @end
28typedef unsigned long NSUInteger;
29typedef long NSInteger;
30
31@interface NSDictionary
32+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
33- (void)setObject:(id)object forKeyedSubscript:(id)key;
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000034- (id)objectForKeyedSubscript:(id)key;
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000035@end
36
37@interface NSString<NSCopying>
38@end
39
40@interface NSArray
41- (id)objectAtIndexedSubscript:(NSInteger)index;
42- (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
43@end
44
Fariborz Jahaniana00a6522014-09-10 22:12:13 +000045void *pvoid;
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000046int main() {
47 NSDictionary *dict = @{ @"name":@666 };
48 dict[@"name"] = @666;
49
Jordan Rose96c496862012-07-19 18:10:18 +000050 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 +000051
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000052 // rdar://18254621
53 [@{@"foo" : @"bar"} objectForKeyedSubscript:nil];
54 (void)@{@"foo" : @"bar"}[nil];
Fariborz Jahaniana00a6522014-09-10 22:12:13 +000055 [@{@"foo" : @"bar"} objectForKeyedSubscript:pvoid];
56 (void)@{@"foo" : @"bar"}[pvoid];
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000057
58 [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"];
59 @{@"foo" : @"bar"}[nil] = @"gorf";
Fariborz Jahaniana00a6522014-09-10 22:12:13 +000060 [@{@"foo" : @"bar"} setObject:pvoid forKeyedSubscript:@"gorf"];
61 @{@"foo" : @"bar"}[pvoid] = @"gorf";
Fariborz Jahaniand13951f2014-09-10 20:55:31 +000062
Fariborz Jahanianba0afde2012-03-28 17:56:49 +000063 return 0;
64}
65
Bruno Cardoso Lopes1383ddc2016-07-19 20:21:18 +000066enum XXXYYYZZZType { XXXYYYZZZTypeAny }; // expected-note {{'XXXYYYZZZTypeAny' declared here}}
67void foo() {
68 NSDictionary *d = @{
69 @"A" : @(XXXYYYZZZTypeA), // expected-error {{use of undeclared identifier 'XXXYYYZZZTypeA'; did you mean 'XXXYYYZZZTypeAny'}}
70 @"F" : @(XXXYYYZZZTypeSomethingSomething), // expected-error {{use of undeclared identifier 'XXXYYYZZZTypeSomethingSomething'}}
71 };
72}