[code-reflection] RFR: Unify common code of SwitchStatementOp and SwitchExpressionOp [v2]

Paul Sandoz psandoz at openjdk.org
Tue Sep 10 01:34:15 UTC 2024


On Tue, 10 Sep 2024 01:22:21 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> I see. Or we can test if resultType isn't void
>
> It cannot be:
> 
>     /**
>      * Returns the operation's result, otherwise {@code null} if the operation is not assigned to a block.
>      *
>      * @return the operation's result, or {@code null} if not assigned to a block.
>      */
>     public final Result result() {
>         return result;
>     }
> 
> 
> The field is only null if the operation is not assigned (or bound) to a block, otherwise it has a value even if the type of that value is the void type. An operation is assigned to a block when it is appended via building, so any non-top-level operation in a model must have a result.

Yes, you can check if its not equal e.g. `!JavaType.VOID.equals(result())`, but you could also check the `this` instance, since a switch expression yields a non-void value, its arguably clearer in the code.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/222#discussion_r1751125048


More information about the babylon-dev mailing list