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

STC: problem w/ map based constructors

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.4
    • Component/s: Static Type Checker
    • Labels:
      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

            • Assignee:
              melix Cédric Champeau
              Reporter:
              Guillaume Guillaume Delcroix
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: