Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.3.11, 2.4.13, 2.5.0-rc-3
-
None
Description
There is currently a maximum hierarchical depth for childclasses when using compile static.
The compiler only searches for method parameters that match the provided class or up to 29 super classes. This in return means that the usable hierarchical depth is limited 29 child classes/distance from the root.
Without CompileStatic this limit does not exists. Changing the following code to Java works too.
This Code:
import groovy.transform.CompileStatic @CompileStatic class StaticTest { public static int getNummer( ZClassDepth0 instance ) { return instance.depth } public static void main( String[] args ) { println getNummer( new ZClassDepth29() ) //works println getNummer( new ZClassDepth30() ) //doesn't work } }
fails with the following execption:
Error:(13, 15) Groovyc: [Static type checking] - Cannot find matching method StaticTest#getNummer(ZClassDepth30). Please check if the declared type is right and if the method exists.
How the "ZClassDepth" files where generated:
import java.nio.file.Paths class Generator { public static void main( String[] args ) { def template = { int nummer -> return """\ public class ZClassDepth${ nummer } ${ nummer > 0 ? "extends ZClassDepth${ nummer - 1 }" : '' } { ${ nummer > 0 ? '@Override' : '' } public int getDepth() { return $nummer } } """ } def path = Paths.get( '[PATH_TO_SOURCE]/src' ) 101.times{ i -> new File( path.toFile(), "ZClassDepth${i}.groovy" ).text = template( i ) } } }