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

STC error for call to static trait method from closure

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.14
    • Fix Version/s: 4.0.0-beta-1, 3.0.9
    • Component/s: None
    • Labels:
      None

      Description

      The following code fails to compile:

      class Foo {
          String bar
      }
      @groovy.transformn.CompileStatic
      trait A {
          final Foo foo = new Foo().with {
              config(it)
              it
          }
          static void config(foo) {
              foo.bar = 'bar'
          }
      }
      class C implements A {
      }
      print new C().foo.bar
      

       

      The error is:

      src/test/groovy/bar/Foo.groovy: 14: [Static type checking] - Cannot find matching method bar.A#config(bar.Foo). Please check if the declared type is correct and if the method exists.
       @ line 14, column 9.
                 config(it)
                 ^
      1 error
      

       
      If I change trait to class, it compiles successfully.

      I think this has to do with the fact that trait cannot have constructors, and hence the context in which the code executes does not have the right imports?

      Anyway, this was working fine before we upgraded to the latest Groovy 2.5.x version from 2.4.x.

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              renatoathaydes Renato Athaydes
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: