[code-reflection] RFR: 8374550: API for casting Value to Op.Result and Block.Parameter [v3]

Gary Frost gfrost at openjdk.org
Tue Jan 6 16:01:36 UTC 2026


On Tue, 6 Jan 2026 01:42:21 GMT, Ruby Chen <duke at openjdk.org> wrote:

>> This PR adds two methods, `Value::result()` and `Value::parameter()`, which cast a given Value as a Op.Result or Block.Parameter. If the cast fails, the two methods throw an IllegalStateException.
>
> Ruby Chen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update copyright
>   
>   Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>

src/jdk.incubator.code/share/classes/jdk/incubator/code/Value.java line 81:

> 79:      * @throws IllegalStateException if the value is not an instance of an operation result.
> 80:      */
> 81:     public Op.Result result() {

This may be just my personal preference, so will defer to Paul.  But I thnkk this method should be called asResultOrThrow or resultOrThrow

src/jdk.incubator.code/share/classes/jdk/incubator/code/Value.java line 95:

> 93:      */
> 94:     public Block.Parameter parameter() {
> 95:         if (this instanceof Block.Parameter p) {

as above, I think this is likley to trip folk up, calling this to get Parameter and having to deal with exception 

maybe asParameterorThrow. 

Again Paul can make the final call on this.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/816#discussion_r2665409287
PR Review Comment: https://git.openjdk.org/babylon/pull/816#discussion_r2665415283


More information about the babylon-dev mailing list