Skip to content

release/19.x: [clang-format] Correctly annotate braces in ObjC square brackets (#106654) #106819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2668,6 +2668,7 @@ void UnwrappedLineParser::parseSquare(bool LambdaIntroducer) {
break;
}
case tok::at:
case tok::colon:
nextToken();
if (FormatTok->is(tok::l_brace)) {
nextToken();
Expand Down
9 changes: 9 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3238,6 +3238,15 @@ TEST_F(TokenAnnotatorTest, BlockLBrace) {
EXPECT_BRACE_KIND(Tokens[4], BK_Block);
EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_BlockLBrace);
EXPECT_BRACE_KIND(Tokens[5], BK_Block);

Tokens = annotate("[foo bar:{{0, 1}} baz:baz];",
getLLVMStyle(FormatStyle::LK_ObjC));
ASSERT_EQ(Tokens.size(), 17u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown); // Not TT_BlockLBrace.
EXPECT_BRACE_KIND(Tokens[4], BK_Unknown); // Not BK_Block.
EXPECT_BRACE_KIND(Tokens[5], BK_BracedInit);
EXPECT_BRACE_KIND(Tokens[9], BK_Unknown); // Not BK_Block.
EXPECT_BRACE_KIND(Tokens[10], BK_Unknown); // Not BK_Block.
}

TEST_F(TokenAnnotatorTest, SwitchExpression) {
Expand Down
Loading