From 7d9ba1ec64699c2203f1624de6bcb99803ce311d Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 10 Dec 2013 19:22:41 +0000 Subject: [PATCH] Improve on an objc_bridge_related diagnostic. // rdar://15499111 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196950 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 5 +++-- lib/Sema/SemaExprObjC.cpp | 12 ++++++------ test/SemaObjC/arc-objcbridge-related-attribute.m | 10 +++++----- test/SemaObjC/objcbridge-related-attribute.m | 10 +++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 0823b5dcd6..23339fe7ef 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2472,8 +2472,9 @@ def err_objc_bridged_related_invalid_class : Error< def err_objc_bridged_related_invalid_class_name : Error< "%0 must be name of an Objective-C class to be able to convert %1 to %2">; def err_objc_bridged_related_unknown_method : Error< - "you can't convert %0 to %1, without using an existing " - "%select{class|instance}2 method for this conversion">; + "%0 cannot be directly converted to %1; specify " + "%select{a class|an instance}2 method in objc_bridge_related attribute" + " for this conversion">; def err_objc_bridged_related_known_method : Error< "%0 must be explicitly converted to %1; use %select{%objcclass2|%objcinstance2}3 " "method for this conversion">; diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index c0f65ea84d..960700bd5c 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -3405,7 +3405,7 @@ bool Sema::checkObjCBridgeRelatedComponents(SourceLocation Loc, ClassMethod = RelatedClass->lookupMethod(Sel, false); if (!ClassMethod) { Diag(Loc, diag::err_objc_bridged_related_known_method) - << SrcType << DestType << Sel << 0; + << SrcType << DestType << Sel << false; Diag(TDNDecl->getLocStart(), diag::note_declared_at); return false; } @@ -3417,7 +3417,7 @@ bool Sema::checkObjCBridgeRelatedComponents(SourceLocation Loc, InstanceMethod = RelatedClass->lookupMethod(Sel, true); if (!InstanceMethod) { Diag(Loc, diag::err_objc_bridged_related_known_method) - << SrcType << DestType << Sel << 1; + << SrcType << DestType << Sel << true; Diag(TDNDecl->getLocStart(), diag::note_declared_at); return false; } @@ -3454,13 +3454,13 @@ Sema::CheckObjCBridgeRelatedConversions(SourceLocation Loc, SourceLocation SrcExprEndLoc = PP.getLocForEndOfToken(SrcExpr->getLocEnd()); // Provide a fixit: [RelatedClass ClassMethod SrcExpr] Diag(Loc, diag::err_objc_bridged_related_known_method) - << SrcType << DestType << ClassMethod->getSelector() << 0 + << SrcType << DestType << ClassMethod->getSelector() << false << FixItHint::CreateInsertion(SrcExpr->getLocStart(), ExpressionString) << FixItHint::CreateInsertion(SrcExprEndLoc, "]"); } else Diag(Loc, diag::err_objc_bridged_related_unknown_method) - << SrcType << DestType << 0; + << SrcType << DestType << false; Diag(RelatedClass->getLocStart(), diag::note_declared_at); Diag(TDNDecl->getLocStart(), diag::note_declared_at); } @@ -3474,13 +3474,13 @@ Sema::CheckObjCBridgeRelatedConversions(SourceLocation Loc, SourceLocation SrcExprEndLoc = PP.getLocForEndOfToken(SrcExpr->getLocEnd()); Diag(Loc, diag::err_objc_bridged_related_known_method) - << SrcType << DestType << InstanceMethod->getSelector() << 1 + << SrcType << DestType << InstanceMethod->getSelector() << true << FixItHint::CreateInsertion(SrcExpr->getLocStart(), "[") << FixItHint::CreateInsertion(SrcExprEndLoc, ExpressionString); } else Diag(Loc, diag::err_objc_bridged_related_unknown_method) - << SrcType << DestType << 1; + << SrcType << DestType << true; Diag(RelatedClass->getLocStart(), diag::note_declared_at); Diag(TDNDecl->getLocStart(), diag::note_declared_at); } diff --git a/test/SemaObjC/arc-objcbridge-related-attribute.m b/test/SemaObjC/arc-objcbridge-related-attribute.m index d78ee4dc4e..d92c636da8 100644 --- a/test/SemaObjC/arc-objcbridge-related-attribute.m +++ b/test/SemaObjC/arc-objcbridge-related-attribute.m @@ -25,9 +25,9 @@ NSColor * Test1(NSTextField *textField, CGColorRef newColor) { } NSColor * Test2(NSTextField *textField, CGColorRef1 newColor) { - foo(newColor); // expected-error {{you can't convert 'CGColorRef1' (aka 'struct CGColor1 *') to 'NSColor *', without using an existing class method for this conversion}} - textField.backgroundColor = newColor; // expected-error {{you can't convert 'CGColorRef1' (aka 'struct CGColor1 *') to 'NSColor *__strong', without using an existing class method for this conversion}} - return newColor; // expected-error {{you can't convert 'CGColorRef1' (aka 'struct CGColor1 *') to 'NSColor *', without using an existing class method for this conversion}} + foo(newColor); // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') cannot be directly converted to 'NSColor *'; specify a class method in objc_bridge_related attribute for this conversion}} + textField.backgroundColor = newColor; // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') cannot be directly converted to 'NSColor *__strong'; specify a class method in objc_bridge_related attribute for this conversion}} + return newColor; // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') cannot be directly converted to 'NSColor *'; specify a class method in objc_bridge_related attribute for this conversion}} } CGColorRef Test3(NSTextField *textField, CGColorRef newColor) { @@ -36,6 +36,6 @@ CGColorRef Test3(NSTextField *textField, CGColorRef newColor) { } CGColorRef2 Test4(NSTextField *textField, CGColorRef2 newColor) { - newColor = textField.backgroundColor; // expected-error {{you can't convert 'NSColor *' to 'CGColorRef2' (aka 'struct CGColor2 *'), without using an existing instance method for this conversion}} - return textField.backgroundColor; // expected-error {{you can't convert 'NSColor *' to 'CGColorRef2' (aka 'struct CGColor2 *'), without using an existing instance method for this conversion}} + newColor = textField.backgroundColor; // expected-error {{'NSColor *' cannot be directly converted to 'CGColorRef2' (aka 'struct CGColor2 *'); specify an instance method in objc_bridge_related attribute for this conversion}} + return textField.backgroundColor; // expected-error {{'NSColor *' cannot be directly converted to 'CGColorRef2' (aka 'struct CGColor2 *'); specify an instance method in objc_bridge_related attribute for this conversion}} } diff --git a/test/SemaObjC/objcbridge-related-attribute.m b/test/SemaObjC/objcbridge-related-attribute.m index aa6db6f96e..a6d5e2eb97 100644 --- a/test/SemaObjC/objcbridge-related-attribute.m +++ b/test/SemaObjC/objcbridge-related-attribute.m @@ -25,9 +25,9 @@ NSColor * Test1(NSTextField *textField, CGColorRef newColor) { } NSColor * Test2(NSTextField *textField, CGColorRef1 newColor) { - foo(newColor); // expected-error {{you can't convert 'CGColorRef1' (aka 'struct CGColor1 *') to 'NSColor *', without using an existing class method for this conversion}} - textField.backgroundColor = newColor; // expected-error {{you can't convert 'CGColorRef1' (aka 'struct CGColor1 *') to 'NSColor *', without using an existing class method for this conversion}} - return newColor; // expected-error {{you can't convert 'CGColorRef1' (aka 'struct CGColor1 *') to 'NSColor *', without using an existing class method for this conversion}} + foo(newColor); // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') cannot be directly converted to 'NSColor *'; specify a class method in objc_bridge_related attribute for this conversion}} + textField.backgroundColor = newColor; // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') cannot be directly converted to 'NSColor *'; specify a class method in objc_bridge_related attribute for this conversion}} + return newColor; // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') cannot be directly converted to 'NSColor *'; specify a class method in objc_bridge_related attribute for this conversion}} } CGColorRef Test3(NSTextField *textField, CGColorRef newColor) { @@ -36,6 +36,6 @@ CGColorRef Test3(NSTextField *textField, CGColorRef newColor) { } CGColorRef2 Test4(NSTextField *textField, CGColorRef2 newColor) { - newColor = textField.backgroundColor; // expected-error {{you can't convert 'NSColor *' to 'CGColorRef2' (aka 'struct CGColor2 *'), without using an existing instance method for this conversion}} - return textField.backgroundColor; // expected-error {{you can't convert 'NSColor *' to 'CGColorRef2' (aka 'struct CGColor2 *'), without using an existing instance method for this conversion}} + newColor = textField.backgroundColor; // expected-error {{'NSColor *' cannot be directly converted to 'CGColorRef2' (aka 'struct CGColor2 *'); specify an instance method in objc_bridge_related attribute for this conversion}} + return textField.backgroundColor; // expected-error {{'NSColor *' cannot be directly converted to 'CGColorRef2' (aka 'struct CGColor2 *'); specify an instance method in objc_bridge_related attribute for this conversion}} } -- 2.40.0