Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.6
-
Fix Version/s: 3.0
-
Component/s: None
-
Labels:None
-
Environment:Red Hat Linux 5 with groovy 1.6.0 binary distribution; also reproduced on Debian 5.0
-
Number of attachments :
Description
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...
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()')
Yes, my formatting was completely mangled. I'm also going to attach the code. (Is there a way to prevent JIRA from doing this?)