ceylon-dart icon indicating copy to clipboard operation
ceylon-dart copied to clipboard

consider hard-coding generic type info for `dart.async::Future.then`

Open jvasileff opened this issue 8 years ago • 1 comments

Future.then (docs) is defined as:

Future/*<S>*/ then/*<S>*/(/*=S*/ onValue(T value), { Function onError });

which results in the return type Future<Nothing> in Ceylon. Instead, we should consider hard-coding the model to have something like:

Future<S> then<S>(S|Future<S> onValue(T value), ...);

although, it may need to be more complicated, like:

Future<S|E|Throwable> then<S,E=Nothing>(S|Future<S> onValue(T value), E onError(Nothing) = nothing)

which starts to defeat the purpose. Especially since non-Throwables can be thrown in Dart. So, would we actually wind up with a return type of Future<Anything>?

Edit: not sure why I had Throwable in the union. Need to test this. It might be:

Future<S|E> then<S,E=Nothing>(S|Future<S> onValue(T value), E onError(Nothing) = nothing)

jvasileff avatar Jul 15 '16 20:07 jvasileff

An argument not to do this is in increases the likelihood of mistakenly winding up with a nested Future<Future<T>> result, which will actually be Future<T> since Dart unwraps Futures returned by onValue.

And, type inference seems to prefer the nested option for S|Future<S> (i.e. it ignores the Future<S> part of the union, so the inferred type is not unwrapped).

jvasileff avatar Oct 19 '16 02:10 jvasileff