Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
4.0.6
-
None
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).