-
Notifications
You must be signed in to change notification settings - Fork 79
Fix several issues in InstanceOfPatternMatch #489
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
Fix several issues in InstanceOfPatternMatch #489
Conversation
- always set the clazz of a InstanceOfPatternMatch to the casted class (don't keep the one from the original type check) - back off if the casted class is a non-wildcard generic - adapt `Arrays#string()` test to new behavior
…es (openrewrite#483,openrewrite#484) - doing so causes problems when the preexisting name shadows another variable, because our duplicate checking does not consider shadowing.
null)); | ||
typeCastTypeTree.getType(), | ||
null)) | ||
.withClazz(typeCastTypeTree.withPrefix(currentTypeTree.getPrefix()).withId(Tree.randomId())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems superfluous or possibly even wrong that we have to pass the type to the Identifier and also set it as clazz
on the J.InstanceOf
. Maybe this could be avoided with Java template, but I was unsure how one would look for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you mean a reference to line 263 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems superfluous or possibly even wrong that we have to pass the type to the Identifier and also set it as clazz on the J.InstanceOf
Not sure I understand why you find it superfluous. All identifiers need a type (so that our LST is typed - i.e. all elements have proper type information attributed). And arguably o instanceof String s1
is a declaration of o
Identifier and this needs type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I thought that by giving the identifier a type in line 263, this should determine the type for the entire expression and I should not have to set it again as the clazz
. To me it seems like clazz
should always be the same as the type passed in line 263, therefore I thought maybe I was using the class wrong or I misunderstood something generally.
src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the multiple fixes here @cortlepp ! @greg-at-moderne will have a look shortly and see if we can get this in before the release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the great contribution. I consider it a piece of high quality work. Well tested, thoughtful and solving a few overlapping cases in one go!
There's one minor outstanding issue and I think we are good to merge.
(Also, I acknowledge your questions on some of the linked issues, I will get to them).
null)); | ||
typeCastTypeTree.getType(), | ||
null)) | ||
.withClazz(typeCastTypeTree.withPrefix(currentTypeTree.getPrefix()).withId(Tree.randomId())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you mean a reference to line 263 here.
null)); | ||
typeCastTypeTree.getType(), | ||
null)) | ||
.withClazz(typeCastTypeTree.withPrefix(currentTypeTree.getPrefix()).withId(Tree.randomId())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems superfluous or possibly even wrong that we have to pass the type to the Identifier and also set it as clazz on the J.InstanceOf
Not sure I understand why you find it superfluous. All identifiers need a type (so that our LST is typed - i.e. all elements have proper type information attributed). And arguably o instanceof String s1
is a declaration of o
Identifier and this needs type.
src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java
Outdated
Show resolved
Hide resolved
- no longer discover generic assignments if they aren't wildcards - adapt `catTooSpecific` test to again cover the originally reported issue
…nto fix/instance-of-pattern-match
src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java
Show resolved
Hide resolved
Does it make sense to you? |
Hey, I'm currently on vacation until next week, I'll take a look at it as soon as I return. (Sorry I should've said something, I just forgot) |
Not sure what's happening with Github, might be some glitch. I have clicked the button to approve CI run a few times already for this PR. |
I think the run went through now (on your merge commit). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am satisfied with this change. I appreciate the contribution.
It looks like the current PR create an issue #528 |
What's changed?
instanceof
type.What's your motivation?
Anything in particular you'd like reviewers to focus on?
I'll annotate some areas in the files themselves.
Anyone you would like to review specifically?
@greg-at-moderne
Have you considered any alternatives or workarounds?
Any additional context
Checklist