RFR: 8250625: Compiler implementation of Pattern Matching for instanceof (Final)

Vicente Romero vromero at openjdk.java.net
Tue Oct 20 03:19:16 UTC 2020


On Thu, 8 Oct 2020 11:49:17 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> This is the current proposed patch for the upcoming JEP 394, for pattern matching for instanceof.
> 
> A summary of changes:
> -making the feature permanent (non-preview)
> -making the binding variables non-final (as per current specification proposal)
> -producing a compile-time error for the case where the expression's type is a subtype of the type test pattern's type
>  (as per current specification proposal)
> -changing the AST structure so that the binding variable has a VariableTree in the AST. BindingPatternTree is preserved
>  and encloses the VariableTree. The reason is better consistency in the API, with nodes like CatchTree, EnhancedForLoop
>  Tree, etc.
> 
> This change will not be integrated until JEP 394 is targetted.

Changes requested by vromero (Reviewer).

test/langtools/tools/javac/patterns/BindingsTest1.java line 28:

> 26:  * @bug 8231827
> 27:  * @summary Basic tests for bindings from instanceof
> 28:  * @compile BindingsTest1.java

the @compile can be removed

test/langtools/tools/javac/patterns/BindingsTest1.java line 29:

> 27:  * @summary Basic tests for bindings from instanceof
> 28:  * @compile BindingsTest1.java
> 29:  * @run main BindingsTest1

and this line too

test/langtools/tools/javac/patterns/ExamplesFromProposal.java line 29:

> 27:  * @summary All example code from "Pattern Matching for Java" document, released April 2017, adjusted to current
> state (no switches, etc) 28:  * @compile ExamplesFromProposal.java
> 29:  * @run main ExamplesFromProposal

these two lines can be removed now, there are other tests in this commit in which they can also be eliminated

test/langtools/tools/javac/patterns/LocalVariableTable.java line 29:

> 27:  * @summary Ensure the LV table entries are generated for bindings
> 28:  * @modules jdk.jdeps/com.sun.tools.classfile
> 29:  * @compile -g LocalVariableTable.java

I believe all tests are always compiled with `-g` option set, not related to your patch but we could probably remove
that line as superfluous

test/langtools/tools/javac/patterns/PatternsSimpleVisitorTest.java line 108:

> 106:         StringWriter out = new StringWriter();
> 107:         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
> 108:             List.of(), null,

nit: what about passing `null` instead of `List.of()`?

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

PR: https://git.openjdk.java.net/jdk/pull/559


More information about the core-libs-dev mailing list