groovy
  1. groovy
  2. GROOVY-4633

@InheritConstructors does not work on inner classes

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.5, 1.7.6, 1.8.6
    • Fix Version/s: 2.0-beta-3
    • Component/s: class generator
    • Labels:
    • Environment:
      Tested on Fedora and Windows 7. Both show same issue.
    • Number of attachments :
      1

      Description

      When you use the @InheritConstructors to pull all the constructors of a super class into a subclass this fails to work when it is used on an Inner Class. Below is an example of code that fails with error:

      groovy.lang.GroovyRuntimeException: Could not find matching constructor for: D$F(D, java.lang.Integer)
      

      when you would expect it to run.

      import groovy.transform.InheritConstructors
      
      class A {
          def arg
          A(int arg) {this.arg=arg}
      }
      
      @InheritConstructors //add it here just in case that worked!
      class D {
          class E extends A {
              E(int arg) {super(arg)}
          }
          @InheritConstructors //this should make class F identical to class E
          class F extends A{}
         
          public test() {
              def test1=new E(1) //Works FINE.
              println test1.arg  // prints 1 as expected  
              def test2=new F(1) //throws GroovyRuntimeException here due to missing constructor.
              println test2.arg
          }
      }
      
      def test3=new D()
      test3.test()
      

        Activity

        Hide
        Robin Owens added a comment -

        Sorry - typo in description - exception should be:
        groovy.lang.GroovyRuntimeException: Could not find matching constructor for: D$F(D, java.lang.Integer)

        (The class is D$F no D$E)

        Show
        Robin Owens added a comment - Sorry - typo in description - exception should be: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: D$F(D, java.lang.Integer) (The class is D$F no D$E)
        Hide
        Robin Owens added a comment -

        Code that pasted in issue, but seems to have lost end-of-lines.

        Show
        Robin Owens added a comment - Code that pasted in issue, but seems to have lost end-of-lines.
        Hide
        Paul King added a comment -

        add code tags

        Show
        Paul King added a comment - add code tags
        Hide
        Paul King added a comment -

        This should be working now. For 2.0, part of the logic for handling inner classes (constructor tweaking) was moved until a later phase. AST transforms which add constructors during the SEMANTIC_ANALYSIS or CANONICALIZATION phases can leave handling related to inner class constructors up to the normal compiler phases.

        Show
        Paul King added a comment - This should be working now. For 2.0, part of the logic for handling inner classes (constructor tweaking) was moved until a later phase. AST transforms which add constructors during the SEMANTIC_ANALYSIS or CANONICALIZATION phases can leave handling related to inner class constructors up to the normal compiler phases.
        Hide
        Paul King added a comment -

        adding breaking label - shouldn't break user code, nor most transforms but might impact transforms that play with constructors

        Show
        Paul King added a comment - adding breaking label - shouldn't break user code, nor most transforms but might impact transforms that play with constructors

          People

          • Assignee:
            Paul King
            Reporter:
            Robin Owens
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: