On Thu, 2 Apr 2026 15:52:40 GMT, Aggelos Biboudis <[email protected]> 
wrote:

> This is the proposed patch for Enhanced Local Variable Declarations (Preview).
> 
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

nice job, also great work on the CSR. One comment this test case fails in 
jshell with NPE:
$ jshell --enable-preview
jshell> record Point(int x) {}
jshell> Point(var x) = new Object();

although correct, the bytecode generated for test cases like:

record Point(Integer x, Integer y) {}

class Test {
    static void local(Point p) { 
        Point(Integer x, Integer y) = p;
    }
}

seems to be a bit bloated, given that `p` can only be of type `Point` currently 
generated code:

static void local(Point p) {
        Integer x;
        Integer y;
        {
            /*synthetic*/ final Point match93$temp = p;
            if (match93$temp == null) throw new NullPointerException(null);
            {
                /*synthetic*/ Point $b$0;
                if (!(match93$temp instanceof Point && (let $b$0 = 
match93$temp; in true) && ((let /*synthetic*/ final Integer patt1$temp = 
$b$0.x() in (let x = patt1$temp; in true)) && (let /*synthetic*/ final Integer 
patt2$temp = $b$0.y() in (let y = patt2$temp; in true))))) throw new 
MatchException(null, null);
            }
        }
    }

seems to have redundancies that can be avoided.

src/jdk.compiler/share/classes/com/sun/source/tree/EnhancedVariableDeclarationTree.java
 line 49:

> 47:      * @return pattern
> 48:      */
> 49:     Tree getPattern();

At EnhancedForLoopTree we have method:

PatternTree getRecordPattern();


shouldn't this method also return `PatternTree`?

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

PR Comment: https://git.openjdk.org/jdk/pull/30556#issuecomment-4357296061
PR Comment: https://git.openjdk.org/jdk/pull/30556#issuecomment-4360904722
PR Review Comment: https://git.openjdk.org/jdk/pull/30556#discussion_r3174575541

Reply via email to