objective-c: Improve diagnostics and
provide 'fixit' hint when dictionary index
is not of proper type. // rdar://11062080
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153584 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaObjC/objc-container-subscripting-2.m b/test/SemaObjC/objc-container-subscripting-2.m
index 2564975..45f82e5 100644
--- a/test/SemaObjC/objc-container-subscripting-2.m
+++ b/test/SemaObjC/objc-container-subscripting-2.m
@@ -16,8 +16,8 @@
id func() {
NSMutableArray *array;
float f;
- array[f] = array; // expected-error {{expected method to write dictionary element not found on object of type 'NSMutableArray *'}}
- return array[3.14]; // expected-error {{expected method to read dictionary element not found on object of type 'NSMutableArray *'}}
+ array[f] = array; // expected-error {{indexing expression is invalid because subscript type 'float' is not an intergal or objective-C pointer type}}
+ return array[3.14]; // expected-error {{indexing expression is invalid because subscript type 'double' is not an intergal or objective-C pointer type}}
}
void test_unused() {
diff --git a/test/SemaObjC/objc-dictionary-literal.m b/test/SemaObjC/objc-dictionary-literal.m
new file mode 100644
index 0000000..2acbc39
--- /dev/null
+++ b/test/SemaObjC/objc-dictionary-literal.m
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://11062080
+
+@interface NSNumber
++ (NSNumber *)numberWithChar:(char)value;
++ (NSNumber *)numberWithInt:(int)value;
+@end
+
+@protocol NSCopying @end
+typedef unsigned long NSUInteger;
+typedef long NSInteger;
+
+@interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
+- (void)setObject:(id)object forKeyedSubscript:(id)key;
+@end
+
+@interface NSString<NSCopying>
+@end
+
+@interface NSArray
+- (id)objectAtIndexedSubscript:(NSInteger)index;
+- (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
+@end
+
+int main() {
+ NSDictionary *dict = @{ @"name":@666 };
+ dict[@"name"] = @666;
+
+ dict["name"] = @666; // expected-error {{indexing expression is invalid because subscript type 'char *' is not an objective-C pointer}}
+
+ return 0;
+}
+