[patterns] Labeled statements

Tagir Valeev amaembo at gmail.com
Wed Jan 22 09:54:06 UTC 2020


Current spec draft 6.3.2 [1] says nothing about the interaction of
pattern scopes and labeled statements, and reading spec 14.5 and 14.7
I conclude that the labeled statement is a kind of statement.


public static void main(String[] args) {
        Object o = "hello";
        L0: if(!(o instanceof String s)) {

I conclude that the `if` statement has no immediately enclosing block
because it's just a part of labeled statement, which is enclosed into
a block. So according to the current spec draft, the `s` variable
should not be resolvable after the labeled statement. Though javac
implementation disagrees with me and happily accepts this code.

So it looks like the spec should be updated to specify how labeled
statements are handled.

[1] http://cr.openjdk.java.net/~gbierman/jep305/jep305-20191021/specs/patterns-instanceof-jls.html#jls-6.3.2

More information about the amber-spec-experts mailing list