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

Closure not statically compiled and owner access issue

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-rc-3
    • 2.0-rc-4
    • Static compilation
    • None

    Description

      import groovy.transform.CompileStatic
      
      interface Row {
          int getKey()
      }
      
      class RowImpl implements Row {
          int getKey() { 1 }
      }
      
      @CompileStatic
      def test() {
          def rows = [new RowImpl(), new RowImpl(), new RowImpl()]
          
          rows.each { Row row ->
              println row.key
          }
      }
      
      test()
      

      When executing the above script, with the statically compiled test() method, I get an exception saying that the owner property could not be found:

      groovy.lang.MissingPropertyException: No such property: owner for class: ConsoleScript47
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
      	at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
      	at ConsoleScript47$_test_closure1.doCall(ConsoleScript47:19)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
      	at groovy.lang.Closure.call(Closure.java:410)
      	at groovy.lang.Closure.call(Closure.java:423)
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1323)
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1295)
      	at ConsoleScript47.test(ConsoleScript47:17)
      

      Furthermore, if you look closely at the stacktrace, it seems strange to see some call sites appearing, as if the closure wasn't compiled statically.

      Attachments

        Activity

          People

            melix Cédric Champeau
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: