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

STC mis-tracks generics in type hierarchy

    XMLWordPrintableJSON

Details

    Description

      I have a Vavr Try pipeline of this form:

      class AttachmentSpec {
        // fields
        Attachment toAttachment(Ref ref) { ... }
      }
      
      
      Try.success(initialValue)
        .mapTry { process(it) } // returns a Map
        .map { convertToRef(it) } // returns a Ref.File extends Ref
        .recover { new Ref.Uri(it.href) } // Ref.Uri extends Ref
        .map(spec::toAttachment)
      

      On a failure in process, this pipeline should enter recover and supply a Ref.Uri, then do the final map. However, this fails with a ClassCastException: cannot convert Ref.Uri to Ref.File. Apparently, the compiler infers Ref.Uri as the return value from the first map (which is legitimate), but then it fails to produce a compile-time error when recover presents a then-incompatible Ref.File. The compiler should either (ideally) recognize that the desired type is superclass Ref or, more simply but at least correctly, produce a compile-time error until a type witness is inserted (and observed).

      Attachments

        Activity

          People

            emilles Eric Milles
            chrylis Christopher Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: