RFR: JDK-8248641: Trees.getScope returns incorrect results for code inside a rule case

Jan Lahoda jan.lahoda at oracle.com
Thu Jul 2 13:11:20 UTC 2020


Hi,

When calling Trees.getScope for a TreePath that is inside a rule case 
(i.e. "case ->"), the results are wrong/do not reflect the elements 
declared inside the enclosing method.

The reason is that, for rule cases, JCCase tree is keeping "body", which 
represents what is in the source code. And this body is wrapped and put 
into "stats", which are basically the statements for an ordinary case. 
This means that javac can typically only work over the "stats". When 
TreeCopied copies the JCCase tree, it will duplicate both "stats" and 
"body" separately, leading to a duplication in trees. And then 
Attr.breakTree points to the requested tree from "body", but that one is 
never attributed, and so the appropriate scope is never captured.

The proposed patch here is to only duplicate "stats", and then take 
appropriate "body" from "stats", leading to only one copy of the tree.

Webrev:
http://cr.openjdk.java.net/~jlahoda/8248641/webrev.00/

JBS:
https://bugs.openjdk.java.net/browse/JDK-8248641

How does this look?

Thanks,
     Jan


More information about the compiler-dev mailing list