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/02/17 17:03:00 UTC

[jira] [Comment Edited] (GROOVY-10494) Groovy 4 can not compile super.foo with generic interface (or trait) method

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

Eric Milles edited comment on GROOVY-10494 at 2/17/22, 5:02 PM:
----------------------------------------------------------------

Sorry, I may have been unclear when using "this".  I agree this ticket represents an issue for Groovy 4.  The STC error does not give any guidance that "IService.super.save(entity)" is the required form because the interface with default method has been converted to a trait.  Traits do not support plain "super.save(entity)" -- I think that is reserved for calling concrete methods in the super class hierarchy.

If IntelliJ does not recognize "super.save(entity)" when the super-interface is java code, then IntelliJ needs a fix.  A method call of this type works in Groovy 4.  See GROOVY-9909

I referenced Groovy 5 because that is where an interface with default/private/static method(s) could be written natively (like Java 8+) instead of using traits.  See GROOVY-8299


was (Author: emilles):
Sorry, I may have been unclear when using "this".  I agree this ticket represents an issue for Groovy 4.  The STC error does not give any guidance that "IService.super.save(entity)" is the required form because the interface with default method has been converted to a trait.  Traits do not support plain "super.save(entity)" -- I think that is reserved for calling concrete methods in the super class hierarchy.

If IntelliJ does not recognize "super.save(entity)" when the super-interface is java code, then IntelliJ needs a fix.  A method call of this type works in Groovy 4.

I referenced Groovy 5 because that is where an interface with default/private/static method(s) could be written natively (like Java 8+) instead of using traits.  See GROOVY-8299

> Groovy 4 can not compile super.foo with generic interface (or trait) method
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-10494
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10494
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.0
>            Reporter: Xiaoguang Wang
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: image-2022-02-17-10-53-45-797.png, image-2022-02-17-10-56-36-832.png
>
>
> {code:java}
> package com.company.test
> import groovy.transform.CompileStatic
> @CompileStatic
> interface IService<T> {
>     default void save(T entity) {
>         System.out.println(entity);
>     }
> }
> @CompileStatic
> interface IServiceString {
>     default void save(String entity) {
>         System.out.println(entity);
>     }
> }
> @CompileStatic
> class TestGenericGroovy implements IService<String> {
>     void save(String entity) {
>         // IService<String>.super.save(entity) // works
>         super.save(entity) // doesn't work: Groovyc: [Static type checking] - Abstract method save(T) cannot be called directly
>     }
>     static void main(String[] args) {
>         new TestGenericGroovy().save("test")
>     }
> }
>  {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)