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 2021/12/03 20:51:00 UTC

[jira] [Resolved] (GROOVY-9909) Cannot call super when overriding an interface default method

     [ https://issues.apache.org/jira/browse/GROOVY-9909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-9909.
---------------------------------
    Fix Version/s: 4.0.0-rc-2
       Resolution: Fixed

https://github.com/apache/groovy/commit/a63ee5e26023dd22db81834d7134053bd566f441

> Cannot call super when overriding an interface default method
> -------------------------------------------------------------
>
>                 Key: GROOVY-9909
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9909
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 2.5.14
>            Reporter: Mauro Molinari
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: default-methods
>             Fix For: 4.0.0-rc-2
>
>
> Suppose you have:
> {code:java}
> public interface MyInterface {
>   default String getFoo() { return "foo"; }
> }
> {code}
> and a Groovy class implementing it:
> {code:groovy}
> @CompileStatic
> class MyClass implements MyInterface {
>   @Overridde
>   String getFoo() {
>     return MyInterface.super.getFoo();
>   }
> }
> {code}
> This produces multiple compiler errors, like:
> {noformat}
> - Groovy:[Static type checking] - No such property: super for class: java.lang.Class <MyInterface>
> - Groovy:The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes
> {noformat}
> If I replace it with:
> {code:groovy}
> @CompileStatic
> class MyClass implements MyInterface {
>   @Overridde
>   String getFoo() {
>     return super.getFoo();
>   }
> }
> {code}
> I get:
> {noformat}
> Groovy:[Static type checking] - Cannot find matching method java.lang.Object#getFoo(). Please check if the declared type is correct and if the method exists
> {noformat}
> I find no way to properly override a default method while calling the super implementation.



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