[jdk16] RFR: 8256266: Binding variables don't correctly support declaration annotations and the final modifier

Jan Lahoda jlahoda at openjdk.java.net
Mon Jan 4 15:55:07 UTC 2021


[This is a copy of https://github.com/openjdk/jdk/pull/1192, but filled against the JDK 16 branch.]

Basically, javac does not handle code like this properly:

import java.lang.annotation.*;

public class B {
     public void test(Object o) {
         if (o instanceof @A String s) {}
     }
}

@Target(ElementType.LOCAL_VARIABLE)
@interface A {}

The parser needs to allow declaration annotations on binding variables, see:
http://cr.openjdk.java.net/~gbierman/jep394/jep394-20201012/specs/patterns-instanceof-jls.html#jls-14.30.1.1

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

Commit messages:
 - Removing forgotten debug call.
 - Reject final modifiers on non-pattern matching instanceof.
 - Fixing tests.
 - Merge branch 'JDK-8256266' of https://github.com/lahodaj/jdk into JDK-8256266
 - Removing an extra whitespace.
 - The 'final' modifier should be allowed on binding variables.
 - Merge branch 'master' into JDK-8256266
 - 8256266: Declaration annotations don't work properly for binding variables

Changes: https://git.openjdk.java.net/jdk16/pull/78/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk16&pr=78&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8256266
  Stats: 240 lines in 10 files changed: 228 ins; 3 del; 9 mod
  Patch: https://git.openjdk.java.net/jdk16/pull/78.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk16 pull/78/head:pull/78

PR: https://git.openjdk.java.net/jdk16/pull/78


More information about the compiler-dev mailing list