Groovy
  1. Groovy
  2. GROOVY-3395

calling binding variable as function fails to try object's call() method

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: 2.5.0-beta-1
    • Component/s: groovy-runtime
    • Labels:
      None
    • Environment:
      Red Hat Linux 5 with groovy 1.6.0 binary distribution; also reproduced on Debian 5.0

      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()')
      

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jay Berkenbilt
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development