Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.3
-
Fix Version/s: 1.7.4, 1.8-beta-1
-
Component/s: Compiler
-
Labels:None
-
Environment:Windows 7
-
Number of attachments :
Description
This code:
class Crasher {
public void m() {
def fields = [1,2,3]
def expectedFieldNames = ["patentnumber", "status"].
for (int i=0; i<fields.size(); i++) {
Object f = fields[i]
System.out.println(f);
}
}
}
is not valid (I believe?). There is an extraneous '.' on the end of the second 'def' line. Instead of a nice error message about having done something wrong, we get this stack on compilation:
>>> a serious error occurred: BUG! exception in phase 'class generation' in source unit 'Crasher.groovy' tried to get a variable wit h the name i as stack variable, but a variable with this name was not created >>> stacktrace: BUG! exception in phase 'class generation' in source unit 'Crasher.groovy' tried to get a variable with the name i as stack variable , but a variable with this name was not created at org.codehaus.groovy.classgen.CompileStack.getVariable(CompileStack.java:263) at org.codehaus.groovy.classgen.AsmClassGenerator.visitClosureExpression(AsmClassGenerator.java:1759) at org.codehaus.groovy.ast.expr.ClosureExpression.visit(ClosureExpression.java:46) at org.codehaus.groovy.classgen.AsmClassGenerator.visitAndAutoboxBoolean(AsmClassGenerator.java:4071) at org.codehaus.groovy.classgen.AsmClassGenerator.makeCallSite(AsmClassGenerator.java:2147) at org.codehaus.groovy.classgen.AsmClassGenerator.makeCall(AsmClassGenerator.java:1984) at org.codehaus.groovy.classgen.AsmClassGenerator.makeCall(AsmClassGenerator.java:1970) at org.codehaus.groovy.classgen.AsmClassGenerator.makeInvokeMethodCall(AsmClassGenerator.java:1953) at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:2300) at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:72) at org.codehaus.groovy.classgen.AsmClassGenerator.visitAndAutoboxBoolean(AsmClassGenerator.java:4071) at org.codehaus.groovy.classgen.AsmClassGenerator.assignmentCastAndVisit(AsmClassGenerator.java:4012) at org.codehaus.groovy.classgen.AsmClassGenerator.evaluateEqual(AsmClassGenerator.java:3962) at org.codehaus.groovy.classgen.AsmClassGenerator.visitDeclarationExpression(AsmClassGenerator.java:1442) at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:53) at org.codehaus.groovy.classgen.AsmClassGenerator.visitAndAutoboxBoolean(AsmClassGenerator.java:4071) at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:1430) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
Looked a bit into it and I have a few questions.
1) Should the following compile
2) What is a ClosureListExpression? Is it of use outside for loops? In what kind of code? For def x = (1;2;3), do multiple closures get generated?
The AST for the JIRA example takes the form def expectedFieldNames = [].for(ClosureListExpression)
{for loop body as a ClosureExpression}, and then ACG runs into this BUG because for variable i, no variable is declared because it is not really treated as a for loop here but separate scope ClosureListExpression and ClosureExpression.