You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/05/02 02:04:15 UTC

[jira] [Closed] (GROOVY-3395) calling binding variable as function fails to try object's call() method

     [ https://issues.apache.org/jira/browse/GROOVY-3395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-3395.
-----------------------------

> calling binding variable as function fails to try object's call() method
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-3395
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3395
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 1.6
>         Environment: Red Hat Linux 5 with groovy 1.6.0 binary distribution; also reproduced on Debian 5.0
>            Reporter: Jay Berkenbilt
>             Fix For: 2.5.0-alpha-1
>
>         Attachments: GROOVY3395.groovy
>
>
> From a script, if x is a variable in the binding, calling x() appears not to try calling x's call method, at least in some cases.  (It does work for closures, though.)  The following example code illustrates the behavior fully.  When running the code, it catches the MissingMethodException and print "oops -- didn't try c1.call()".
> If this is intended behavior, I'd appreciate an explanation. I apologize if this is known.  I searched JIRA but didn't find anything. I suspect my indentation will not be preserved here...
> {code:Java}
> class Callable
> {
>     Object call()
>     {
>         'Callable.call'
>     }
> }
> Callable c = new Callable()
> assert 'Callable.call' == c()
> def binding = new Binding()
> binding.c1 = c
> binding.c2 = { c() }
> def shell = new GroovyShell(binding)
> try
> {
>     assert 'Callable.call' == shell.evaluate('c1()')
> }
> catch (MissingMethodException)
> {
>     println "oops -- didn't try c1.call()"
> }
> assert 'Callable.call' == shell.evaluate('c1.call()')
> assert 'Callable.call' == shell.evaluate('c2()')
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)