Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.1
-
None
Description
Here's an simplified example of what's in Gaelyk:
import groovy.transform.* import org.codehaus.groovy.ast.ClassHelper import org.codehaus.groovy.ast.ASTNode import org.codehaus.groovy.ast.AnnotationNode import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.ast.MethodNode import org.codehaus.groovy.control.SourceUnit import org.codehaus.groovy.transform.ASTTransformation import org.codehaus.groovy.control.CompilePhase import org.codehaus.groovy.transform.GroovyASTTransformation @CompileStatic @GroovyASTTransformation(phase = CompilePhase.SEMANTIC_ANALYSIS) class EntityTransformation implements ASTTransformation { void visit(ASTNode[] nodes, SourceUnit source) { ClassNode parent = (ClassNode) nodes[1] parent.addMethod(addStaticDelegatedMethod([:])) } private MethodNode addStaticDelegatedMethod(Map params, ClassNode returnType = ClassHelper.DYNAMIC_TYPE) {} } def et = new EntityTransformation()
At runtime, we get the following problem:
Exception thrown java.lang.VerifyError: (class: EntityTransformation, method: visit signature: ([Lorg/codehaus/groovy/ast/ASTNode;Lorg/codehaus/groovy/control/SourceUnit;)V) Unable to pop operand off an empty stack at ConsoleScript119.run(ConsoleScript119:23)
It seems to be related to the fact the method addStaticDelegatedMethod has an default parameter at the end. It also depends on the first parameter being a map (for instance it won't fail if the first parameter is a string). It also works if we explicitly give the optional parameter.