Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
This is a quite rare test case
I have the following program
import java.util.function.Supplier; class Test { public static void test(Closure<Byte> x = {Byte v -> { Closure<Byte> y = { Supplier<Byte> d = { -> v } -> d.get() }; y() }}) { null } }
Actual behaviour
The above test program leads to a compiler crash with the following stack trace
>>> a serious error occurred: BUG! exception in phase 'class generation' in source unit 'test.groovy' tried to get a variable with the name v as stack variable, but a variable with this name was not created >>> stacktrace: BUG! exception in phase 'class generation' in source unit 'test.groovy' tried to get a variable with the name v as stack variable, but a variable with this name was not created at org.codehaus.groovy.classgen.asm.CompileStack.getVariable(CompileStack.java:303) at org.codehaus.groovy.classgen.asm.ClosureWriter.loadReference(ClosureWriter.java:151) at org.codehaus.groovy.classgen.asm.ClosureWriter.writeClosure(ClosureWriter.java:126) at org.codehaus.groovy.classgen.AsmClassGenerator.visitClosureExpression(AsmClassGenerator.java:858) at org.codehaus.groovy.ast.expr.ClosureExpression.visit(ClosureExpression.java:110) at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateEqual(BinaryExpressionHelper.java:397) at org.codehaus.groovy.classgen.AsmClassGenerator.visitDeclarationExpression(AsmClassGenerator.java:833) at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:89) at org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:611) at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:817) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41) at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:94) at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:748) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:70) at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:602) at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:547) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:110) at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:686) at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1131) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1124) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52) at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:365) at org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:797) at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:937) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:692) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:666) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:647) at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:311) at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:240) at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:165) at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:205) at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:189)
Expected behaviour
Compile successfully
Tested against master (commit: 5c468cd352f37fb5c599a3f51534ffcc55b339ed)