You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a piece of code that causes this crash. The naming of the initialiser generic type Value can be easily confused with the class generic Value type, so I'll use two different names for my explanation below.
// Keep Swift wrapper alive for chained promise until `ObjCPromise` counterpart is resolved.
objCPromise.__addPendingObject(self)
}
The way the current convenience initialisers in Promise+Do.swift are written, they allow the user to create a promise of some type OneValue and pass a function that returns a type SecondValue. This is because the convenience initialisers contain their own generic type SecondValue which does not have the match the OneValue type of the class Promise. Since the generic type is erased to ObjCPromise<AnyObject> when any class methods are run that cast the resolved to the class OneValue type
class Promise<OneValue>convenienceinit<SecondValue>(on queue:DispatchQueue=.promises, _ work:@escapingDo<SecondValue){letobjCPromise= ObjCPromise<AnyObject>.__onQueue(queue){/*....*/}self.init(objCPromise)
objCPromise.__addPendingObject(self)}
Is there any reason why there are generic initialiser types used in the project like these?
Problem
The following code compiles and causes a crash
Explanation
Here is a piece of code that causes this crash. The naming of the initialiser generic type
Value
can be easily confused with the class genericValue
type, so I'll use two different names for my explanation below.promises/Sources/Promises/Promise+Do.swift
Lines 26 to 38 in afa9a1a
The way the current convenience initialisers in Promise+Do.swift are written, they allow the user to create a promise of some type
OneValue
and pass a function that returns a typeSecondValue
. This is because the convenience initialisers contain their own generic typeSecondValue
which does not have the match theOneValue
type of the classPromise
. Since the generic type is erased toObjCPromise<AnyObject>
when any class methods are run that cast the resolved to the classOneValue
typeIs there any reason why there are generic initialiser types used in the project like these?
promises/Sources/Promises/Promise+Do.swift
Line 26 in afa9a1a
promises/Sources/Promises/Promise+Do.swift
Line 45 in afa9a1a
The text was updated successfully, but these errors were encountered: