You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/07/19 21:53:00 UTC
[jira] [Updated] (GROOVY-10166) Cannot call T#method(arg) with arguments
[ https://issues.apache.org/jira/browse/GROOVY-10166?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-10166:
---------------------------------
Fix Version/s: 3.0.11
> 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)