groovy
  1. groovy
  2. GROOVY-4710

Creating anonymous class instance fails with some legal code structures

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8-rc-1
    • Fix Version/s: 1.8.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 10.10 Maverick Meerkat, Groovy trunk 2011-03-05T08:00+00:00
    • Number of attachments :
      3

      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.

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

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Russel Winder
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: