Convert float/double += 1 into increment and decrement expressions - #3933
Open
siegfriedpammer wants to merge 1 commit into
Open
Convert float/double += 1 into increment and decrement expressions#3933siegfriedpammer wants to merge 1 commit into
siegfriedpammer wants to merge 1 commit into
Conversation
Reviving the 2020 test-cases-fp-types fixtures (compound assignment on float, double and decimal) exposed an asymmetry: post-increment and post-decrement on float/double round-tripped as x++/x--, but the pre forms came back as x += 1f because the increment detection in PrettifyAssignments only accepted integer constants. C# defines ++/-- on floating-point types as adding or subtracting exactly 1, so the conversion is exact for a constant 1 operand. Decimal already works through the op_Increment/op_Decrement path. Assisted-by: Claude:claude-fable-5:Claude Code
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Updates increment/decrement detection in the C# decompiler so float/double pre-increment/decrement can round-trip as ++x/--x (instead of x += 1f), and expands the pretty-printing fixture coverage for floating-point and decimal compound assignments.
Changes:
- Extend
PrettifyAssignmentsincrement/decrement detection to accept constant-1operands forfloatanddouble. - Revive/expand
CompoundAssignmentTestfixtures with extensivefloat/double/decimalcompound-assignment and inc/dec scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ICSharpCode.Decompiler/CSharp/Transforms/PrettifyAssignments.cs | Broadens ++/-- detection from integer-only constants to also cover float/double constant-1 cases. |
| ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs | Adds large fixture coverage for compound assignments and inc/dec over float, double, and decimal across many receiver shapes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -76,9 +76,12 @@ public override void VisitAssignmentExpression(AssignmentExpression assignment) | |||
| } | |||
| if (context.Settings.IntroduceIncrementAndDecrement && assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) | |||
Comment on lines
+79
to
+80
| // detect increment/decrement; ++/-- on float/double is defined as adding/subtracting | ||
| // exactly 1, so a constant 1 right-hand side qualifies there just like for integers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Revives the 2020
test-cases-fp-typesfixture work: ~770 lines of compound-assignment / increment / decrement coverage forfloat,double, anddecimalinCompoundAssignmentTest.cs, mirroring the existing integer sections (fields, properties, params, locals, ref returns, custom-struct receivers).The revived fixtures exposed an asymmetry: post-increment/decrement on float/double round-tripped as
x++/x--, but the pre forms decompiled tox += 1f, because the increment detection inPrettifyAssignmentsonly accepted integer constants. Since C# defines++/--on floating-point types as adding/subtracting exactly 1, a constant-1 float/double operand now also converts. Decimal needed no change (op_Increment/op_Decrementpath).Verified:
CompoundAssignmentTestgreen in all 24 configs, full decompiler suite green on Linux (3082 passed / 0 failed / 44 skipped).🤖 Generated with Claude Code