[clang] 0c28a09 - [clang-format] Correct indentation for `[key] = value,` entries in C# object initialisers
Jonathan Coe via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 02:47:49 PDT 2020
Author: Jonathan Coe
Date: 2020-03-10T09:36:52Z
New Revision: 0c28a0938c55ad34587fe88ac54ff2c85e79fa70
URL: https://github.com/llvm/llvm-project/commit/0c28a0938c55ad34587fe88ac54ff2c85e79fa70
DIFF: https://github.com/llvm/llvm-project/commit/0c28a0938c55ad34587fe88ac54ff2c85e79fa70.diff
LOG: [clang-format] Correct indentation for `[key] = value,` entries in C# object initialisers
Restores content of commit cb3f20d27c9e91cb9f997f0401f388e62c4ba993
reverted in commit 5a101f377315c0c0c58e8df842fe5eb5d8c7611d
with a corrected commit message.
Summary: Do not use continuation indent for '[' in blocks in C# code.
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: cfe-commits
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D75747
Added:
Modified:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index a08f5a3df864..9a6d7877efaa 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1047,6 +1047,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
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
index a22f48676065..7f819a61c70e 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -549,6 +549,15 @@ Shape[] shapes = new[] { new Circle { Radius = 2.7281, Colour = Colours.Red },
private Transformer _transformer = new X.Y {
Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
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);
}
More information about the cfe-commits
mailing list