Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.0-beta-4
-
None
-
Mac OS X, Java 1.4.2
Description
I cannot return from a void method/function. For example:
def void testme() {
if(1==1)
return
else
println "hi"
}
testme()
This will fail with this stack trace:
Caught: org.codehaus.groovy.classgen.ClassGeneratorException: Cannot generate bytecode for constant: class java.lang.Void of type: java.lang.Class
org.codehaus.groovy.classgen.ClassGeneratorException: Cannot generate bytecode for constant: class java.lang.Void of type: java.lang.Class
at org.codehaus.groovy.classgen.ClassGenerator.visitConstantExpression(ClassGenerator.java:1315)
at org.codehaus.groovy.ast.expr.ConstantExpression.visit(ConstantExpression.java:75)
at org.codehaus.groovy.classgen.ClassGenerator.visitAndAutobox(ClassGenerator.java:2639)
at org.codehaus.groovy.classgen.ClassGenerator.evaluateExpression(ClassGenerator.java:971)
at org.codehaus.groovy.classgen.ClassGenerator.visitReturnStatement(ClassGenerator.java:903)
at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:70)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:108)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:79)
at org.codehaus.groovy.classgen.ClassGenerator.visitIfElse(ClassGenerator.java:545)
at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:71)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:108)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:79)
at org.codehaus.groovy.classgen.ClassGenerator.visitMethod(ClassGenerator.java:346)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:699)
at org.codehaus.groovy.classgen.ClassGenerator.visitClass(ClassGenerator.java:273)
at org.codehaus.groovy.classgen.CompilerFacade.generateClass(CompilerFacade.java:114)
at org.codehaus.groovy.classgen.CompilerFacade.parseClass(CompilerFacade.java:153)
at org.codehaus.groovy.classgen.CompilerFacade.parseClass(CompilerFacade.java:83)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:154)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:108)
at groovy.lang.GroovyShell.run(GroovyShell.java:182)
at groovy.lang.GroovyShell.main(GroovyShell.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:344)
at org.codehaus.classworlds.Launcher.main(Launcher.java:474)
Attachments
Attachments
Issue Links
- is duplicated by
-
GROOVY-405 Can't generate bytecode for void return
- Closed