groovy
  1. groovy
  2. GROOVY-5000

Wrong constructor call generated with AIC + closure usage

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      This issue is raised based on dev mailing list discussion here: http://markmail.org/message/ksngkezqgqazpz5q

      Here are the code snippets that demonstrate the issue with constructor call generation when anonymous inner classes and closure are used together.

      1)

      interface X{}
      
      final double delta = 0.1
      (0 ..< 1).collect { n ->
          new X () {
              Double foo () {
                  delta
              }
          }
      }
      

      fails with

      Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: TryGroovy$1(TryGroovy, java.lang.Double)
      

      2) Seems like there is some mix-up with the variables used from the enclosing context. In this snippet, I use 2 variables from enclosing context, and both become part of constructor call that fails.

      interface X{}
      
      final double delta1 = 0.1
      final double delta2 = 0.1
      (0 ..< 1).collect { n ->
          new X () {
              Double foo () {
                  delta1 + delta2
              }
          }
      }
      

      fails with:

      Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: TryGroovy$1(TryGroovy, java.lang.Double, java.lang.Double)
      

        Activity

        Hide
        blackdrag blackdrag added a comment -

        fixed

        Show
        blackdrag blackdrag added a comment - fixed
        Hide
        Russel Winder added a comment -

        I just pulled and reinstalled, but I still get the errant behaviour

        Show
        Russel Winder added a comment - I just pulled and reinstalled, but I still get the errant behaviour
        Hide
        Russel Winder added a comment -

        Experiment shows that Roshan's code highlights a bug that has been present in 1.8.0, 1.8.1 and 1.8.2 but is now fixed in HEAD. The problem I am having with my Pi_Quadrature codes is not present in 1.8.0 and 1.8.1, but is present in 1.8.2 and remain in HEAD after this fix commit. The hypothesis must be that the problem in Pi_Quadrature is in fact different from these small tests which have highlighted a bug we didn't know we had!

        I'll see if I can trim one of my programs to something different than the above that shows the fault and create a new issue. This issue is quite properly closed.

        Show
        Russel Winder added a comment - Experiment shows that Roshan's code highlights a bug that has been present in 1.8.0, 1.8.1 and 1.8.2 but is now fixed in HEAD. The problem I am having with my Pi_Quadrature codes is not present in 1.8.0 and 1.8.1, but is present in 1.8.2 and remain in HEAD after this fix commit. The hypothesis must be that the problem in Pi_Quadrature is in fact different from these small tests which have highlighted a bug we didn't know we had! I'll see if I can trim one of my programs to something different than the above that shows the fault and create a new issue. This issue is quite properly closed.
        Hide
        Russel Winder added a comment -

        The continuation issue is GROOVY-5006.

        Show
        Russel Winder added a comment - The continuation issue is GROOVY-5006 .

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: