-
Notifications
You must be signed in to change notification settings - Fork 59
Fix scope of generics within parenthesis #148
Fix scope of generics within parenthesis #148
Conversation
The angle brackets in "value = (B<C>) obj;" were being treated as operators instead of punctuation.
Thanks for opening a PR. I have a couple of minor concerns with this approach; plus, it does not seem to work on the following cases: value = (B<T<C>>) a;
value = (B<T<? extends C>>) a; And potentially other weird generic combinations. Did you look to see if there is anything we do already for it? |
I didn’t see anything else that that handles generics within parenthesis, only generics that are directly in classes and functions. Do you have any suggestions for a better approach? |
Your approach seems reasonable, we just need to make it work for a wider set of generic expressions:). I will also look into the code closely and will let you know if there is anything we are missing in this approach. Well done with the initial fix! |
I realize that my first solution was a bit hacky, so I've been trying to come up with something else. The way we are currently matching generics every else (but not in parenthesis) is using a if (a < b && c > d) {
return;
}
if (a < b) {
return;
}
c = "b>a"; it ends up matching
and
An alternative I tried was to use a pattern like A<B<C>> obj = obj; Only Do you have any ideas @sadikovi? |
I would not really throw away your initial approach, I think it can work with some minor updates. So let's keep it as a fallback plan, in case there is no general enough solution. We had a discussion some time ago, and one of the approaches was solving from the perspective of My initial pull request was around fixing those angle brackets in parenthesis that had been originally parsed as generics, which could have been causing this issue as well (#93) It could be useful to create such patterns of matching Cheers! |
@brennenberkley any progress on this issue? I was thinking that we could merge your fix for now and open a follow-up issue. Let me know if you are happy with this approach. I will also try poking around a bit more and see if there is anything else we can do. |
@sadikovi I have not worked on it recently. We can merge it for now |
The angle brackets in
value = (B<C>) obj;
were being treated as comparison operators instead of punctuation.Description of the Change
Generics within parenthesis were not being recognized, so I added a pattern to match them before anything else.
Alternate Designs
None
Benefits
Syntax highlighting will be more accurate, all tests pass
Possible Drawbacks
none
Applicable Issues
Fixes #132