JDK-8300691 - final variables in for loop headers should accept updates
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Oct 16 21:37:25 UTC 2024
Ok, now onto an improvements that might help us classify the results
more easily. Remember, our ultimate goal would be to see in which
context these variables are introduced. E.g. is it a for loop, is it a
method declaration, or an else block?
I was thinking of doing this in Attr using Env<AttrContext> but on
second though, that seems to complex.
Instead, it would be better if you just created a new visitor in Flow
whose only responsibility is that of populating the DummyVariable map
you already have.
This new visitor might keep track of the innermost "interesting"
enclosing context, and when you create the dummy variable, you note that
context down.
Possible interesting contexts are:
* if/then/else
* loop bodies (of all kinds)
* try/catch blocks
* switch
* method/constructor body
* static/instance initializer
* lambda expression
I probably forgot a few - but hopefully it's enough to get the message
across :-)
The note/warning will then include the context in which the dummy
variable was found (e.g. something like FOR, WHILE, TRY, CATCH. Just use
the name of the tree tag, which is an enum, so should render nicely).
Thanks
Maurizio
On 16/10/2024 22:03, Archie Cobbs wrote:
> On Wed, Oct 16, 2024 at 3:56 PM Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com> wrote:
>
> think we have to check whether the symbol under tree.init is that
> of a local variable.
>
> Oops, thanks. Should be fixed now.
>
> FWIW when I build the JDK itself with this change it outputs 113 notes.
>
> -Archie
>
> --
> Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241016/b78177fb/attachment.htm>
More information about the amber-dev
mailing list