Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.7
-
None
Description
Consider following code:
@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 { }
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(...).
Attachments
Issue Links
- relates to
-
GROOVY-11242 Stackoverflow error when calling super from overridden method
- Closed