Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstanceOfPatternMatch leads to duplicate variable name in if statement with two different instanceof #174

Closed
ghost opened this issue Sep 26, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Sep 26, 2023

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v5.5.2
  • Maven/Gradle plugin v3.11.0
  • rewrite-module v2.1.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

<plugin>
    <groupId>org.openrewrite.maven</groupId>
    <artifactId>rewrite-maven-plugin</artifactId>
    <version>5.5.2</version>
    <configuration>
        <activeRecipes>
            <recipe>org.openrewrite.java.migrate.UpgradeToJava20</recipe>
        </activeRecipes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-migrate-java</artifactId>
            <version>2.1.0</version>
        </dependency>
    </dependencies>
</plugin>

What is the smallest, simplest way to reproduce the problem?

if (test instanceof TestClass && test2 instanceof TestClass) {
    ...
}

What did you expect to see?

if (test instanceof TestClass t && test2 instanceof TestClass t2) {
    ...
}

What did you see instead?

if (test instanceof TestClass t && test2 instanceof TestClass t) {
    ...
}

Are you interested in contributing a fix to OpenRewrite?

@ghost ghost added the bug Something isn't working label Sep 26, 2023
@timtebeek
Copy link
Contributor

Thanks for reporting this issue! We have a variable name utility class that should be used here to generate a unique name given the context. Should be relatively straightforward if you'd want to explore that yourself.

@timtebeek timtebeek added the good first issue Good for newcomers label Sep 26, 2023
@timtebeek timtebeek transferred this issue from openrewrite/rewrite-migrate-java Sep 27, 2023
@timtebeek
Copy link
Contributor

timtebeek commented Sep 27, 2023

Replicated and picked up in #175 by @KoTurk

@timtebeek timtebeek removed the good first issue Good for newcomers label Dec 2, 2023
@timtebeek timtebeek changed the title Duplicate variable name in if statement with two different instanceof InstanceOfPatternMatch leads to duplicate variable name in if statement with two different instanceof Jun 27, 2024
@timtebeek
Copy link
Contributor

Already much improved in

Closing the issue as I expect any remaining cases to be rare in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

1 participant