Skip to content

Fix type of onError. #1339

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 1 commit into from
May 9, 2022
Merged

Fix type of onError. #1339

merged 1 commit into from
May 9, 2022

Conversation

stereotype441
Copy link
Member

The function passed to Stream.handleError needs to accept either a
single argument of type Object, or an Object and a StackTrace.
Since this can't be expressed by the type system, it's checked at
runtime. As a result, the check function (as previously written)
would fail if ever instantiated with a type T that was narrower than
Object.

Prior to implementation of
dart-lang/language#731 (improved inference
for fold etc.), this worked fine, because type inference always
supplied an argument type of dynamic or Object for the function
literals passed to check. However, with the inference improvement
enabled, it starts to infer other types, causing runtime failures.

The correct fix is to give the event argument of onError an
appropriate type.

The function passed to Stream.handleError needs to accept either a
single argument of type `Object`, or an `Object` and a `StackTrace`.
Since this can't be expressed by the type system, it's checked at
runtime.  As a result, the `check` function (as previously written)
would fail if ever instantiated with a type `T` that was narrower than
`Object`.

Prior to implementation of
dart-lang/language#731 (improved inference
for fold etc.), this worked fine, because type inference always
supplied an argument type of `dynamic` or `Object` for the function
literals passed to `check`.  However, with the inference improvement
enabled, it starts to infer other types, causing runtime failures.

The correct fix is to give the `event` argument of `onError` an
appropriate type.
@stereotype441 stereotype441 requested a review from srawlins May 6, 2022 15:48
@stereotype441 stereotype441 merged commit 9849573 into master May 9, 2022
stereotype441 added a commit that referenced this pull request May 9, 2022
@stereotype441 stereotype441 deleted the b-731-168 branch May 9, 2022 17:07
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request May 10, 2022
2022-05-09 [email protected] Fix type of onError. (dart-lang/co19#1339)

Change-Id: I78b2c218acb97881b9feb05e74c9775a2f6cd360
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244102
Commit-Queue: William Hesse <[email protected]>
Reviewed-by: Alexander Thomas <[email protected]>
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