[code-reflection] Integrated: Fix the bug of pattern variable initialized with conversion

Mourad Abbay mabbay at openjdk.org
Fri Dec 19 22:36:54 UTC 2025


On Fri, 19 Dec 2025 20:15:27 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

> Generating code model for code such as:
>  ```@Reflect
>     void m(int i) {
>         if (i instanceof byte b) {
> 
>         }
>     }
>    ```
> was causing the below error in the compiler:
> 
> java.lang.IllegalStateException: Operand of operation jdk.incubator.code.dialect.core.CoreOp$VarOp at 503d687a is not defined in tree: %result at 482bce4f
>         at jdk.incubator.code/jdk.incubator.code.Block.bindOp(Block.java:764)
>         at jdk.incubator.code/jdk.incubator.code.Block.insertOp(Block.java:743)
>         at jdk.incubator.code/jdk.incubator.code.Block$Builder.op(Block.java:697)
>         at jdk.incubator.code/jdk.incubator.code.internal.ReflectMethods$BodyScanner.scanPattern(ReflectMethods.java:1342)
> ...
> 
> The cause is that we were adding the op that perform the conversion to the block of the IfOp first body, making the value unreachable to the VarOp of the pattern variable.
> The fix is from @PaulSandoz.

This pull request has now been integrated.

Changeset: 6973e96d
Author:    Mourad Abbay <mabbay at openjdk.org>
URL:       https://git.openjdk.org/babylon/commit/6973e96d31d1854a93b9c16ae816d4cf2944f823
Stats:     48 lines in 2 files changed: 42 ins; 0 del; 6 mod

Fix the bug of pattern variable initialized with conversion

Reviewed-by: psandoz

-------------

PR: https://git.openjdk.org/babylon/pull/771


More information about the babylon-dev mailing list