[code-reflection] RFR: Support match all pattern [v3]
Paul Sandoz
psandoz at openjdk.org
Tue Sep 17 18:14:18 UTC 2024
On Tue, 17 Sep 2024 02:50:53 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
>> Support match all pattern.
>> This PR is based on [227](https://github.com/openjdk/babylon/pull/227).
>
> Mourad Abbay has updated the pull request incrementally with one additional commit since the last revision:
>
> Apply suggestions
That looks better.
We still might need to express the type for the match all (as described in the JLS section previously referenced) so that we can generate the lowered model that preserves Java program meaning.
Consider this:
record R<T extends Number>(T s) {
}
R<Double> r = new R<>(1.0);
if (r instanceof R<Double>(_)) {
System.out.println("");
}
The generated bytecode associated with `_` is:
INVOKEVIRTUAL A$R.s ()Ljava/lang/Number;
CHECKCAST java/lang/Double
ASTORE 3
I suggest we make a comment on `MatchAllPatternOp` and investigate further, with in a subsequent PR if needed.
src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 3228:
> 3226: } else if (pattern instanceof TypePatternOp bp) {
> 3227: return lowerBindingPattern(endNoMatchBlock, currentBlock, bindings, bp, target);
> 3228: } else if (pattern instanceof MatchAllPatternOp) {
Feel free to promote to switch expression, the IDE will probably do most of it for you.
-------------
Marked as reviewed by psandoz (Lead).
PR Review: https://git.openjdk.org/babylon/pull/230#pullrequestreview-2310369166
PR Review Comment: https://git.openjdk.org/babylon/pull/230#discussion_r1763610152
More information about the babylon-dev
mailing list