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

Duplicate variable name in if statement with two different instanceof #175

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

KoTurk
Copy link

@KoTurk KoTurk commented Sep 27, 2023

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

What's changed?

Created a failing JUnit test for the issue.
TODO: fix the issue

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Be kind, it's my first contribution to Open Source :-)

Anyone you would like to review specifically?

@timtebeek

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek
Copy link
Contributor

timtebeek commented Sep 27, 2023

As a next step it looks like we should be using VariableNameUtils when naming primitves as well; we already use it elsewhere, but not yet for primitives.

} else if (type instanceof JavaType.Primitive) {
String keyword = ((JavaType.Primitive) type).getKeyword();
return style == Style.SHORT ? keyword.substring(0, 1) : keyword;

Then, depending on what names VariableNameUtils will produce, we might need to revisit the expected test outcome.

@timtebeek timtebeek self-requested a review September 28, 2023 09:17
@timtebeek timtebeek added the bug Something isn't working label Sep 28, 2023
@timtebeek
Copy link
Contributor

Stepped through this case with the debugger; the problem here seems to be that once we process the second instanceof, that we don't have the first instanceof new string variable in scope as we generate a name for the second one. 🤔

@timtebeek
Copy link
Contributor

Exploring a likely fix in

@timtebeek timtebeek assigned timtebeek and unassigned KoTurk Mar 3, 2024
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
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants