From b791ce6223aecadbd6363e35870bc8be4b50ec4c Mon Sep 17 00:00:00 2001 From: Dmitry Zhavoronkov Date: Wed, 12 Jun 2024 13:48:20 +0700 Subject: [PATCH] Fix #1268 (#1292) --- .../TestFiles/cs/InitializerExpressions.test | 7 +++++ .../InitializerExpression.cs | 29 ++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/InitializerExpressions.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/InitializerExpressions.test index fd4cd4e0d..cbe656ed2 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/InitializerExpressions.test +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/InitializerExpressions.test @@ -232,6 +232,13 @@ class ClassName .CallMethod() .CallMethod() }; + + // Issue#1268 + var someObject = new List<( + int Field1__________________________________, + int Field2__________________________________ + )> + { }; } private SomeObject someObject = diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InitializerExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InitializerExpression.cs index 2b9dc3052..25c78ecbf 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InitializerExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InitializerExpression.cs @@ -29,22 +29,23 @@ is SyntaxKind.ArrayInitializerExpression var result = Doc.Concat( separator, Token.Print(node.OpenBraceToken, context), - Doc.Indent( - alwaysBreak ? Doc.HardLine : Doc.Line, - SeparatedSyntaxList.Print( - node.Expressions, - Node.Print, - alwaysBreak ? Doc.HardLine : Doc.Line, - context - ) - ), - node.Expressions.Any() - ? alwaysBreak - ? Doc.HardLine - : Doc.Line - : Doc.Null, + node.Expressions.Count == 0 + ? " " + : Doc.Concat( + Doc.Indent( + alwaysBreak ? Doc.HardLine : Doc.Line, + SeparatedSyntaxList.Print( + node.Expressions, + Node.Print, + alwaysBreak ? Doc.HardLine : Doc.Line, + context + ) + ), + alwaysBreak ? Doc.HardLine : Doc.Line + ), Token.Print(node.CloseBraceToken, context) ); + return node.Parent is not (