RFR: 8326204: yield statements doesn't allow cast expressions with more than 1 type arguments

Jan Lahoda jlahoda at openjdk.org
Mon Mar 11 16:42:27 UTC 2024


On Mon, 11 Mar 2024 14:23:38 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

> A valid use of `yield` that includes a cast to a generic type with multiple parameters, was misdetected by `blockStatement` in parser. This PR addresses this issue.

Looks good, with one suggestion for consideration.

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 2897:

> 2895:                         int balance = 1;
> 2896:                         boolean hasComma = false;
> 2897:                         boolean hasTypeArgs = false;

For consideration, may also balance out the `<`/`>`, to cover cases like this:

    private static int t(int i) {
        yield((Map<String, String>) null, 2);
    }

    private static void yield(Map<String, String> m, int j) {
        
    }


Not critical, as this is error recovery anyway, so for consideration only.

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

Marked as reviewed by jlahoda (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/18196#pullrequestreview-1928189455
PR Review Comment: https://git.openjdk.org/jdk/pull/18196#discussion_r1519935963


More information about the compiler-dev mailing list