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

Better error message in the presence of Generics arity errors

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.7
    • 2.5.0-alpha-1
    • None
    • None

    Description

      Currently there are many places in the codebase which make assumptions that they are working with valid generics information. Generics information is checked but not until the classgen phase. Consequently, we get a very uninformative ArrayIndexOutOfBoundsException from the compiler - either along with or instead of the subsequent generics checking. These are all examples which should fail compilation since I have intentionally tried to instantiate the generics type with an incorrect number of parameters. It is just the error message which is not currently useful and masking the subsequent message that would occur had not the exception got in the way.

      Example with TraitComposer:

      class MyNames implements Queue<Integer, String> { }
      // java.lang.ArrayIndexOutOfBoundsException: 1
      // TraitComposer calls GenericsUtils.parameterizeType()
      // which calls GenericsUtils.createGenericsSpec()
      

      Example with StaticTypeCheckingVisitor:

      @CompileStatic
      def foo() {
        List<String> ss = new LinkedList<Integer, String>()
      }
      // => java.lang.ArrayIndexOutOfBoundsException: 1
      

      Example with Verifier:

      class MyNames extends Queue<Integer, String> { }
      

      which gives

      2 compilation errors:
      The class java.util.Queue refers to the class java.util.Queue and uses 2 parameters, but the referred class needs 1
       at line: 5, column: 23
      Exception thrown
      java.lang.ArrayIndexOutOfBoundsException: 1
      	at org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec(GenericsUtils.java:410)
      

      So we get one error from the generics checking but then continue on to the Verifier.

      I suspect the fix for this is to move just the arity checking part of that visitor to an earlier phase.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              paulk Paul King
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: