| 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | // rdar://11062080 |
| 3 | // 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 |
| 5 | |
| 6 | #define nil ((void *)0) |
| 7 | |
| 8 | void checkNSDictionaryUnavailableDiagnostic() { |
| 9 | id key; |
| 10 | id value; |
| 11 | id dict = @{ key : value }; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}} |
| 12 | } |
| 13 | |
| 14 | @class NSDictionary; // expected-note {{forward declaration of class here}} |
| 15 | |
| 16 | void checkNSDictionaryFDDiagnostic() { |
| 17 | id key; |
| 18 | id value; |
| 19 | id dic = @{ key : value }; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}} |
| 20 | } |
| 21 | |
| 22 | @interface NSNumber |
| 23 | + (NSNumber *)numberWithChar:(char)value; |
| 24 | + (NSNumber *)numberWithInt:(int)value; |
| 25 | @end |
| 26 | |
| 27 | @protocol NSCopying @end |
| 28 | typedef unsigned long NSUInteger; |
| 29 | typedef 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; |
| 34 | - (id)objectForKeyedSubscript:(id)key; |
| 35 | @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 | |
| 45 | void *pvoid; |
| 46 | int main() { |
| 47 | NSDictionary *dict = @{ @"name":@666 }; |
| 48 | dict[@"name"] = @666; |
| 49 | |
| 50 | dict["name"] = @666; // expected-error {{indexing expression is invalid because subscript type 'char *' is not an Objective-C pointer}} |
| 51 | |
| 52 | // rdar://18254621 |
| 53 | [@{@"foo" : @"bar"} objectForKeyedSubscript:nil]; |
| 54 | (void)@{@"foo" : @"bar"}[nil]; |
| 55 | [@{@"foo" : @"bar"} objectForKeyedSubscript:pvoid]; |
| 56 | (void)@{@"foo" : @"bar"}[pvoid]; |
| 57 | |
| 58 | [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"]; |
| 59 | @{@"foo" : @"bar"}[nil] = @"gorf"; |
| 60 | [@{@"foo" : @"bar"} setObject:pvoid forKeyedSubscript:@"gorf"]; |
| 61 | @{@"foo" : @"bar"}[pvoid] = @"gorf"; |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | enum XXXYYYZZZType { XXXYYYZZZTypeAny }; // expected-note {{'XXXYYYZZZTypeAny' declared here}} |
| 67 | void 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 | } |
| 73 | |