[code-reflection] RFR: Test Switch Expression lowering when case is constant
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jul 15 14:22:21 UTC 2024
On Thu, 4 Jul 2024 08:44:02 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
>> Test Switch Expression lowering when case is constant.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 658:
>
>> 656: pt = target;
>> 657: scan(tree);
>> 658: // there are cases where tree type is null
>
> @mcimadamore what do you think about this ?
In principle, this method should only be called for expressions. And all expressions have some type. I see two cases where this is not true:
* body of a switch label following a `->` which can be either an expression, or a throw (the latter is a statement, so it has no type)
* the body of a lambda expression, which can be either a JCBlock (no type) or a JCExpression
It might perhaps be better to cleanup this code by making sure that we have the following methods:
* `toValue(JCExpression, Type)`, like the one we have now
* `toValue(JCExpression)` which delegates to `toValue(expr, Type.noType)`
* `toValue(JCStatement)` which just call `scan` on the statement (no target type and no conversion here)
Then, clients will have to pay attention to which method to call. For instance, in the case of a switch label, we'd have to check whether the body of the label is a `throw` statement, and if so call the statement overload of `toValue` (w/o a target type).
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/169#discussion_r1677910820
More information about the babylon-dev
mailing list