r184086 - Objective-C [qoi]: Provide fixit hint when message with typo
Rafael EspĂndola
rafael.espindola at gmail.com
Mon Jun 17 10:28:39 PDT 2013
This test is failing for me:
error: 'warning' diagnostics expected but not seen:
File /home/espindola/llvm/clang/test/SemaObjC/call-super-2.m Line
71: instance method 'instance_func0' not found (return type defaults
to 'id'); did you mean 'instance_func3'?
error: 'warning' diagnostics seen but not expected:
File /home/espindola/llvm/clang/test/SemaObjC/call-super-2.m Line
71: instance method 'instance_func0' not found (return type defaults
to 'id'); did you mean 'instance_func1'?
2 errors generated.
On 17 June 2013 13:10, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Mon Jun 17 12:10:54 2013
> New Revision: 184086
>
> URL: http://llvm.org/viewvc/llvm-project?rev=184086&view=rev
> Log:
> Objective-C [qoi]: Provide fixit hint when message with typo
> is sent to a receiver object. This is wip. // rdar://7853549
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> cfe/trunk/lib/Sema/SemaExprObjC.cpp
> cfe/trunk/test/FixIt/selector-fixit.m
> cfe/trunk/test/SemaObjC/call-super-2.m
> cfe/trunk/test/SemaObjC/protocol-id-test-1.m
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 17 12:10:54 2013
> @@ -4601,6 +4601,9 @@ def warn_instance_method_on_class_found
> def warn_inst_method_not_found : Warning<
> "instance method %objcinstance0 not found (return type defaults to 'id')">,
> InGroup<MethodAccess>;
> +def warn_method_not_found_with_typo : Warning<
> + "%select{instance|class}0 method %1 not found (return type defaults to 'id')"
> + "; did you mean %2?">, InGroup<MethodAccess>;
> def error_no_super_class_message : Error<
> "no @interface declaration found in class messaging of %0">;
> def error_root_class_cannot_use_super : Error<
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Mon Jun 17 12:10:54 2013
> @@ -2672,7 +2672,8 @@ public:
> warn, /*instance*/false);
> }
>
> - const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel);
> + const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel,
> + QualType ObjectType=QualType());
>
> /// DiagnoseMismatchedMethodsInGlobalPool - This routine goes through list of
> /// methods in global pool and issues diagnostic on identical selectors which
>
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Jun 17 12:10:54 2013
> @@ -2295,8 +2295,18 @@ HelperSelectorsForTypoCorrection(
> }
> }
>
> +static bool HelperIsMethodInObjCType(Sema &S, Selector Sel,
> + QualType ObjectType) {
> + if (ObjectType.isNull())
> + return true;
> + if (S.LookupMethodInObjectType(Sel, ObjectType, true/*Instance method*/))
> + return true;
> + return S.LookupMethodInObjectType(Sel, ObjectType, false/*Class method*/) != 0;
> +}
> +
> const ObjCMethodDecl *
> -Sema::SelectorsForTypoCorrection(Selector Sel) {
> +Sema::SelectorsForTypoCorrection(Selector Sel,
> + QualType ObjectType) {
> unsigned NumArgs = Sel.getNumArgs();
> SmallVector<const ObjCMethodDecl *, 8> Methods;
>
> @@ -2305,12 +2315,14 @@ Sema::SelectorsForTypoCorrection(Selecto
> // instance methods
> for (ObjCMethodList *M = &b->second.first; M; M=M->getNext())
> if (M->Method &&
> - (M->Method->getSelector().getNumArgs() == NumArgs))
> + (M->Method->getSelector().getNumArgs() == NumArgs) &&
> + HelperIsMethodInObjCType(*this, M->Method->getSelector(), ObjectType))
> Methods.push_back(M->Method);
> // class methods
> for (ObjCMethodList *M = &b->second.second; M; M=M->getNext())
> if (M->Method &&
> - (M->Method->getSelector().getNumArgs() == NumArgs))
> + (M->Method->getSelector().getNumArgs() == NumArgs) &&
> + HelperIsMethodInObjCType(*this, M->Method->getSelector(), ObjectType))
> Methods.push_back(M->Method);
> }
>
>
> Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Jun 17 12:10:54 2013
> @@ -1232,8 +1232,22 @@ bool Sema::CheckMessageArgumentTypes(Qua
> DiagID = isClassMessage ? diag::warn_class_method_not_found
> : diag::warn_inst_method_not_found;
> if (!getLangOpts().DebuggerSupport) {
> - Diag(SelLoc, DiagID)
> - << Sel << isClassMessage << SourceRange(SelectorLocs.front(),
> + const ObjCMethodDecl *OMD = 0;
> + if (const ObjCObjectPointerType *ObjCPtr =
> + ReceiverType->getAsObjCInterfacePointerType()) {
> + QualType ObjectType = QualType(ObjCPtr->getInterfaceType(), 0);
> + OMD = SelectorsForTypoCorrection(Sel, ObjectType);
> + }
> + if (OMD) {
> + Selector MatchedSel = OMD->getSelector();
> + SourceRange SelectorRange(SelectorLocs.front(), SelectorLocs.back());
> + Diag(SelLoc, diag::warn_method_not_found_with_typo)
> + << isClassMessage << Sel << MatchedSel
> + << FixItHint::CreateReplacement(SelectorRange, MatchedSel.getAsString());
> + }
> + else
> + Diag(SelLoc, DiagID)
> + << Sel << isClassMessage << SourceRange(SelectorLocs.front(),
> SelectorLocs.back());
> // Find the class to which we are sending this message.
> if (ReceiverType->isObjCObjectPointerType()) {
>
> Modified: cfe/trunk/test/FixIt/selector-fixit.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/selector-fixit.m?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/test/FixIt/selector-fixit.m (original)
> +++ cfe/trunk/test/FixIt/selector-fixit.m Mon Jun 17 12:10:54 2013
> @@ -28,3 +28,13 @@
> }
>
> @end
> +
> +// rdar://7853549
> + at interface rdar7853549 : NSObject
> +- (int) bounds;
> + at end
> +
> + at implementation rdar7853549
> +- (int) bounds { return 0; }
> +- (void)PrivateMeth { int bounds = [self bonds]; }
> + at end
>
> Modified: cfe/trunk/test/SemaObjC/call-super-2.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/call-super-2.m?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/call-super-2.m (original)
> +++ cfe/trunk/test/SemaObjC/call-super-2.m Mon Jun 17 12:10:54 2013
> @@ -68,7 +68,7 @@ id objc_getClass(const char *s);
> }
> - (int) instance_func1
> {
> - int i = (size_t)[self instance_func0]; // expected-warning {{instance method '-instance_func0' not found (return type defaults to 'id')}}
> + int i = (size_t)[self instance_func0]; // expected-warning {{instance method 'instance_func0' not found (return type defaults to 'id'); did you mean 'instance_func3'?}}
> return i + (size_t)[super instance_func0]; // expected-warning {{'Object' may not respond to 'instance_func0'}}
> }
> - (int) instance_func2
>
> Modified: cfe/trunk/test/SemaObjC/protocol-id-test-1.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocol-id-test-1.m?rev=184086&r1=184085&r2=184086&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/protocol-id-test-1.m (original)
> +++ cfe/trunk/test/SemaObjC/protocol-id-test-1.m Mon Jun 17 12:10:54 2013
> @@ -12,5 +12,5 @@
> @end
>
> @implementation INTF
> -- (void)IMeth {INTF<P> *pi; [pi Meth]; } // expected-warning {{method '-Meth' not found (return type defaults to 'id')}}
> +- (void)IMeth {INTF<P> *pi; [pi Meth]; } // expected-warning {{instance method 'Meth' not found (return type defaults to 'id'); did you mean 'IMeth'?}}
> @end
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list