ceylon/ceylon-compiler — Issue #247: += on toplevel value causes NPE and compiler crash
Author: gavinking
Created: 2011-11-30 01:20:53+00:00
State: open
Labels: BUG, high priority

This code:

variable Natural i:=0;
void run() {
i+=1;
}

Results in:

java.lang.NullPointerException
at com.sun.tools.javac.comp.Flow.visitApply(Flow.java:1134)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1297)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:172)
at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1143)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:501)
at com.sun.tools.javac.comp.Flow.scanStats(Flow.java:509)
at com.sun.tools.javac.comp.Flow.visitBlock(Flow.java:764)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:766)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:501)
at com.sun.tools.javac.comp.Flow.visitMethodDef(Flow.java:710)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:654)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow.visitClassDef(Flow.java:658)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:586)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:1273)
at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1186)
at com.redhat.ceylon.compiler.tools.LanguageCompiler.flow(LanguageCompiler.java:480)
at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1160)
at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:851)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:810)
at com.redhat.ceylon.compiler.launcher.Main.compile(Main.java:392)
at com.redhat.ceylon.compiler.launcher.Main.compile(Main.java:327)
at com.redhat.ceylon.compiler.launcher.Main.compile(Main.java:317)
at com.redhat.ceylon.compiler.Main.compile(Main.java:50)
at com.redhat.ceylon.compiler.Main.main(Main.java:69)

Changing to `i:=i+1;` fixes the problem.

Note that `+=` also appears to be broken for locals, though the problem is less spectacular.