Skip to content

fix: do not replace lambda params with underscore when used as assignment target#1117

Merged
timtebeek merged 1 commit into
openrewrite:mainfrom
darrencilia:fix/replace-unused-variables-assignment-target
May 28, 2026
Merged

fix: do not replace lambda params with underscore when used as assignment target#1117
timtebeek merged 1 commit into
openrewrite:mainfrom
darrencilia:fix/replace-unused-variables-assignment-target

Conversation

@darrencilia
Copy link
Copy Markdown
Contributor

@darrencilia darrencilia commented May 28, 2026

Problem

ReplaceUnusedVariablesWithUnderscore incorrectly renames lambda parameters to _ when they appear as LHS assignment targets, producing uncompilable code.

Fix

Added usedAsAssignmentTarget() guard following the same pattern as the existing usedInModifyingUnary() method, and wired it into renameVariableIfUnusedInContext.

Tests

Added three test cases covering:

Copy link
Copy Markdown
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the immediate fix! Looks perfect.

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite May 28, 2026
@timtebeek timtebeek merged commit 21548bd into openrewrite:main May 28, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 28, 2026
@darrencilia darrencilia deleted the fix/replace-unused-variables-assignment-target branch May 28, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ReplaceUnusedVariablesWithUnderscore incorrectly renames lambda params used as assignment targets producing uncompilable code

2 participants