Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4252

Invalid code crashes the compiler

    XMLWordPrintableJSON

    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

      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)
      

        Attachments

        1. 4252_v17x.patch
          2 kB
          Roshan Dawrani

          Activity

            People

            • Assignee:
              roshandawrani Roshan Dawrani
              Reporter:
              aclement Andy Clement
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: