Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.4
-
None
-
None
Description
Given code:
interface ParamInterface{} class ParamImplementation implements ParamInterface{} class ParamExtension extends ParamImplementation {} class A<T extends ParamInterface> { def getResult(T a) { return "A" } } class B<T extends ParamImplementation> extends A<T> { def getResult(T b) { return "B" } } class C extends B<ParamExtension> { @Override def getResult(ParamExtension b) { return super.getResult(b) } } String result = new C().getResult(new ParamExtension()) assert result == "B"
I get output:
Assertion failed: assert result == "B" | | A false at generics_extension_test.run(generics_extension_test.groovy:31)
When calling super method, instead of looking for method in a class one hierarchy bellow, groovy goes through complex calculations for finding a better method. I debug'ed up to a point in
groovy.lang.MetaClassImpl#chooseMostSpecificParams
where it turned out that distance for interface was 2 and distance for class that directly extends the method was much bigger, therefore the method from class A is chosen instead of method from class B. However, looking objectively, it would seem that B.getResult is a much better fit:
C extends B and B extends A
parameter hierarchy is shorter (ParamExtension -> ParamImplementation -> ParamInterface)