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

Multiple traits with related generic types cannot be used

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.0
    • 4.0.24
    • Compiler
    • None
    • Patch, Important

    Description

      When updating Grails from Groovy 3.x to 4.x we discovered that GROOVY-5106 prevents us from updating to Groovy 4 for the grails-data-mapping (GORM) project.  Groovy-5106 does not take into account relationships between generic types and groovy does not support inheritance in generic types on traits so we have no workable solution for using Groovy 4.

       

      For example, the following is not possible in Groovy 4:

      class Parent extends GormEntity<Parent> {
      
      }
      
      class Child extends GormEntity<Child> {
      
      } 
      
      class GormEntity<? extends GormEntity> { // ? extends GormEntity is not allowed
      
      }

       

      We have documented the impacts of this issue on the grails-data-mapping project here:  https://github.com/grails/grails-data-mapping/issues/1811   We have discovered that the original change could be reverted and continue to work with the latest Java & Groovy. 

       

      For Grails Data Mapping (GORM), there is support for inheritance between a Parent & Child domain object.  This is often implemented like this:

      class Parent extends GormEntity<Parent> {
      
      }
      
      class Child extends GormEntity<Child> {
      
      }
      
      trait GormEntity<D> { // Simplified for this ticket
          static D get(Serializable id)
         
          static List<D> getAll()
      }
       

      This allows someone to do the following in code:

      Parent.get(1L) // Will find either a Child or Parent
      Child.get(1L) // Will find only child types

       

      Since Groovy-5106 does not take into account inheritance, can this change be reverted or changed to a warning until inheritance is taken into account?

      Attachments

        1. screenshot-3.png
          15 kB
          Eric Milles
        2. screenshot-2.png
          19 kB
          Eric Milles
        3. screenshot-1.png
          16 kB
          Eric Milles

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            emilles Eric Milles
            jdaugherty James Daugherty
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment