This is an archive of the discontinued LLVM Phabricator instance.

[Format/ObjC] Correctly handle base class with lightweight generics and protocol
ClosedPublic

Authored by benhamilton on Oct 15 2020, 2:10 PM.

Details

Summary

ClangFormat does not correctly handle an Objective-C interface declaration
with both lightweight generics and a protocol conformance.

This simple example:

@interface Foo : Bar <Baz> <Blech>

@end

means Foo extends Bar (a lightweight generic class whose type
parameter is Baz) and also conforms to the protocol Blech.

ClangFormat should not apply any changes to the above example, but
instead it currently formats it quite poorly:

@interface Foo : Bar <Baz>
<Blech>

    @end

The bug is that UnwrappedLineParser assumes an open-angle bracket
after a base class name is a protocol list, but it can also be a
lightweight generic specification.

This diff fixes the bug by factoring out the logic to parse
lightweight generics so it can apply both to the declared class
as well as the base class.

Test Plan: New tests added. Ran tests with:

% ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
Confirmed tests failed before diff and passed after diff.

Diff Detail

Event Timeline

benhamilton created this revision.Oct 15 2020, 2:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2020, 2:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benhamilton requested review of this revision.Oct 15 2020, 2:10 PM
sammccall accepted this revision.Oct 16 2020, 2:07 AM
This revision is now accepted and ready to land.Oct 16 2020, 2:07 AM