Skip to content

Breaking change to await, update to flatten. #2333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 7, 2022
Merged

Breaking change to await, update to flatten. #2333

merged 8 commits into from
Jul 7, 2022

Conversation

lrhn
Copy link
Member

@lrhn lrhn commented Jul 7, 2022

Changes flatten to be specified for a static type which is a type variable.

Changes await to throw when provided a Future value
of a type that could provide an unsound value if awaited.

This differs from the current specification, which instead treats the future as
a value, so await someFuture can evaluate to someFuture.

It also differs from the current implementation,
which awaits someFuture to its value,
whether the result is sound or not.

The result can be sound. Compare:

Object o = await (Future<Object?>.value(3) as FutureOr<Object>));

which ends up not breaking soundness, with

Object o = await (Future<Object?>.value(null) as FutureOr<Object>));

which currently does break soundness.

This change will make both into runtime errors.

(The alternative, and current specification,
to make both expression evaluate to the future itself,
is considered just as error prone and harder to debug,
since a type error is likely happen further downstream
when the Object is unexpectedly still a Future.)

Changes **flatten** to be specified for a static type which is a type variable.

Changes `await` to throw when provided a `Future` value
of a type that could provide an unsound value if awaited.

This differes from the current specification, which instead treats the future as
a value, so `await someFuture` can evaluate to `someFuture`.

It also differs from the current implementation,
which awaits `someFuture` to its value,
whether the result is sound or not.

The result *can* be sound. Compare:
```dart
Object o = await (Future<Object?>.value(3) as FutureOr<Object));
```
which ends up not breaking soundness, with
```dart
Object o = await (Future<Object?>.value(null) as FutureOr<Object));
```
which currently does break soundness.

This change will make both into runtime errors.

(The alternative, and current specification,
to make both expression evaluate to the future itself,
is considered just as error prone and harder to debug,
since a type error is likely happen further downstream
when the `Object` is unexpectedly still a `Future`.)
@lrhn lrhn requested a review from eernstg July 7, 2022 08:47
Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, recommending some changes, for consistency with the rest of the language specification.

I also suggested several changes for the definition of \flatten, in order to make it complete for null safety (I don't think we should specify flatten in a new way for the legacy language, so the new definition of flatten should be the full null safety thing). But this creates some issues: We need to use a \ref{...} to a section that doesn't exist in the current specification, and we need to add a command to dart.sty.

@github-actions
Copy link

github-actions bot commented Jul 7, 2022

Visit the preview URL for this PR (updated for commit 9733ae8):

https://dart-specification--pr2333-flatten-await-s0p1ts7w.web.app

(expires Thu, 14 Jul 2022 11:18:59 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 6941ecd630c4f067ff3d02708a45ae0f0a42b88a

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just to make sure, does it LaTeX successfully? (A script on github will do that when it's landed.)

@eernstg eernstg merged commit a3b45ab into master Jul 7, 2022
@eernstg eernstg deleted the flatten-await branch July 7, 2022 11:28
Otherwise
(\commentary{when $R$ does not implement \code{Future}}),
let $f$ be an object whose run-time type implements \code{Future<$T$>},
which is completed with the value $o$.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. This doesn't actually say what behavior the f object has.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants