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 creates duplicate identifiers in same scope #210

Closed
Bananeweizen opened this issue Nov 3, 2023 · 1 comment
Closed
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@Bananeweizen
Copy link
Contributor

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

Add this to InstanceOfPatternMatchTest

        @Test
        void multipleCastsSameType() {
            rewriteRun(
              //language=java
              java(
                """
                  public class A {
                      void test(Object first, Object second) {
                          if (first instanceof String && second instanceof String) {
                              System.out.println((String) first);
                              System.out.println((String) second);
                          }
                      }
                  }
                  """,
                """
                  public class A {
                      void test(Object first, Object second) {
                          if (first instanceof String string1 && second instanceof String string2) {
                              System.out.println(string1);
                              System.out.println(string2);
                          }
                      }
                  }
                  """
              )
            );
        }

What did you see instead?

Both instanceof checks use the same identifier:

                  public class A {
                      void test(Object first, Object second) {
                          if (first instanceof String string && second instanceof String string) {
                              System.out.println(string);
                              System.out.println(string);
                          }
                      }
                  }

Are you interested in contributing a fix to OpenRewrite?

No, sorry.

@Bananeweizen Bananeweizen added the bug Something isn't working label Nov 3, 2023
@timtebeek
Copy link
Contributor

Thanks for reporting this issue! We're already working on this in

After seeing in reported before in

Hope you don't mind me closing this issue as a duplicate; it's still appreciated, but best tracked in the existing issues.

@timtebeek timtebeek added the duplicate This issue or pull request already exists label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
Archived in project
Development

No branches or pull requests

2 participants