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

@CompileStatic non-static inner class instantiation in closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.4, 2.4.0, 2.5.0, 3.0.0
    • 4.0.0-alpha-1, 3.0.5, 2.5.13
    • None
    • None

    Description

      Script:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Test {
          final String test = 'test-'
      
          List<String> test() {
              ['val'].collect {String s ->
                  return new InnerTest(s).val
              }
          }
      
          class InnerTest {
              final String val
              InnerTest(String val) {
                  this.val = test + val
              }
          }
      }
      
      println(new Test().test())
      

      Result:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      ideaGroovyConsole.groovy: 9: [Static type checking] - Cannot find matching method Test$InnerTest#<init>(groovy.lang.Closure <V extends java.lang.Object>, java.lang.String). Please check if the declared type is correct and if the method exists.
       @ line 9, column 20.
                     return new InnerTest(s).val
                            ^
      
      1 error
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:287)
      	at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:963)
      and so on...
      

      Attachments

        Activity

          People

            emilles Eric Milles
            Eliak Aleksey
            Votes:
            0 Vote for this issue
            Watchers:
            2 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 - 0.5h
                0.5h