diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-03-28 17:56:49 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-03-28 17:56:49 +0000 |
commit | a78eca20429e55b041bffcea1938cd0df07a6ebd (patch) | |
tree | f21a05e69d3519bbf9d801c786ffd87088dabe9e /lib/Sema/SemaPseudoObject.cpp | |
parent | 253955ca25c7e7049963b5db613c0cd15d66e4f8 (diff) |
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
Diffstat (limited to 'lib/Sema/SemaPseudoObject.cpp')
-rw-r--r-- | lib/Sema/SemaPseudoObject.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index effb372303..aebc0eb608 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -842,14 +842,20 @@ Sema::ObjCSubscriptKind // If we don't have a class type in C++, there's no way we can get an // expression of integral or enumeration type. const RecordType *RecordTy = T->getAs<RecordType>(); - if (!RecordTy) + if (!RecordTy && T->isObjCObjectPointerType()) // All other scalar cases are assumed to be dictionary indexing which // caller handles, with diagnostics if needed. return OS_Dictionary; - if (!getLangOpts().CPlusPlus || RecordTy->isIncompleteType()) { + if (!getLangOpts().CPlusPlus || + !RecordTy || RecordTy->isIncompleteType()) { // No indexing can be done. Issue diagnostics and quit. - Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion) - << FromE->getType(); + const Expr *IndexExpr = FromE->IgnoreParenImpCasts(); + if (isa<StringLiteral>(IndexExpr)) + Diag(FromE->getExprLoc(), diag::err_objc_subscript_pointer) + << T << FixItHint::CreateInsertion(FromE->getExprLoc(), "@"); + else + Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion) + << T; return OS_Error; } |