@@ -470,13 +470,13 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
470470 ///
471471 /// - e.g. task.success { value -> NextTaskType in ... }
472472 ///
473- public func success< Progress2, Value2> ( successClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
473+ public func success< Progress2, Value2, Error2 > ( successClosure: Value -> Task < Progress2 , Value2 , Error2 > ) -> Task < Progress2 , Value2 , Error >
474474 {
475475 var dummyCanceller : Canceller ? = nil
476476 return self . success ( & dummyCanceller, successClosure)
477477 }
478478
479- public func success< Progress2, Value2, C: Canceller > ( inout canceller: C ? , _ successClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
479+ public func success< Progress2, Value2, Error2 , C: Canceller > ( inout canceller: C ? , _ successClosure: Value -> Task < Progress2 , Value2 , Error2 > ) -> Task < Progress2 , Value2 , Error >
480480 {
481481 return Task < Progress2 , Value2 , Error > { [ unowned self] newMachine, progress, fulfill, _reject, configure in
482482
@@ -581,8 +581,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
581581
582582// MARK: - Helper
583583
584- internal func _bindInnerTask< Progress2, Value2, Error> (
585- innerTask: Task < Progress2 , Value2 , Error > ,
584+ internal func _bindInnerTask< Progress2, Value2, Error, Error2 > (
585+ innerTask: Task < Progress2 , Value2 , Error2 > ,
586586 newMachine: _StateMachine < Progress2 , Value2 , Error > ,
587587 progress: Task < Progress2 , Value2 , Error > . ProgressHandler ,
588588 fulfill: Task < Progress2 , Value2 , Error > . FulfillHandler ,
@@ -595,20 +595,26 @@ internal func _bindInnerTask<Progress2, Value2, Error>(
595595 fulfill ( innerTask. value!)
596596 return
597597 case . Rejected, . Cancelled:
598- _reject ( innerTask. errorInfo!)
598+ let ( error2, isCancelled) = innerTask. errorInfo!
599+
600+ // NOTE: innerTask's `error2` will be treated as `nil` if not same type as outerTask's `Error` type
601+ _reject ( ( error2 as? Error , isCancelled) )
599602 return
600603 default :
601604 break
602605 }
603606
604607 innerTask. progress { _, progressValue in
605608 progress ( progressValue)
606- } . then { ( value: Value2 ? , errorInfo : Task < Progress2 , Value2 , Error > . ErrorInfo ? ) -> Void in
609+ } . then { ( value: Value2 ? , errorInfo2 : Task < Progress2 , Value2 , Error2 > . ErrorInfo ? ) -> Void in
607610 if let value = value {
608611 fulfill ( value)
609612 }
610- else if let errorInfo = errorInfo {
611- _reject ( errorInfo)
613+ else if let errorInfo2 = errorInfo2 {
614+ let ( error2, isCancelled) = errorInfo2
615+
616+ // NOTE: innerTask's `error2` will be treated as `nil` if not same type as outerTask's `Error` type
617+ _reject ( ( error2 as? Error , isCancelled) )
612618 }
613619 }
614620
0 commit comments