[
https://issues.apache.org/jira/browse/GROOVY-10166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17568754#comment-17568754
]
Eric Milles commented on GROOVY-10166:
--------------------------------------
https://github.com/apache/groovy/commit/9a988c4f9b9946872f5912cc9c4de3fa2df983ca
https://github.com/apache/groovy/commit/d08e9d69dca43bc0afe1dfa87c63750eb690e482
https://github.com/apache/groovy/commit/e23480c2927083c042abe75921316a6203b6fe0c
> 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
> Components: Static Type Checker
> Affects Versions: 2.5.15, 4.0.0-beta-1, 3.0.9
> Environment: Linux (Ubuntu 20.04)
> Java 11
> Gradle 7.1.1
> Reporter: A. Lepe
> Assignee: Eric Milles
> Priority: Major
> Labels: compile-error
> Fix For: 4.0.0-beta-2, 3.0.11
>
>
> 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.20.10#820010)