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

UFO Operator(<=>) errors with CompileStatic and TypeChecked

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2
    • None
    • MacOSX 10.8
      java version "1.7.0_05"
      Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

    Description

      When I use UFO operator in following code:

      @groovy.transform.CompileStatic
      def main() {
        Closure c = { Integer l, Integer r -> l <=> r }
        // Closure c = { Integer l, Integer r -> l.compareTo(r) } // OK
        println([7, 4, 1, 2, 3].sort(c))
      }
      main()
      

      reports:

      Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ufo@7067f21' with class 'ufo' to class 'java.lang.Comparable'
      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ufo@7067f21' with class 'ufo' to class 'java.lang.Comparable'
      at ufo$_main_closure1.doCall(ufo.groovy)
      at ufo.main(ufo.groovy:6)
      at ufo.run(ufo.groovy:8)

      and I found another case, i don't know the relation of above case.
      When running:

      @groovy.transform.TypeChecked
      def main() {
        Integer x = 3
        Integer y = 4
        println (x <=> y)
      }
      main()
      

      Static type checker claims:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /tool/ufo2.groovy: 6: [Static type checking] - Reference to method is ambiguous. Cannot choose between [MethodNode@2142220333[int compareTo(java.lang.Object)], MethodNode@153838582[int compareTo(java.lang.Integer)]]
      @ line 6, column 12.
      println (x <=> y)
      ^

      1 error

      Attachments

        Activity

          People

            melix Cédric Champeau
            uehaj UEHARA Junji
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: