ReplaceUnusedVariablesWithUnderscore produces invalid syntax for typed lambda parameters #1080
Copy link
Copy link
Closed
Description
What version of OpenRewrite are you using?
rewrite-core8.81.1rewrite-migrate-java3.34.0
What is the smallest, simplest way to reproduce the problem?
@Test
void typedLambdaParameterRenamedToUnderscoreNeedsParentheses() {
rewriteRun(
spec -> spec.recipe(new ReplaceUnusedVariablesWithUnderscore()),
java(
"""
package com.helloworld;
public class Main {
interface Handler {
String handle(RequestContext context);
}
static class RequestContext {}
Handler route() {
return (RequestContext rc) -> {
return "result";
};
}
}
""",
spec -> spec.markers(javaVersion(25))));
}What did you expect to see?
The explicitly typed lambda parameter should remain parenthesized:
Handler route() {
return (RequestContext _) -> {
return "result";
};
}What did you see instead?
The recipe emits invalid Java:
Handler route() {
return RequestContext _ -> {
return "result";
};
}What is the full stack trace of any errors you encountered?
The invalid output later failed Java formatting/parsing with errors like:
error: ')' or ',' expected
RequestContext _ -> {
^
error: not a statement
RequestContext _ -> {
^
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Keep parentheses when renaming typed lambda parameter to underscore (#…