diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index ac117840ea335..d0d08e470e6c1 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -106,7 +106,7 @@ namespace format { TYPE(CSharpNullable) \ TYPE(CSharpNullCoalescing) \ TYPE(CSharpNullConditional) \ - TYPE(CSharpNullConditionalSq) \ + TYPE(CSharpNullConditionalLSquare) \ TYPE(Unknown) enum TokenType { diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index da73361ee3d5b..8fa78b773e5eb 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -345,7 +345,7 @@ bool FormatTokenLexer::tryMergeCSharpNullConditional() { if (PeriodOrLSquare->is(tok::l_square)) { Question->Tok.setKind(tok::question); // no '?[' in clang tokens. - Question->Type = TT_CSharpNullConditionalSq; + Question->Type = TT_CSharpNullConditionalLSquare; } else { Question->Tok.setKind(tok::question); // no '?.' in clang tokens. Question->Type = TT_CSharpNullConditional; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e1e08686ac44e..35e0b423cfc49 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -972,7 +972,7 @@ class AnnotatingParser { } break; case tok::question: - if (Tok->is(TT_CSharpNullConditionalSq)) { + if (Tok->is(TT_CSharpNullConditionalLSquare)) { if (!parseSquare()) return false; break; @@ -1456,7 +1456,7 @@ class AnnotatingParser { return; } if (CurrentToken->TokenText == "?[") { - Current.Type = TT_CSharpNullConditionalSq; + Current.Type = TT_CSharpNullConditionalLSquare; return; } } @@ -2947,11 +2947,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return true; // No space before '?['. - if (Right.is(TT_CSharpNullConditionalSq)) + if (Right.is(TT_CSharpNullConditionalLSquare)) return false; // Possible space inside `?[ 0 ]`. - if (Left.is(TT_CSharpNullConditionalSq)) + if (Left.is(TT_CSharpNullConditionalLSquare)) return Style.SpacesInSquareBrackets; // space between keywords and paren e.g. "using (" diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 0bc49856375b0..d22e0da82321e 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -607,6 +607,7 @@ TEST_F(FormatTestCSharp, CSharpSpaces) { Style.SpacesInSquareBrackets = true; verifyFormat(R"(private float[ , ] Values;)", Style); + verifyFormat(R"(string dirPath = args?[ 0 ];)", Style); } TEST_F(FormatTestCSharp, CSharpNullableTypes) {