RFR: 8256266: Binding variables don't correct support declaration annotations and the final modifier [v3]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Mon Dec 7 13:51:15 UTC 2020
On Mon, 7 Dec 2020 11:21:26 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> 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
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>
> Fixing tests.
Changes look good - I just have a question on the parser code
src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 946:
> 944: TreeInfo.getStartPos(pattern);
> 945: } else {
> 946: if (mods.annotations.nonEmpty()) {
We don't seem to check for the source level here? E.g. is it possible that `instanceof @Foo Bar` will not issue the usual error if compiled with source != 16?
-------------
PR: https://git.openjdk.java.net/jdk/pull/1192
More information about the compiler-dev
mailing list