RFR: 8286895: InternalError: Exception during analyze
Jan Lahoda
jlahoda at openjdk.java.net
Tue May 24 11:32:12 UTC 2022
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.
-------------
Commit messages:
- 8286895: InternalError: Exception during analyze
Changes: https://git.openjdk.java.net/jdk/pull/8866/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8866&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8286895
Stats: 31 lines in 4 files changed: 30 ins; 0 del; 1 mod
Patch: https://git.openjdk.java.net/jdk/pull/8866.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/8866/head:pull/8866
PR: https://git.openjdk.java.net/jdk/pull/8866
More information about the compiler-dev
mailing list