Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3395

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6
    • 2.5.0-alpha-1
    • groovy-runtime
    • None
    • 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()')
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ejb@ql.org Jay Berkenbilt
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: