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

Goorvy 3 Compilation Failure issue with Generics and same type argument name

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.1, 3.0.2, 3.0.3
    • None
    • Static compilation
    • None

    Description

      While upgrading GORM for Neo4j to support Groovy 3, we are seeing an issue with generics as:

      [Static type checking] - Cannot return value of type grails.neo4j.Path$Segment <S, E> on method returning type T
       @ line 81, column 16.
       return end
       ^
      
      1 error
      

       

      I believe the problem is with using same name of type argument in the Generics for multiple classes as in the following code:

      import groovy.transform.CompileStatic
      import java.util.function.Consumer
      
      @CompileStatic
      abstract class Path<F extends Neo4jEntity, T extends Neo4jEntity> implements Iterable<Segment<F,T>> {
      
          T end
      
          interface Segment<F, T> {
              F start()
      
              T end()
          }
      
          abstract F start()
          T end() {
              return end
          }
      
          @Override
          void forEach(Consumer<? super Segment<F, T>> action) { }
      
          @Override
          Spliterator<Segment<F, T>> spliterator() {
              return null
          }
      
          @Override
          Iterator<Segment<F, T>> iterator() {
              return null
          }
      }
      
      trait Neo4jEntity<D> {
      
      }
      
      println GroovySystem.version
      
      

      Please note that If we replace `F` and `T` in the above code with `S` and `E` the code will compile successfully.

       

      Attachments

        Activity

          People

            emilles Eric Milles
            behlp Puneet Behl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: