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

TypeChecked/CompileStatic says ambiguous about calling PrintWriter.write(byte[],int,int)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2
    • Compiler
    • None
    • MacOS X,

    Description

      I tried TypeChecked/CompileStatic with calling PrintWriter.write(byte[], int, int) in following code:

      //@groovy.transform.CompileStatic
      
      @groovy.transform.TypeChecked
      def main() {
        byte[] data = [1,2,3] as byte[]
        System.out.write((byte[])data, (int)0, (int)0)
      }
      
      main()
      

      raises following static type check error:

      m.groovy: 11: [Static type checking] - Reference to method is ambiguous. Cannot choose between [MethodNode@1587779925[void write([B, int, int)], MethodNode@1727501758[void write([B)], MethodNode@957941600[void write([B)], MethodNode@902239314[void write([C)]]
      @ line 11, column 3.
      System.out.write((byte[])data, (int)0, (int)0)
      ^

      1 error

      When tried without cast operator( System.out.write(data,0,0) ), the result was similar.
      When I tried to call method which i defined, no error detected:

      @groovy.transform.TypeChecked
      def foo(byte[] c, int a, int b)
      {}
      
      @groovy.transform.TypeChecked
      def main() {
        byte[] data = [1,2,3] as byte[]
        foo((byte[])data, (int)0, (int)0)
      }
      
      main()
      

      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: