Hannes Greule created GROOVY-10897:
--------------------------------------

             Summary: Static Type Checking selects wrong method for abstract 
method call check
                 Key: GROOVY-10897
                 URL: https://issues.apache.org/jira/browse/GROOVY-10897
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 4.0.7
            Reporter: Hannes Greule


Consider following code:
{code:java}
@CompileStatic
class E extends BImpl {
    @Override
    void a() {
        super.a();
    }
    static void main(args) { }
}
interface A {
    void a()
}
interface B extends A {
    @Override
    void a()
}
class AImpl implements A {
    @Override
    void a() {
    }
}
class BImpl extends AImpl implements B {
} {code}
Compiling it will fail with the error 
{{{}[Static type checking] - Abstract method a() cannot be called directly

{}}}However, when running it _without_ {{@CompileStatic}} or when writing 
similar code in Java, it will select the non-abstract method from {{AImpl}} 
instead.

It seems like this is a problem in the code to choose the best method here: 
[https://github.com/apache/groovy/blob/ea6ba7c6fcfefe3d8abdfbb6e20a44b1ebb8823e/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1091]

The distance from {{BImpl}} to {{B}} to the interface is less than (1) the 
distance to {{AImpl}} (4), therefore the abstract method is chosen as best 
method.

This originally happened when extending {{AbstractSet}} and calling 
{{{}super.addAll(...){}}}.



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

Reply via email to