RFR: 8308637: AssertionError when using Trees.getScope in plug-in [v2]
Jan Lahoda
jlahoda at openjdk.org
Thu Feb 19 19:23:51 UTC 2026
> 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.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/29739/files
- new: https://git.openjdk.org/jdk/pull/29739/files/6d20f8a1..2a30c91d
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=29739&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=29739&range=00-01
Stats: 1 line in 1 file changed: 0 ins; 1 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/29739.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29739/head:pull/29739
PR: https://git.openjdk.org/jdk/pull/29739
More information about the compiler-dev
mailing list