Calling a closure from another when using @CompileStatic

182 Views Asked by At

When implicit calling a closure from another closure under @CompileStatic, the caller somehow goes into a recursive loop. Can you spot an issue with the code, or is this an issue with Groovy:

import groovy.transform.CompileStatic

@CompileStatic
class Main {
    static main(args) {
        TestClass testclass = new TestClass()
        testclass.foo()
        //testclass.bar() // compile error for closure with @CompileStatic 
        testclass.bar.call()  // compiles and works fine
    }
}

@CompileStatic
class TestClass {
    void foo () {
        println('In foo')
        bar() // inside a method -- works fine
    }

    Closure bar = {
        println('In bar')
        //baz() // What's going on here?? It compiles, but instead
        //         of calling baz, this recurses on itself (seemingly)
        baz.call() // this works fine
    }

    Closure baz = {
        println('In baz')
    }
}

[Groovy Version: 2.4.5]

Note: This SO question discusses a similar problem, but the Groovy issue related to it says it has been fixed.

0

There are 0 best solutions below