JDK-8051439 : Wrong type calculated for ADD operator with undefined operand
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-07-21
  • Updated: 2015-01-21
  • Resolved: 2014-08-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b26Fixed
Description
This program crashes with the latest Nashorn bits in 9. Assigning x to something before the loop fixes it.

function liveness() {                                                                                                                        
    var x;                                                                                                                                   
    for (var i = 0;i < 10; i++) {                                                                                                            
        x += i;                                                                                                                              
    }                                                                                                                                        
    x += "test";                                                                                                                             
    return x;                                                                                                                                
}                                                                                                                                            
                                                                                                                                            
                                                                                                                                             
liveness(); 

Exception in thread "main" java.lang.AssertionError
	at jdk.nashorn.internal.codegen.LocalVariableTypesCalculator.onSelfAssignment(LocalVariableTypesCalculator.java:1389)
	at jdk.nashorn.internal.codegen.LocalVariableTypesCalculator.enterBinaryNode(LocalVariableTypesCalculator.java:447)
	at jdk.nashorn.internal.ir.BinaryNode.accept(BinaryNode.java:315)
	at jdk.nashorn.internal.ir.ExpressionStatement.accept(ExpressionStatement.java:62)
	at jdk.nashorn.internal.ir.Node.accept(Node.java:240)
	at jdk.nashorn.internal.ir.Block.accept(Block.java:152)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.Block.accept(Block.java:391)
	at jdk.nashorn.internal.codegen.LocalVariableTypesCalculator.enterTestFirstLoop(LocalVariableTypesCalculator.java:821)
	at jdk.nashorn.internal.codegen.LocalVariableTypesCalculator.enterForNode(LocalVariableTypesCalculator.java:560)
	at jdk.nashorn.internal.ir.ForNode.accept(ForNode.java:91)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.LexicalContextStatement.accept(LexicalContextStatement.java:53)
	at jdk.nashorn.internal.ir.LoopNode.accept(LoopNode.java:36)
	at jdk.nashorn.internal.ir.Node.accept(Node.java:240)
	at jdk.nashorn.internal.ir.Block.accept(Block.java:152)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.Block.accept(Block.java:391)
	at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:351)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.LexicalContextExpression.accept(LexicalContextExpression.java:46)
	at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:52)
	at jdk.nashorn.internal.codegen.LocalVariableTypesCalculator$1.leaveFunctionNode(LocalVariableTypesCalculator.java:1229)
	at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:351)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.LexicalContextExpression.accept(LexicalContextExpression.java:46)
	at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:52)
	at jdk.nashorn.internal.ir.VarNode.accept(VarNode.java:127)
	at jdk.nashorn.internal.ir.Node.accept(Node.java:240)
	at jdk.nashorn.internal.ir.Block.accept(Block.java:152)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.Block.accept(Block.java:391)
	at jdk.nashorn.internal.codegen.LocalVariableTypesCalculator.leaveFunctionNode(LocalVariableTypesCalculator.java:1285)
	at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:351)
	at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
	at jdk.nashorn.internal.ir.LexicalContextExpression.accept(LexicalContextExpression.java:46)
	at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:52)
	at jdk.nashorn.internal.codegen.CompilationPhase$9.transform(CompilationPhase.java:277)
	at jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:685)
	at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:524)
	at jdk.nashorn.internal.runtime.Context.compile(Context.java:1131)
	at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1067)
	at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:517)
	at jdk.nashorn.tools.Shell.runScripts(Shell.java:314)
	at jdk.nashorn.tools.Shell.run(Shell.java:169)
	at jdk.nashorn.tools.Shell.main(Shell.java:133)
	at jdk.nashorn.tools.Shell.main(Shell.java:112)