Sdk: Finalize Future flattening in strong mode

Created on 6 Oct 2016  路  4Comments  路  Source: dart-lang/sdk

The fact that futures implicitly "flatten" at runtime makes statically typing code that works with them harder. In some cases, code that accepts a Future<T> really effectively takes a Future<T>|T, which Dart cannot represent.

Strong mode currently has some ad hoc rules around Future.then() to make it work nicer, but those rules are kind of hacky and don't extend to user-defined methods that work in a similar fashion. See here and the following comments.

To finish off strong mode, we need to decide what the real rules we want here are, commit to them, and describe and implement them fully. A couple of options:

  1. Stick with the current ad hoc rules.
  2. Define a special Async<T> which works roughly like a special case union type of Future<T>|T.
  3. Full-fledged union types.
area-language

Most helpful comment

I'd love Async<T> in the short term and full-fledged union types in the long term.

All 4 comments

馃憤 for Full-fledged union types.

I'd love Async<T> in the short term and full-fledged union types in the long term.

status: language team is ok with the Async<T> proposal (possibly with a different name). @lrhn is writing up the informal spec to be shared for wider feedback and then implementation.

We are going to implement FutureOr<T>: https://github.com/dart-lang/sdk/issues/28006

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgrekhov picture sgrekhov  路  3Comments

matanlurey picture matanlurey  路  3Comments

DartBot picture DartBot  路  3Comments

gspencergoog picture gspencergoog  路  3Comments

brooth picture brooth  路  3Comments