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

Calling super constructor with in-line casted Closure param does not compile: unexpected "constructor call must be first statement" error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.6
    • 3.0.0-beta-3
    • Compiler
    • None
    • Linux Mint 17.3

    Description

      Running the following code in Groovy Console should result "successfully" with "Could not find matching constructor for 'SomeObject'"

      Instead, code fails with issue "Constructor call must be the first statement in a constructor," which is weird because it is...

      Code only runs correctly (e.g. fails in the expected way) in 5 cases:

      • "{} as BiConsumer" line in the super constructor is commented out
      • all arguments past Closure-cast line must be commented out
      • Closure is cast to a different object (say String)
      • the first "Collections.emptyList()" is changed to a different type (say String) but the second remains the same
      • The BiConsumer's second generic type (Collection<String>) is changed to a different type (say String)
      import java.util.function.BiConsumer
      
      public class ProblematicObject extends SomeObject {
      
          public ProblematicObject() {
              super(
                  { } as BiConsumer<String, Collection<String>>, 
                  
                  Collections.emptyList(),
                  Collections.emptyList()
              )
          }
          
      }
      
      new ProblematicObject()
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            kadblas Jordan Martinez
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: