[patterns] Labeled statements

Brian Goetz brian.goetz at oracle.com
Wed Jan 22 15:37:23 UTC 2020

Thanks, you are right.  Labeled statements are a kind of statement, 
which is a clever way to spec it (and the nonlocal control flow they 
support), but the intent was never for labeled statements to create 
their own scopes.  For purposes of flow scoping, labels are not 
relevant, but obviously that's not what the spec says, and this needs 
should be clarified.

On 1/22/2020 4:54 AM, Tagir Valeev wrote:
> Hello!
> 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.
> E.g.:
> public static void main(String[] args) {
>          Object o = "hello";
>          L0: if(!(o instanceof String s)) {
>              return;
>          }
>          System.out.println(s.length());
> }
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200122/e47b04d1/attachment.htm>

More information about the amber-spec-experts mailing list