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: handle same type for multiple operands #265

Conversation

rickie
Copy link
Contributor

@rickie rickie commented Mar 1, 2024

What's changed?

This introduces a failing unit test for the InstanceOfPatternmatch recipe.
We are giving the same name to the variable while we have an expression with two operands that check the same type.

What's your motivation?

The code in the "after" template is incorrect as it gives the following error:

Variable 's' is already defined in the scope

Any additional context

I'm curious how we can fix this. It doesn't seem trivial, so probably I don't have time right now to create a fix myself.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@rickie rickie force-pushed the rossendrijver/instanceofpatternmatch_bug branch from 735b18b to f817498 Compare March 1, 2024 15:33
@timtebeek timtebeek marked this pull request as draft March 1, 2024 16:29
@timtebeek
Copy link
Contributor

Thanks for the report! I think this is a variant of this case which contains some earlier attempts

Definitely something we'd want to see resolved.

@timtebeek
Copy link
Contributor

Exploring a likely fix in

@timtebeek timtebeek added the bug Something isn't working label Mar 3, 2024
@timtebeek timtebeek self-assigned this Mar 3, 2024
timtebeek added a commit to KoTurk/rewrite-static-analysis that referenced this pull request Mar 4, 2024
@timtebeek
Copy link
Contributor

I've merged this test into #175 ; let's continue there.

@timtebeek timtebeek closed this Mar 4, 2024
@rickie rickie deleted the rossendrijver/instanceofpatternmatch_bug branch March 4, 2024 12:17
@rickie
Copy link
Contributor Author

rickie commented Mar 4, 2024

Thanks Tim 😄!

I should've noticed the other issue before opening this one...

timtebeek added a commit that referenced this pull request Jul 14, 2024
…#175)

* Added failing JUnit test for issue "Duplicate variable name in if statement with two different instanceof"

* Add issue link

* Move and update test; include #265

* Update expectations & handle binary separately

* Demonstrate known failure

---------

Co-authored-by: Ko Turk <turkk@Kos-MacBook-Pro.local>
Co-authored-by: Tim te Beek <tim@moderne.io>
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

Successfully merging this pull request may close these issues.

2 participants