Skip to content

Commit 772b06b

Browse files
Ensure sub-expressions are still cleaned up.
1 parent 6a4311c commit 772b06b

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/Analyzers/CSharp/Tests/UseCoalesceExpression/UseCoalesceExpressionForNullableTernaryConditionalCheckTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseCoalesceExpression;
1717

1818
[Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
19-
public sealed class UseCoalesceExpressionForNullableTernaryConditionalCheckTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest_NoEditor
19+
public sealed class UseCoalesceExpressionForNullableTernaryConditionalCheckTests(ITestOutputHelper logger)
20+
: AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest_NoEditor(logger)
2021
{
21-
public UseCoalesceExpressionForNullableTernaryConditionalCheckTests(ITestOutputHelper logger)
22-
: base(logger)
23-
{
24-
}
25-
2622
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
2723
=> (new CSharpUseCoalesceExpressionForNullableTernaryConditionalCheckDiagnosticAnalyzer(),
2824
new UseCoalesceExpressionForNullableTernaryConditionalCheckCodeFixProvider());

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpSyntaxGeneratorInternal.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,7 @@ public override SyntaxNode ConvertExpression(SyntaxNode type, SyntaxNode express
338338
=> SyntaxFactory.CastExpression((TypeSyntax)type, (ExpressionSyntax)ParenthesizeNonSimple(expression)).WithAdditionalAnnotations(Simplifier.Annotation);
339339

340340
internal static SyntaxNode ParenthesizeNonSimple(SyntaxNode expression)
341-
=> expression is IdentifierNameSyntax ? expression : Parenthesize(expression);
341+
=> expression is IdentifierNameSyntax
342+
? expression.WithPrependedLeadingTrivia(SyntaxFactory.ElasticMarker).WithAppendedTrailingTrivia(SyntaxFactory.ElasticMarker)
343+
: Parenthesize(expression);
342344
}

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
104104
Friend Shared Function ParenthesizeNonSimple(expression As SyntaxNode, Optional addSimplifierAnnotation As Boolean = True) As ExpressionSyntax
105105
Dim identifierName = TryCast(expression, IdentifierNameSyntax)
106106
If identifierName IsNot Nothing Then
107-
Return identifierName
107+
Return identifierName.WithPrependedLeadingTrivia(SyntaxFactory.ElasticMarker).WithAppendedTrailingTrivia(SyntaxFactory.ElasticMarker)
108108
End If
109109

110110
Return Parenthesize(expression, addSimplifierAnnotation)

0 commit comments

Comments
 (0)