[ https://issues.apache.org/jira/browse/GROOVY-10166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17411978#comment-17411978 ]
Eric Milles commented on GROOVY-10166: -------------------------------------- You can work around the type confusion in the compiler by using a different type parameter name in {{Table}}, like this: {code:groovy} class Table<M extends Model> implements Instanciable<M> { {code} Groovy 2.5.15 is getting {{T}} from {{Model}} and {{T}} from {{Table}} confused. I am checking on Groovy 3.0.9 and 4.0b1 next. > 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)