You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "mgroovy (Jira)" <ji...@apache.org> on 2021/03/04 17:20:00 UTC
[jira] [Created] (GROOVY-9965) Static generic method hiding method
of same name leads to MME
mgroovy created GROOVY-9965:
-------------------------------
Summary: Static generic method hiding method of same name leads to MME
Key: GROOVY-9965
URL: https://issues.apache.org/jira/browse/GROOVY-9965
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 2.5.14
Environment: Windows 10
jdk-11.0.10.9-hotspot
IntelliJ 2020.3.2
Reporter: mgroovy
*Problem*
Executing the test from the sample below throws:
{code:java}
groovy.lang.MissingMethodException: No signature of method: static simple.groovy.bugs.gb_2021_03_04.TableGeneric.reference() is applicable for argument types: (String) values: [FOO_schema]{code}
even though TableGeneric's base class Table has a public method with signature:
{code:java}
Table reference(String){code}
It seems this method is hidden by the static Table method:
{code:java}static <T extends Table> T reference(T table){code}
*Expected*
Table#reference(String) should be called inside TableGeneric#reference() .
*Sample Code*
{code:java}
import org.junit.Ignore
import org.junit.Test
class GroovyBugs_2021_03_04 {
@Test
@Ignore
void 'Groovy 2-5-14 TableGeneric#reference() MissingMethodException'() {
final TableGeneric tableGeneric = new TableGeneric("FOO")
println tableGeneric.reference()
}
}
{code}
{code:java}
import groovy.transform.Canonical
@Canonical
class Table {
final String name = "defaultTable"
Table reference(String schema) {
println "${this.getClass().simpleName}#reference(schema): schema=$schema"
return this
}
// Commenting out this static method gets rid of the error
static <T extends Table> T reference(T table) {
println "Table.reference(table): table=$table"
assert null != table
return table
}
}
{code}
{code:java}
import groovy.transform.InheritConstructors
@InheritConstructors
class TableGeneric extends Table {
// If this method takes an argument, the error disappears
TableGeneric reference() {
println "${this.getClass().simpleName}#reference(): name=$name"
final String schema = "${name}_schema"
/*
Passing schema = null leads to
Table.reference(T table) being
called with table=null
*/
return (TableGeneric) super.reference(schema)
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)