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

STC: problem w/ map based constructors

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.2
    • 2.0.4
    • Static Type Checker
    • None

    Description

      class CustomServletOutputStream extends OutputStream {
          OutputStream out
      
          void write(int i) {
              out.write(i)
          }
      
          void write(byte[] bytes) {
              out.write(bytes)
          }
      
          void write(byte[] bytes, int offset, int length) {
              out.write(bytes, offset, length)
          }
      
          void flush() {
              out.flush()
          }
      
          void close() {
              out.close()
          }
      }
      
      @groovy.transform.TypeChecked
      class Test {
          static void test() {
              def csos = new CustomServletOutputStream(out: new ByteArrayOutputStream())
          }   
      }
      
      Test.test()
      

      This fails with:

      [Static type checking] - Cannot assign value of type java.io.ByteArrayOutputStream to variable of type java.io.OutputStream
      

      However, the following spanning two lines work:

              def csos = new CustomServletOutputStream()
              csos.out = new ByteArrayOutputStream()
      

      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: