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

groovyc hangs if a type is declared to extend itself

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.6.5, 1.7-beta-2
    • 1.6.6, 1.7-rc-1
    • Compiler
    • None

    Description

      This code will hang groovyc 1.7beta2:

      class XXX extends XXX {
      }
      

      With stack:

       at org.codehaus.groovy.ast.ClassNode.getUnresolvedSuperClass(ClassNode.java:919)
       at org.codehaus.groovy.ast.ClassNode.getSuperClass(ClassNode.java:913)
       at org.codehaus.groovy.classgen.InnerClassVisitor.getObjectDistance(InnerClassVisitor.java:517)
       at org.codehaus.groovy.classgen.InnerClassVisitor.addDispatcherMethods(InnerClassVisitor.java:378)
       at org.codehaus.groovy.classgen.InnerClassVisitor.visitClass(InnerClassVisitor.java:67)
       at org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:173)
       at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:936)
      

      basically this method loops indefinetly InnerClassVisitor.getObjectDistance():

          private int getObjectDistance(ClassNode node) {
              int count = 1;
              while (node!=null && node!=ClassHelper.OBJECT_TYPE) {
                  count++;
                  node = node.getSuperClass();
              }
              return count;
          }
      

      whereas 1.6.5 prints:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, cyclic inheritance involving XXX in class XXX
      

      This variant will hang 1.6.5 and 1.7b2:

      class XXX extends XXX {
        public static void main(String []argv) {
          print 'hey'
        }
      }
      

      it instead loops indefinetly 'around' this location:

      at java.util.AbstractList.iterator(AbstractList.java:273)
      at java.util.AbstractCollection.toArray(AbstractCollection.java:120)
      at java.util.ArrayList.addAll(ArrayList.java:472)
      at org.codehaus.groovy.ast.ClassNode.getMethods(ClassNode.java:807)
      at org.codehaus.groovy.ast.ClassNode.hasPossibleStaticMethod(ClassNode.java:1169)
      at org.codehaus.groovy.control.StaticImportVisitor.transformMethodCallExpression(StaticImportVisitor.java:189)
      at org.codehaus.groovy.control.StaticImportVisitor.transform(StaticImportVisitor.java:77)
      at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:139)
      at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
      at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
      

      Attachments

        1. 3904_v17x_v1.txt
          2 kB
          Roshan Dawrani
        2. 3904_v17x_v2.txt
          4 kB
          Roshan Dawrani

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: