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

Static Compilation fails when using generics (no such property)

    XMLWordPrintableJSON

Details

    Description

      Hi,

      The code below works fine with 3.0.19 but after upgrading to 3.0.20 it doesn't compile anymore:

      import groovy.transform.CompileStatic
      import org.springframework.data.domain.Pageable
      import org.springframework.data.mongodb.repository.MongoRepository
      
      @CompileStatic
      class GalleryItem {
          String someProperty
      }
      
      @CompileStatic
      interface GalleryItemRepository extends MongoRepository<GalleryItem, String> {
      }
      
      @CompileStatic
      static void main(String[] args) {
          GalleryItemRepository repository = null //no implementation for the sake of simplicity
          def page = repository.findAll(Pageable.ofSize(1))
      
          page.content.each {
              it.someProperty //[Static type checking] - No such property: someProperty for class: java.lang.Object
          }
      } 

      My build.gradle

      plugins {
          id 'groovy'
      }
      
      group = 'org.example'
      version = '1.0-SNAPSHOT'
      
      repositories {
          mavenCentral()
      }
      
      dependencies {
          //works fine with 3.0.19
          implementation 'org.codehaus.groovy:groovy-all:3.0.20'
          implementation 'org.springframework.data:spring-data-mongodb:3.4.18'
      }
      
      compileJava {
          sourceCompatibility = JavaVersion.VERSION_21
          targetCompatibility = JavaVersion.VERSION_21
      }
      
      compileGroovy {
          groovyOptions.optimizationOptions.indy = true
      }

      A simple "gradle compileGroovy" should reproduce the issue:

      /Projects/groovytest/src/main/groovy/Main.groovy: 20: [Static type checking] - No such property: someProperty for class: java.lang.Object
       @ line 20, column 9.
                 it.someProperty //[Static type checking] - No such property: someProperty for class: java.lang.Object
                 ^ 

       

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              rodolfo.yanke Rodolfo Yanke
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: