def err_undeclared_nsdictionary : Error<
"NSDictionary must be available to use Objective-C dictionary "
"literals">;
-def err_undeclared_arraywithobjects : Error<
- "declaration of %0 is missing in NSArray class">;
-def err_undeclared_dictwithobjects : Error<
- "declaration of %0 is missing in NSDictionary class">;
-def err_undeclared_nsnumber_method : Error<
- "declaration of %0 is missing in NSNumber class">;
+def err_undeclared_boxing_method : Error<
+ "declaration of %0 is missing in %1 class">;
def err_objc_literal_method_sig : Error<
"literal construction method %0 has incompatible signature">;
def note_objc_literal_method_param : Note<
}
if (!Method) {
- S.Diag(Loc, diag::err_undeclared_nsnumber_method) << Sel;
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ S.Diag(Loc, diag::err_undeclared_boxing_method)
+ << Sel << S.NSNumberDecl->getName();
return 0;
}
M->setMethodParams(Context, value, ArrayRef<SourceLocation>());
StringWithUTF8StringMethod = M;
}
- assert(StringWithUTF8StringMethod &&
- "StringWithUTF8StringMethod should not be NULL");
+
+ // FIXME: Copied from getNSNumberFactoryMethod().
+ if (!StringWithUTF8StringMethod) {
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ Diag(SR.getBegin(), diag::err_undeclared_boxing_method)
+ << stringWithUTF8String << NSStringDecl->getName();
+ return ExprError();
+ }
+
+ // Make sure the return type is reasonable.
+ QualType ResultType = StringWithUTF8StringMethod->getResultType();
+ if (!ResultType->isObjCObjectPointerType()) {
+ Diag(SR.getBegin(), diag::err_objc_literal_method_sig)
+ << stringWithUTF8String;
+ Diag(StringWithUTF8StringMethod->getLocation(),
+ diag::note_objc_literal_method_return)
+ << ResultType;
+ return ExprError();
+ }
}
BoxingMethod = StringWithUTF8StringMethod;
}
if (!ArrayWithObjectsMethod) {
- Diag(SR.getBegin(), diag::err_undeclared_arraywithobjects) << Sel;
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ Diag(SR.getBegin(), diag::err_undeclared_boxing_method)
+ << Sel << NSArrayDecl->getName();
return ExprError();
}
}
}
if (!DictionaryWithObjectsMethod) {
- Diag(SR.getBegin(), diag::err_undeclared_dictwithobjects) << Sel;
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ Diag(SR.getBegin(), diag::err_undeclared_boxing_method)
+ << Sel << NSDictionaryDecl->getName();
return ExprError();
}
}
+ (int)numberWithBool:(BOOL)value; // expected-note{{method returns unexpected type 'int' (should be an object type)}}
@end
+@interface NSString
++ (char)stringWithUTF8String:(const char *)value; // expected-note{{method returns unexpected type 'char' (should be an object type)}}
+@end
+
@interface NSArray
@end
(void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}}
id array = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}}
id dict = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}}
+ id str = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}}
}