Integrated: 8286895: InternalError: Exception during analyze
Jan Lahoda
jlahoda at openjdk.java.net
Tue May 31 15:05:53 UTC 2022
On Tue, 24 May 2022 11:25:10 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Consider code like:
>
> Number n = 0;
> if (!n instanceof Integer i) {}
>
> javac parses this like:
>
> Number n = 0;
> if ((!n) instanceof Integer i) {}
>
>
> This is obviously erroneous, and will report an error in `Attr`, but if this code gets to `Flow`, like in JShell, then it will split the `inits`/`uninits` of variables to the `true`/`false` inits while processing the unary negation. But, then, the `instanceof` operator will try to declare a variable, which will fail with on an assertion, as that shouldn't be done when the inits are split to `true`/`false`:
>
> Caused by: java.lang.AssertionError
> at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
> at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
> at jdk.compiler/com.sun.tools.javac.util.Bits.excl(Bits.java:220)
> at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.newVar(Flow.java:1883)
> at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitVarDef(Flow.java:2261)
> at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1027)
> at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
> at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:444)
> at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1743)
> at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitBindingPattern(TreeScanner.java:307)
> at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitBindingPattern(Flow.java:2848)
> ...
>
>
> The proposed solution is to use `scanExpr` when handling the `instanceof`'s expression, which will merge the `true`/`false` inits, and let the variable be declared.
This pull request has now been integrated.
Changeset: 171a7cdd
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/171a7cdd5d44265b17541e17304e9ebed376a9fd
Stats: 31 lines in 4 files changed: 30 ins; 0 del; 1 mod
8286895: InternalError: Exception during analyze
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/8866
More information about the compiler-dev
mailing list