Skip to content

Commit bc99892

Browse files
Address PR feedback: Add WorkItem and refactor assignment checks
- Added WorkItem attribute to TestIfStatement_CompoundAssignment_Event test - Merged simple and compound assignment checks using IsLeftSideOfAnyAssignment helper - Simplified code by consolidating the two separate if statements into one Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
1 parent 30128dd commit bc99892

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/Analyzers/CSharp/Tests/UseNullPropagation/UseNullPropagationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ public void Dispose()
29142914
}
29152915
""");
29162916

2917-
[Fact]
2917+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81322")]
29182918
public Task TestIfStatement_CompoundAssignment_Event()
29192919
=> TestInRegularAndScriptAsync(
29202920
"""

src/Analyzers/Core/Analyzers/UseNullPropagation/AbstractUseNullPropagationDiagnosticAnalyzer.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,11 @@ private static TExpressionSyntax RemoveObjectCastIfAny(
440440
if (node is TElementAccessExpressionSyntax elementAccess)
441441
return (TExpressionSyntax?)syntaxFacts.GetExpressionOfElementAccessExpression(elementAccess);
442442

443-
if (syntaxFacts.SyntaxKinds.SimpleAssignmentExpression == node.RawKind && syntaxFacts.SupportsNullConditionalAssignment(node.SyntaxTree.Options))
444-
{
445-
syntaxFacts.GetPartsOfAssignmentExpressionOrStatement(node, out var left, out _, out _);
446-
return (TExpressionSyntax)left;
447-
}
448-
449-
// Check if node itself is a compound assignment. We do this by checking if the first child node
450-
// is on the left side of a compound assignment (which means the node is the compound assignment itself).
451-
// Compound assignments with null conditional (?.) are only supported in C# 14+.
443+
// Check if node itself is an assignment (simple or compound). We do this by checking if the first child node
444+
// is on the left side of any assignment (which means the node is the assignment itself).
445+
// Simple and compound assignments with null conditional (?.) are only supported in C# 14+.
452446
var firstChild = node.ChildNodesAndTokens().FirstOrDefault().AsNode();
453-
if (firstChild != null && syntaxFacts.IsLeftSideOfCompoundAssignment(firstChild) && syntaxFacts.SupportsNullConditionalAssignment(node.SyntaxTree.Options))
447+
if (firstChild != null && syntaxFacts.IsLeftSideOfAnyAssignment(firstChild) && syntaxFacts.SupportsNullConditionalAssignment(node.SyntaxTree.Options))
454448
{
455449
syntaxFacts.GetPartsOfAssignmentExpressionOrStatement(node, out var left, out _, out _);
456450
return (TExpressionSyntax)left;

0 commit comments

Comments
 (0)