diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3053,6 +3053,10 @@ if (Left.is(TT_CSharpNullConditionalLSquare)) return Style.SpacesInSquareBrackets; + // space after var in `var (key, value)` + if (Left.is(Keywords.kw_var) && Right.is(tok::l_paren)) + return true; + // space between keywords and paren e.g. "using (" if (Right.is(tok::l_paren)) if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when)) 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 @@ -698,6 +698,7 @@ verifyFormat(R"(Result this[Index x] => Foo(x);)", Style); verifyFormat(R"(char[,,] rawCharArray = MakeCharacterGrid();)", Style); + verifyFormat(R"(var (key, value))", Style); // Not seen as a C-style cast. verifyFormat(R"(//