[patterns-record-deconstruction3] RFR: Fix deconstruction patterns with unconditional nested type pattern
Aggelos Biboudis
duke at openjdk.java.net
Mon Apr 25 18:54:58 UTC 2022
On Mon, 25 Apr 2022 07:09:13 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> According to the spec:
>>
>>
>> class Super {}
>> class Sub extends Super {}
>> record R(Super s) {}
>>
>> public static void testRes(R r) {
>> switch(r) {
>> case R(Super s) -> System.out.println("a");
>> }
>> }
>>
>> testRes(new R(null)); // this should match since after resolution, the nested type pattern is transformed to an any pattern
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java line 310:
>
>> 308: }
>> 309: else
>> 310: extraTest = makeLit(syms.booleanType, 1);
>
> Thanks for working on this.
>
> A few general comments here:
> - we usually put `else` at the same line as the preceding closing `}`, e.g. `} else`.
> - we usually put `{}` around the else section when there are brackets around the then section
> - we normally don't (currently) use `instanceof` to check AST node types - we usually use `JCTree.hasTag` or `JCTree.getTag`.
>
> Here, seems this would work as well, right?
>
> } else if (nested.type.isReference() && nested.hasTag(Tag.DECONSTRUCTIONPATTERN)) {
> extraTest = makeBinary(Tag.NE, make.Ident(nestedTemp), makeNull());
> }
Thank you @lahodaj
Addressed.
-------------
PR: https://git.openjdk.java.net/amber/pull/81
More information about the amber-dev
mailing list