Skip to content

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #79338

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 11, 2025 18:32
@CyrusNajmabadi CyrusNajmabadi enabled auto-merge July 11, 2025 20:15
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment

return null;

return (analysisResult.Value.ConditionPartToCheck, analysisResult.Value.WhenPartToCheck);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broke analysis into two parts. the pure, stateless analysis portino, and the part that does that and reports diagnostics. the former will be used by the fixer when batch fixing.

var ifStatement = (TIfStatementSyntax)context.Node;
var analysisResultOpt = AnalyzeIfStatement(
context.SemanticModel, referenceEqualsMethod, ifStatement, cancellationToken);
if (analysisResultOpt is not IfStatementAnalysisResult analysisResult)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing happened to the if-statement analyzer.

@@ -32,7 +33,7 @@ internal abstract class AbstractUseNullPropagationCodeFixProvider<
TElementBindingExpressionSyntax,
TIfStatementSyntax,
TExpressionStatementSyntax,
TElementBindingArgumentListSyntax> : SyntaxEditorBasedCodeFixProvider
TElementBindingArgumentListSyntax> : ForkingSyntaxEditorBasedCodeFixProvider<SyntaxNode>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hte major change. the amount of mutation that the fixer would perform (Especially with nested constructs) made this too difficult to be a normal SyntaxEditor fixer. So it got changes to a Forking one. That means it will fix, and then if it hits another diagnostic that contains a span it already fixed, it will instead form and attempt to reanalyze that outer construct to see if and how it can still be fixed.

var whenPart = root.FindNode(diagnostic.AdditionalLocations[2].SourceSpan, getInnermostNodeForTie: true);
var conditionalExpressionParts = this.GetPartsOfConditionalExpression(
semanticModel, conditionalExpression, cancellationToken);
if (conditionalExpressionParts is not var (conditionalPart, whenPart))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now, instead of grabbing this data off the diagnostic, we go back and renanalyze to get hte up to date info int he current fork.

@CyrusNajmabadi CyrusNajmabadi merged commit d3571ef into dotnet:main Jul 11, 2025
24 of 25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the nullPropCrash branch July 11, 2025 21:19
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 11, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSharpUseNullPropagationCodeFixProvider for IDE0031 in SyntaxEditor fails with "GetCurrentNode returned null" on Windows and macOS but works on Linux
3 participants