Skip to content

C# conversion-operator rename casts nested conversions instead of failing on overlapping edits - #608

Merged
MelbourneDeveloper merged 2 commits into
mainfrom
fix/rename-nested-conversion-casts
Nov 19, 2026
Merged

MelbourneDeveloper merged 2 commits into
mainfrom
fix/rename-nested-conversion-casts

Conversation

@MelbourneDeveloper

Copy link
Copy Markdown
Collaborator

TLDR

Renaming a C# implicit conversion operator to explicit no longer fails with "The changes must not overlap" when one converted use is nested inside another.

Details

  • WorkspaceManager.Rename.Operators.cs ConversionCasts:
    • Each converted expression used to get its own cast edit. In Twice(Pass(a)), both a and Pass(a) convert through the operator. Their edits overlapped, SourceText.WithChanges threw, and the whole rename failed with that raw exception.
    • Now only the OUTERMOST converted expression gets an edit. Its replacement is built with SyntaxNode.ReplaceNodes, so each inner conversion is already cast inside it: Twice((int)(Pass((int)(a)))).
    • The conversion check (ConvertsThrough) and the cast spelling (CastText) are split into their own helpers.
  • Found by the regression review of main against v0.33.0. The bug is in code added since the release, so no issue was filed.

How Do The Automated Tests Prove It Works?

  • WorkspaceManagerRenameConversionCastsTests.Implicit_to_explicit_casts_a_conversion_nested_in_a_converted_argument_without_overlapping_edits (new) uses a real project:
    • the rename succeeds, and the declaration reads explicit operator int;
    • a cast the user already wrote ((int)a) stays one cast, never (int)(int);
    • the nested use becomes Twice((int)(Pass((int)(a)))).
    • Before the fix it failed with The changes must not overlap. (Parameter 'changes').
  • The existing WorkspaceManagerRenameOperatorsTests still pass unchanged: 4 tests covering binary, unary, refused respellings and explicit↔implicit casts.

…e changes must not overlap' when one converted use is nested inside another (Twice(Pass(a)))
…ide the outer cast, built from the syntax tree, instead of emitting overlapping edits that fail the whole rename
@MelbourneDeveloper
MelbourneDeveloper enabled auto-merge (squash) November 19, 2026 16:25
@MelbourneDeveloper
MelbourneDeveloper merged commit 9161022 into main Nov 19, 2026
63 checks passed
@MelbourneDeveloper
MelbourneDeveloper deleted the fix/rename-nested-conversion-casts branch November 19, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant