Skip to content

Fix InvalidCastException in split-if refactoring for top-level statements#82807

Open
dibarbet wants to merge 2 commits intodotnet:mainfrom
dibarbet:fix/split-if-top-level-statement
Open

Fix InvalidCastException in split-if refactoring for top-level statements#82807
dibarbet wants to merge 2 commits intodotnet:mainfrom
dibarbet:fix/split-if-top-level-statement

Conversation

@dibarbet
Copy link
Member

@dibarbet dibarbet commented Mar 17, 2026

Probably resolves dotnet/vscode-csharp#9066

root.FindNode can return a GlobalStatementSyntax instead of an IfStatementSyntax when they share the same span in top-level code. Use getInnermostNodeForTie and FirstAncestorOrSelf to locate the correct if-statement node, matching the pattern already used by AbstractMergeIfStatementsCodeRefactoringProvider.

Microsoft Reviewers: Open in CodeFlow

…ents

root.FindNode can return a GlobalStatementSyntax instead of an
IfStatementSyntax when they share the same span in top-level code.
Use getInnermostNodeForTie and FirstAncestorOrSelf to locate the
correct if-statement node, matching the pattern already used by
AbstractMergeIfStatementsCodeRefactoringProvider.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dibarbet dibarbet marked this pull request as ready for review March 17, 2026 23:49
@dibarbet dibarbet requested a review from a team as a code owner March 17, 2026 23:50
…redundant assert

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dibarbet dibarbet enabled auto-merge March 18, 2026 00:13
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.

codeAction/resolve IfStatementSyntax

4 participants