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

Anonymous subclasses should cast their super-parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.7, 2.5.7
    • 2.5.9, 3.0.0-rc-1
    • None
    • None
    • I tried in GroovyConsole 2.4.7 and Groovy web console 2.5.7

    Description

      Given this code:

          import java.util.regex.Pattern
      
          abstract class Groovy3 {
              Groovy3(String s) { println "String" }
              Groovy3(Pattern p) { println "Pattern" }
          }
      
          class Groovy4 extends Groovy3 {
              Groovy4(String s) { super(s) }
              Groovy4(Pattern p) { super(p) }
          }
      
          class Groovy5 extends Groovy3 {
              Groovy5(String s) { super(s as String) }
              Groovy5(Pattern p) { super(p as Pattern) }
          }
      
          class Groovy6 {
              Groovy6(String s) { println "String" }
              Groovy6(Pattern p) { println "Pattern" }
          }
      
          new Groovy3(null as String) { }
          new Groovy4(null as String)
          new Groovy5(null as String)
          new Groovy6(null as String)
      

      Groovy3ish and Groovy4 instantiation fail
      Groovy5 and Groovy6 instantiation succeed and print String.

      I did not find a way to make the Groovy3ish one work, except for doing it the Groovy4 way, but no chance with an anonymous subclass.

      From what I observed, I guess the anonymous subclass does it like Groovy4 but should do it like Groovy5 to properly select the super constructor.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              vampire Björn Kautler
              Votes:
              0 Vote for this issue
              Watchers:
              3 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 - 1h 40m
                  1h 40m