RFR: 8308637: AssertionError when using Trees.getScope in plug-in [v2]
Vicente Romero
vromero at openjdk.org
Thu Feb 19 19:34:58 UTC 2026
On Thu, 19 Feb 2026 19:23:51 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> The Trees API has a method to get information about elements available at a given place in the source code: `Trees.getScope(TreePath)`. It works by duplicating a piece of the AST, passing it to `Attr`, and stopping the attribution at the point specified by the `TreePath`, returning the current `Env` at that point.
>>
>> For code like:
>>
>> class B {
>> public class Test {}
>> void m() {
>> new Test() {};
>> this.new Test() {};
>> }
>> }
>>
>>
>> when the TreePath is pointing at `Test` in `this.new Test`, this does not work very well for two reasons:
>> - when attributing the NewClassTree with enclosing expression, `Attr` is not really attributing the `Test` tree, but it synthetizes a temporary qualified name and attributes this synthetized name. The attribution then does not stop properly. This can be fixed by adding a check to stop the attribution at the appropriate place.
>> - if the enclosing classes are not-yet attributed, attributing the anonymous body for `new Test() {};` will trigger attribution of `Test`, which will trigger an attribution of `B`, and that will try to re-attribute the original method `m`. This is attributing the conceptually same method (with same local classes) twice, which leads to problems downstream. The proposal is to avoid superclass and enclosing class attribution when evaluating `Scope`.
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>
> Review feedback: cleanup/removing comment.
lgtm
-------------
Marked as reviewed by vromero (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/29739#pullrequestreview-3828083498
More information about the compiler-dev
mailing list