Skip to content

Commit

Permalink
[clang-format] Correctly annotate braces in ObjC square brackets (#10…
Browse files Browse the repository at this point in the history
…6654)

See
#88238 (comment).

(cherry picked from commit e0f2368)
  • Loading branch information
owenca authored and tru committed Sep 1, 2024
1 parent 6f62347 commit 1ccd19c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 1ccd19c

Please sign in to comment.