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

ASF GitHub Bot commented on GROOVY-11929:
-----------------------------------------

eric-milles opened a new pull request, #2472:
URL: https://github.com/apache/groovy/pull/2472

   Java classes as well as Groovy classes with special super types with 
generics (see GROOVY-11929) have abstract methods in the `methodsForSuper` 
index.  These can be discarded, since they are not callable.  This is an 
extension of the culling of bridge and some other methods from this index.
   
   In the test example, the index for `EntityDaoImpl` contains an entry `save: 
["save(T) from AbstractDao", "save(Entity) from EntityDao"]` before 
`MetaClassImpl#replaceWithMOPCalls` runs.  After it runs the index contains 
`save: ["super$2$save(Object) from EntityDaoImpl", "save(Entity) from 
EntityDao"]`.  "save(Entity)" is abstract and is not replaced by a MOP method 
(due to the parameter matching).  So discard it to prevent the runtime error.




> Generic type information erased for super call
> ----------------------------------------------
>
>                 Key: GROOVY-11929
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11929
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.5
>         Environment: Groovy 5.0.5, groovy-eclipse-compiler 3.9.1, 
> groovy-eclipse-batch 5.0.5-01, JDK 21, macOS 26
>            Reporter: Tommi Ratamaa
>            Assignee: Eric Milles
>            Priority: Major
>
> MissingMethodException runtime exception from dynamic invocation when calling 
> super method with parameter type bound by interface and base class generic 
> type.
> Simplified code example (in real case classes and interfaces are not inner 
> but that does not matter) that used to work with Groovy 3, Groovy 4 and also 
> works as Java code with JDK21 or with @CompileStatic, but fails to bind to 
> super method on runtime when compiled with Groovy 5 using dynamic invocation:
> {code:java}
> class GroovyBug {
>     static interface Dao<T> {
>         T save(T entity)
>     }
>     static abstract class AbstractDao<T> implements Dao<T> {
>         T save(T entity) {
>             return entity
>         }
>     }
>     static interface EntityDao extends Dao<Entity> {
>         @Override
>         Entity save(Entity entity)
>     }
>     static class EntityDaoImpl extends AbstractDao<Entity> implements 
> EntityDao {
>         @Override
>         //@CompileStatic // would fix it
>         Entity save(Entity entity) {
>             //return super.save((Object) entity) // would fix it
>             return super.save(entity)
>         }
>     }
>     static class Entity {
>         long id
>     }
>     static void main(String[] args) {
>         new EntityDaoImpl().save(new Entity())
>         /* Exception from save ^ call:
>             groovy.lang.MissingMethodException: No signature of method: save 
> for class: GroovyBug$EntityDaoImpl is applicable for argument types: 
> (GroovyBug$Entity) values: [GroovyBug$Entity@1c05a54d]
>              Possible solutions: save(GroovyBug2$Entity), 
> save(java.lang.Object), save(java.lang.Object), wait(), any(), wait(long)
>              at GroovyBug$EntityDaoImpl.methodMissing(GroovyBug.groovy)
>              at GroovyBug$EntityDaoImpl.save(GroovyBug.groovy:24)
>              at GroovyBug.main(GroovyBug.groovy:33)
>          */
>     }
> }{code}
> The generic type information provided for the implemented interface/base 
> class is erased and argument would need to be casted to Object (as 
> save(java.lang.Object) in possible solutions suggests).
> Also removing the overridden declaration from interface would solve it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to