Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-beta-4
-
None
-
Mac OS X, java 1.4.2
Description
I seem to be unable to use a closure inside a case statement. For example:
def testme(cmd, a) {
switch(cmd) {
case "list":
a.each
break
}
}
testme "list" [1,2,3]
This generates the following stack trace:
No variable scope for: org.codehaus.groovy.ast.expr.ClosureExpression@a3eab6[]
{ org.codehaus.groovy.ast.stmt.BlockStatement@867fad[org.codehaus.groovy.ast.stmt.ExpressionStatement@285d14[expression:org.codehaus.groovy.ast.expr.MethodCallExpression@f6ef01[object: org.codehaus.groovy.ast.expr.VariableExpression@c54654[variable: this] method: println arguments: org.codehaus.groovy.ast.expr.TupleExpression@8c6982[org.codehaus.groovy.ast.expr.VariableExpression@62e703[variable: it]]]]] } method: org.codehaus.groovy.ast.MethodNode@2c7ac5[name: testme] constructor: null
Caught: java.lang.RuntimeException: Must have a VariableScope by now! for expression: org.codehaus.groovy.ast.expr.ClosureExpression@a3eab6[]
class: SwitchClosure$1
java.lang.RuntimeException: Must have a VariableScope by now! for expression: org.codehaus.groovy.ast.expr.ClosureExpression@a3eab6[]
class: SwitchClosure$1
at org.codehaus.groovy.classgen.ClassGenerator.createClosureClass(ClassGenerator.java:2275)
at org.codehaus.groovy.classgen.ClassGenerator.visitClosureExpression(ClassGenerator.java:1143)
at org.codehaus.groovy.ast.expr.ClosureExpression.visit(ClosureExpression.java:74)
at org.codehaus.groovy.classgen.ClassGenerator.visitAndAutobox(ClassGenerator.java:2639)
at org.codehaus.groovy.classgen.ClassGenerator.visitTupleExpression(ClassGenerator.java:2157)
at org.codehaus.groovy.ast.expr.TupleExpression.visit(TupleExpression.java:86)
at org.codehaus.groovy.classgen.ClassGenerator.visitMethodCallExpression(ClassGenerator.java:1427)
at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:71)
at org.codehaus.groovy.classgen.ClassGenerator.visitAndAutobox(ClassGenerator.java:2639)
at org.codehaus.groovy.classgen.ClassGenerator.visitExpressionStatement(ClassGenerator.java:985)
at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.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.visitCaseStatement(ClassGenerator.java:835)
at org.codehaus.groovy.classgen.ClassGenerator.visitSwitch(ClassGenerator.java:804)
at org.codehaus.groovy.ast.stmt.SwitchStatement.visit(SwitchStatement.java:77)
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)