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

Creating anonymous class instance fails with some legal code structures

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8-rc-1
    • 1.8.3
    • None
    • None
    • Ubuntu 10.10 Maverick Meerkat, Groovy trunk 2011-03-05T08:00+00:00

    Description

      Attached are three small code examples. One shows that Groovy captures variables fine when using anonymous class creation using new when the expression is part of an assignment. The second shows that using an as expression also enable proper capture of variables when an expression is the return value used in a collect expression. The third shows the failure of Groovy to "do the right thing" in the case of using a new expression in a collect expression. The error returned is:

      Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: fails$1(fails, java.lang.Integer)
      at fails$_run_closure1.doCall(fails.groovy:15)
      at fails.run(fails.groovy:14)

      Current hypothesis is that the fact that the function is (necessarily) called call may be a factor.

      Attachments

        1. works_as.groovy
          0.5 kB
          Dr. Russel Winder
        2. works_array.groovy
          0.7 kB
          Dr. Russel Winder
        3. fails.groovy
          0.6 kB
          Dr. Russel Winder

        Activity

          People

            Unassigned Unassigned
            russel Dr. Russel Winder
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: