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

Wrong constructor call generated with AIC + closure usage

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.8.3, 1.9-beta-4
    • None
    • None

    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)
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            blackdrag Jochen Theodorou
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment