ceylon-dart
ceylon-dart copied to clipboard
consider hard-coding generic type info for `dart.async::Future.then`
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-Throwable
s 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)
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 Future
s 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).