You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Lóránt Pintér (Jira)" <ji...@apache.org> on 2022/02/25 23:56:00 UTC

[jira] [Created] (GROOVY-10514) Class method is not called anymore from inside closure

Lóránt Pintér created GROOVY-10514:
--------------------------------------

             Summary: Class method is not called anymore from inside closure
                 Key: GROOVY-10514
                 URL: https://issues.apache.org/jira/browse/GROOVY-10514
             Project: Groovy
          Issue Type: Bug
          Components: syntax
    Affects Versions: 4.0.0
            Reporter: Lóránt Pintér


This code works with Groovy 3.0.9, but doesn't work with 4.0.0:

{code:language=groovy}
class Lajos {
    static void main(String[] args) {
        FileTreeBuilder builder = new FileTreeBuilder()

        builder {
            hello("world")
        }
    }

    static void hello(String param) {
        println "Hello $param!"
    }
}
{code}

Using 3.0.9 the expected result is printed:

{code}
$ ../groovy-3.0.9/bin/groovy script.groovy
Hello world!

$ ls -l
total 8
-rw-r--r--  1 lptr  staff  249 Feb 26 00:45 script.groovy
{code}

Using 4.0.0 instead of calling {{hello()}} the {{methodMissing()}} method is called on {{FileTreeBuilder}} and a file is created.

{code}
$ ../groovy-4.0.0/bin/groovy script.groovy

$ ls -l
total 16
-rw-r--r--  1 lptr  staff    5 Feb 26 00:53 hello
-rw-r--r--  1 lptr  staff  249 Feb 26 00:45 script.groovy

$ cat hello
world
{code}

Same thing happens when {{hello()}} is called from an instance method, and even if {{hello()}} itself is non-static.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)