Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | // rdar://11062080 |
Fariborz Jahanian | e1e33f8 | 2013-11-01 21:58:17 +0000 | [diff] [blame] | 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 |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 5 | |
Fariborz Jahanian | d13951f | 2014-09-10 20:55:31 +0000 | [diff] [blame] | 6 | #define nil ((void *)0) |
| 7 | |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 8 | void checkNSDictionaryUnavailableDiagnostic() { |
| 9 | id key; |
| 10 | id value; |
Alex Denisov | b7d8563 | 2015-07-24 05:09:40 +0000 | [diff] [blame] | 11 | id dict = @{ key : value }; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}} |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 12 | } |
| 13 | |
Alex Denisov | b7d8563 | 2015-07-24 05:09:40 +0000 | [diff] [blame] | 14 | @class NSDictionary; // expected-note {{forward declaration of class here}} |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 15 | |
| 16 | void checkNSDictionaryFDDiagnostic() { |
| 17 | id key; |
| 18 | id value; |
Alex Denisov | b7d8563 | 2015-07-24 05:09:40 +0000 | [diff] [blame] | 19 | id dic = @{ key : value }; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}} |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 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; |
Fariborz Jahanian | d13951f | 2014-09-10 20:55:31 +0000 | [diff] [blame] | 34 | - (id)objectForKeyedSubscript:(id)key; |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 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 | |
Fariborz Jahanian | a00a652 | 2014-09-10 22:12:13 +0000 | [diff] [blame] | 45 | void *pvoid; |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 46 | int main() { |
| 47 | NSDictionary *dict = @{ @"name":@666 }; |
| 48 | dict[@"name"] = @666; |
| 49 | |
Jordan Rose | 96c49686 | 2012-07-19 18:10:18 +0000 | [diff] [blame] | 50 | dict["name"] = @666; // expected-error {{indexing expression is invalid because subscript type 'char *' is not an Objective-C pointer}} |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 51 | |
Fariborz Jahanian | d13951f | 2014-09-10 20:55:31 +0000 | [diff] [blame] | 52 | // rdar://18254621 |
| 53 | [@{@"foo" : @"bar"} objectForKeyedSubscript:nil]; |
| 54 | (void)@{@"foo" : @"bar"}[nil]; |
Fariborz Jahanian | a00a652 | 2014-09-10 22:12:13 +0000 | [diff] [blame] | 55 | [@{@"foo" : @"bar"} objectForKeyedSubscript:pvoid]; |
| 56 | (void)@{@"foo" : @"bar"}[pvoid]; |
Fariborz Jahanian | d13951f | 2014-09-10 20:55:31 +0000 | [diff] [blame] | 57 | |
| 58 | [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"]; |
| 59 | @{@"foo" : @"bar"}[nil] = @"gorf"; |
Fariborz Jahanian | a00a652 | 2014-09-10 22:12:13 +0000 | [diff] [blame] | 60 | [@{@"foo" : @"bar"} setObject:pvoid forKeyedSubscript:@"gorf"]; |
| 61 | @{@"foo" : @"bar"}[pvoid] = @"gorf"; |
Fariborz Jahanian | d13951f | 2014-09-10 20:55:31 +0000 | [diff] [blame] | 62 | |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
Bruno Cardoso Lopes | 1383ddc | 2016-07-19 20:21:18 +0000 | [diff] [blame] | 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 | } |