diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/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; } diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/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 { + ["name"] = _donald, + ["age"] = Convert.ToString(DateTime.Today.Year - 1934), + ["type"] = _duck, +};)", + Style); } TEST_F(FormatTestCSharp, CSharpNamedArguments) {