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

Eric Milles commented on GROOVY-10166:
--------------------------------------

Both STC errors are reproduced in this smaller example (Groovy 2.5.15, 3.0.9 
and 4.0b1):
{code:groovy}
import groovy.transform.CompileStatic

@CompileStatic
abstract class A<T extends C> {
  T getC() {
  }
  Map toMap() {
    c.getMap(this)
  }
}

@CompileStatic
class C<T extends A> {
  Map getMap(T a) {
  }
  T setMap(Map m) {
    A a = null
    a.c.get(1)
  }
  T get(int i) {
    setMap([:])
  }
}
{code}

> Cannot call T#method(arg) with arguments <arg>
> ----------------------------------------------
>
>                 Key: GROOVY-10166
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10166
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.8
>         Environment: Linux (Ubuntu 20.04)
> Java 11
> Gradle 7.1.1
>            Reporter: A. Lepe
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: compile-error, compilestatic
>
> I'm unable to compile [my OSS project|https://gitlab.com/intellisrc/common] 
> under 3.0.8, it is throwing this error:
> {quote}startup failed:
>  
> [modules/db/src/main/groovy/com/intellisrc/db/Model.groovy|https://gitlab.com/intellisrc/common/-/blob/master/modules/db/src/main/groovy/com/intellisrc/db/Model.groovy#L76]:76:
>  [Static type checking] - Cannot call T#getMap(T) with arguments 
> [com.intellisrc.db.Model <T extends com.intellisrc.db.Table>] 
>  @ line 76, column 16.
>  return table.getMap(this)
>  ^
> [modules/db/src/main/groovy/com/intellisrc/db/Table.groovy|https://gitlab.com/intellisrc/common/-/blob/master/modules/db/src/main/groovy/com/intellisrc/db/Table.groovy#L261]:261:
>  [Static type checking] - Cannot call T#get(int) with arguments [int] 
>  @ line 261, column 42.
>  type[origName] = refType.table.get(it.value as int)
> ^
> 2 errors
> {quote}
> (clicking on the links above will take you to the source code)
> I prepared a (mutilated) simplified project to replicate the issue:
> [https://gitlab.com/intellisrc/groovy-compile-error]
> Here is the relevant code:
> _Model.groovy_
> {code:java}
> // code placeholder
> @CompileStatic
> abstract class Model<T extends Table> implements Instanciable<T> {
>     T getTable() {
>         return getParametrizedInstance()
>     }
>     Map<String, Object> toMap() {
>         return table.getMap(this)
>     }
> }{code}
>  _Table.groovy_
> {code:java}
> @CompileStatic
> class Table<T extends Model> implements Instanciable<T> {
>     Map<String, Object> getMap(T type) {
>         return [:]
>     }
>     T setMap(Map<String, Object> map) {
>         T type = parametrizedInstance
>         map.each {
>             String origName = it.key
>             Field field = null // some field
>             if(field) {
>                 switch (field.type) {
>                     case Model:
>                         Constructor<?> c = field.type.getConstructor()
>                         Model refType = (c.newInstance() as Model)
>                         type[origName] = refType.table.get(it.value as int)
>                         break
>                 }
>             }
>         }
>         return type
>     }
>     T get(int id) {
>         T type = setMap([:])
>         return type
>     }
> }
> {code}
> _Instanciable.groovy_
> {code:java}
> @CompileStatic
> trait Instanciable<T> {
>     T getParametrizedInstance(int index = 0) {
>         T obj = null
>         try {
>             ParameterizedType parameterizedType = 
> this.class.genericSuperclass as ParameterizedType
>             Class type = (Class) parameterizedType.actualTypeArguments[index]
>             obj = (T) type.getDeclaredConstructor().newInstance()
>         } catch(Exception ignore) {}
>         return obj
>     }
> }
> {code}
> *NOTES:*
>  * There are no issues when compiled in a lower version : 2.5.6 to 2.5.14, 
> 3.0.0 to 3.0.7.
>  * Using `@CompileStatic` in all classes
> Perhaps there is an error in my code which other versions didn't catch? 
> However the code runs as expected when compiled.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to