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

Stub missing cast, depending on constructor order

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

Details

    Description

       

      package org.apache.groovy.tests
      class Parent {
          Parent(Object context) {
              this(context.class.name)
          }
          Parent(Class<?> context) {
              this(context.name)
          }
          Parent(String context) {}
      }
      class Child extends Parent {
          Child() {
              super(Child.class.name)
          }
      }
      

      Generates this stub for Child, missing the cast in the constructor

      package org.apache.groovy.tests;
      import java.lang.*;
      import java.util.*;
      import java.io.*;
      import java.net.*;
      import groovy.lang.*;
      import groovy.util.*;
      
      public class Child
        extends org.apache.groovy.tests.Parent {
      ;
      public Child
      () {
      super (null);
      }
      @groovy.transform.Generated() @groovy.transform.Internal() @java.beans.Transient() public  groovy.lang.MetaClass getMetaClass() { return (groovy.lang.MetaClass)null;}
      @groovy.transform.Generated() @groovy.transform.Internal() public  void setMetaClass(groovy.lang.MetaClass mc) { }
      }
      

      Which causes the Java compilation to fail

      Child.java:[14,1] reference to Parent is ambiguous
         both constructor Parent(java.lang.Class<?>) in org.apache.groovy.tests.Parent and constructor Parent(java.lang.String) in org.apache.groovy.tests.Parent match
      

       

      But 

      package org.apache.groovy.tests
      class Parent {
          Parent(Class<?> context) {
              this(context.name)
          }
          Parent(String context) {}
          Parent(Object context) {
              this(context.class.name)
          }
      }
      class Child extends Parent {
          Child() {
              super(Child.class.name)
          }
      }
      

      Generates this stub for Child, with the cast in it

      package org.apache.groovy.tests;
      import java.lang.*;
      import java.util.*;
      import java.io.*;
      import java.net.*;
      import groovy.lang.*;
      import groovy.util.*;
      
      public class Child
        extends org.apache.groovy.tests.Parent {
      ;
      public Child
      () {
      super ((java.lang.Class)null);
      }
      @groovy.transform.Generated() @groovy.transform.Internal() @java.beans.Transient() public  groovy.lang.MetaClass getMetaClass() { return (groovy.lang.MetaClass)null;}
      @groovy.transform.Generated() @groovy.transform.Internal() public  void setMetaClass(groovy.lang.MetaClass mc) { }
      }
      

      Attachments

        Activity

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

          People

            emilles Eric Milles
            keegan Keegan Witt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0h
              0h
              Logged:
              Time Spent - 50m
              50m

              Slack

                Issue deployment