[ 
https://issues.apache.org/jira/browse/GROOVY-11411?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17856503#comment-17856503
 ] 

Tyler VanZanten commented on GROOVY-11411:
------------------------------------------

Oops! In the body of this issue I accidentally posted my workaround code that 
avoids the error being thrown. The line which is causing the issue is:

{{SessionItemGroup.getAll(longIds)}}

 

Thankfully, [~paulk]  posted both lines (explicitly casting {{longIds}} and not 
casting it) in his example code.

 
{quote}List<Long> is not an Iterable<Serializeable>. The type argument is 
invariant.
{quote}
According to [~emilles]' statement above, the issue I reported appears not be a 
Groovy bug, correct? If I'm understanding things correctly, in order for future 
versions of Grails (6.2.1+) to behave like it did in earlier versions (before 
6.2.0), these method signatures in the grails-data-mapping repository would 
need to be changed to:

List<D> getAll(Iterable<? extends Serializable> ids)

 

[https://github.com/grails/grails-data-mapping/blob/c53c008350ffec8e24a68eebb302288ca5283ea6/grails-datastore-gorm/src/main/groovy/grails/gorm/api/GormStaticOperations.groovy#L136]

 

[https://github.com/grails/grails-data-mapping/blob/c53c008350ffec8e24a68eebb302288ca5283ea6/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy#L585]

 

[https://github.com/grails/grails-data-mapping/blob/c53c008350ffec8e24a68eebb302288ca5283ea6/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/multitenancy/TenantDelegatingGormOperations.groovy#L265]

 

[https://github.com/grails/grails-data-mapping/blob/c53c008350ffec8e24a68eebb302288ca5283ea6/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormStaticApi.groovy#L377]

 

> Static Compilation fails for Grails domain class method getAll()
> ----------------------------------------------------------------
>
>                 Key: GROOVY-11411
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11411
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 3.0.21
>            Reporter: Tyler VanZanten
>            Priority: Minor
>
> Hello,
>  
> The following code results in a static compilation error after upgrading from 
> Grails 6.1.2 (which uses Groovy 3.0.11) to Grails 6.2.0 (which uses Groovy 
> 3.0.21):
>  
>  
> {code:java}
> import grails.compiler.GrailsCompileStatic
> import static org.springframework.http.HttpStatus.NO_CONTENT
> @GrailsCompileStatic
> class SessionItemGroupController {
>     def deleteMultiple() {
>         List<Long> longIds = ((String) params.ids)?.split(',')?.collect { 
> String id -> id.toLong() }           
>         List<SessionItemGroup> sessionItemGroups = 
> SessionItemGroup.getAll(longIds as Iterable<Serializable>) // This line 
> causes the error            
>         response.status = NO_CONTENT.value()    
>     }
> }{code}
>  
>  
> SessionItemGroup is a Grails domain class and this is the error I'm getting 
> when trying to run a Gradle task such as `bootRun` or `build`:
>  
> ```
> > Task :compileGroovy FAILED
> startup failed:
> grails-app/controllers/myapp/sessionitem/SessionItemGroupController.groovy: 
> 57: [Static type checking] - Cannot call 
> myapp.sessionitem.SessionItemGroup#getAll(java.lang.Iterable 
> <java.io.Serializable>) with arguments [java.util.List <java.lang.Long>]
> @ line 41, column 56.
> temGroup> sessionItemGroups = SessionIte
> ```
>  
> I have created a sample application repository which reproduces the issue:
> https://github.com/tylervz/grails620-groovy-bug-compile-static



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to