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.
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.
I assume you mean a reference to line 263 here.
There was a problem hiding this comment.
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.
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.
timtebeek
left a comment
There was a problem hiding this comment.
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
greg-at-moderne
left a comment
There was a problem hiding this comment.
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.
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.
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.
- 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
|
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). |
greg-at-moderne
left a comment
There was a problem hiding this comment.
I am satisfied with this change. I appreciate the contribution.
|
It looks like the current PR create an issue #528 |
What's changed?
instanceoftype.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