groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernando Ariel Niwes Naufal <ferna...@soluciones3f.com.ar>
Subject Issue with methodMissing using a innerClass as closure delegate
Date Mon, 27 Jul 2015 12:07:54 GMT
I am not sure if the following code should, or should not work. As right
now, with Groovy Version: 2.4.3 JVM: 1.8.0_31 Vendor: Oracle Corporation
OS: Mac OS X does not.

    class OuterClass {
        class DelegateClass {
            def calls = [:]
            def methodMissing(String value, args) { calls[value] = args;
return this }
        }

        def run() {
            def closure = { method1 'calling1' method2 'calling2' }

            def delegate = new DelegateClass()
            closure.delegate = delegate
            closure()

            return delegate.calls
        }
    }

    assert new OuterClass().run() == [method1: ['calling1'], method2:
['calling2']]

The same code, but with DelegateClass as a independent class does works
correctly.
Even more, if I replace methodMissing with two methods called method1, and
method2 does works correctly too.

Seems like a bug to me (specially because it fails only with methodMissing)
but I am not sure.

Mime
View raw message