Octavia Togami created GROOVY-12188:
---------------------------------------

             Summary: Incorrect "abstract method not implemented … same name 
but different return type" error for a valid covariant override
                 Key: GROOVY-12188
                 URL: https://issues.apache.org/jira/browse/GROOVY-12188
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 5.0.7
            Reporter: Octavia Togami


The following code in a `Repro.groovy` will cause the error:

{code:groovy}
abstract class ProviderSpec<T> {
    abstract T someValue()
}

abstract class CollectionPropertySpec<C extends Collection<String>> extends 
ProviderSpec<C> {
    C someValue() { return null }

    static class Nested<T> {
        // This method is required to trigger the bug, for some reason.
        void trigger(Optional<T> p) { p.map { it } }
    }
}

class DefaultListPropertyTest extends CollectionPropertySpec<List<String>> {
}
{code}

{code:sh}
$ groovyc Repro.groovy 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Repro.groovy: 2: Abstract method 'T someValue()' is not implemented but a 
method of the same name but different return type is defined: method 'C 
someValue()'
 @ line 2, column 5.
       abstract T someValue()
       ^

1 error
{code}

This worked fine in Groovy 4 and appears to be correct code as it compiles 
under {{javac}} as well.

This was shrunk from real code in Gradle, located at 
https://github.com/gradle/gradle/blob/adbe2eb8a092ed6f92ea3d693d32769b553151e9/platforms/core-configuration/model-core/src/test/groovy/org/gradle/api/internal/provider/CollectionPropertySpec.groovy#L49
 .



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

Reply via email to