Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6
    • 2.3.0-beta-1
    • Static Type Checker
    • None

    Description

      Consider the following code:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      def test() {
          List<String> strings = ["one", "two"]
          
          def other = strings.collect { String s -> true }
          
          other.every { String s -> "bad" }
      }
      
      test()
      

      It produces

      groovy.lang.MissingMethodException: No signature of method: ConsoleScript4$_test_closure2.call() is applicable for argument types: (java.lang.Boolean) values: [true]
      Possible solutions: any(), any(), doCall(java.lang.String), any(groovy.lang.Closure), each(groovy.lang.Closure), any(groovy.lang.Closure)
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:906)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:727)
      	at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
      	at org.codehaus.groovy.runtime.callsite.BooleanReturningMethodInvoker.invoke(BooleanReturningMethodInvoker.java:49)
      	at org.codehaus.groovy.runtime.callsite.BooleanClosureWrapper.call(BooleanClosureWrapper.java:52)
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.every(DefaultGroovyMethods.java:1453)
      	at ConsoleScript4.test(ConsoleScript4:10)
      	a
      

      The closure dispatch seems to be dynamic, regardless of the use of @CompileStatic, nevertheless the more unexpected aspect of this is that the code compiles in the first place. I would have expected a compilation error not a runtime one?

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              graemerocher Graeme Rocher
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: