This is an archive of the discontinued LLVM Phabricator instance.

[clang][ObjC] Add fix it for missing methods in impl
ClosedPublic

Authored by dgoldman on Dec 30 2021, 9:36 AM.

Details

Summary

We suggest inserting the method with an empty body at the end
of the implementation decl.

Diff Detail

Event Timeline

dgoldman requested review of this revision.Dec 30 2021, 9:36 AM
dgoldman created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 30 2021, 9:36 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dgoldman updated this revision to Diff 396690.Dec 30 2021, 9:59 AM

Add a test

Thanks, this looks good!

clang/lib/Sema/SemaDeclObjC.cpp
2237

Str -> FixitStr

The comment is IMO too verbose, maybe just "// Add an empty definition at the end of @implementation".
(The future idea doesn't seem either specific or critical)

2239

No need to copy the policy, just refer to it directly?

2241

nit: mixing string & output stream modifications is a bit confusing

2241

I think this should probably only have one inside and one at the end.

Fixits aren't really in the business of formatting the code to be further modified.
I can't find examples of fixits inserting blank lines that aren't necessary, apart from at the end of decls.

One newline between empty braces seems to be LLVM's style for objc. (For C++ it's zero newlines)

clang/test/FixIt/fixit-objc-missing-method-impl.m
2

Can you also include a -verify run to show the error being fixed? This seems to be common in other tests, and it makes it much easier to understand what's being tested.

dgoldman updated this revision to Diff 397336.Jan 4 2022, 10:32 AM
dgoldman marked 4 inline comments as done.

Fixes for review

dgoldman marked an inline comment as done.Jan 4 2022, 10:34 AM
dgoldman added inline comments.
clang/lib/Sema/SemaDeclObjC.cpp
2241

I changed it to be one newline between the braces but 2 before the @end so you get

- (void)something {
}

@end

since I think that's more common

sammccall accepted this revision.Jan 4 2022, 10:44 AM
This revision is now accepted and ready to land.Jan 4 2022, 10:44 AM
This revision was landed with ongoing or failed builds.Jan 4 2022, 12:58 PM
This revision was automatically updated to reflect the committed changes.
dgoldman marked an inline comment as done.