This revision was automatically updated to reflect the committed changes. Closed by commit rGcb3f20d27c9e: [clang-format] Correct indentation for `[key] = value,` entries in C++ object… (authored by Jonathan Coe <jb...@google.com>).
Changed prior to commit: https://reviews.llvm.org/D75747?vs=249155&id=249172#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75747/new/ https://reviews.llvm.org/D75747 Files: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTestCSharp.cpp Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -551,6 +551,15 @@ Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); }, };)", Style); + + // Dictionary initialisation. + verifyFormat(R"(// +var myDict = new Dictionary<string, string> { + ["name"] = _donald, + ["age"] = Convert.ToString(DateTime.Today.Year - 1934), + ["type"] = _duck, +};)", + Style); } TEST_F(FormatTestCSharp, CSharpNamedArguments) { Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1047,6 +1047,9 @@ if (NextNonComment->is(TT_ArraySubscriptLSquare)) { if (State.Stack.back().StartOfArraySubscripts != 0) return State.Stack.back().StartOfArraySubscripts; + else if (Style.isCSharp()) // C# allows `["key"] = value` inside object + // initializers. + return State.Stack.back().Indent; return ContinuationIndent; }
Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -551,6 +551,15 @@ Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); }, };)", Style); + + // Dictionary initialisation. + verifyFormat(R"(// +var myDict = new Dictionary<string, string> { + ["name"] = _donald, + ["age"] = Convert.ToString(DateTime.Today.Year - 1934), + ["type"] = _duck, +};)", + Style); } TEST_F(FormatTestCSharp, CSharpNamedArguments) { Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1047,6 +1047,9 @@ if (NextNonComment->is(TT_ArraySubscriptLSquare)) { if (State.Stack.back().StartOfArraySubscripts != 0) return State.Stack.back().StartOfArraySubscripts; + else if (Style.isCSharp()) // C# allows `["key"] = value` inside object + // initializers. + return State.Stack.back().Indent; return ContinuationIndent; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits