Skip to content

Commit 72161a9

Browse files
committed
Fix type of onError.
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.
1 parent 8f22acf commit 72161a9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

LibTest/async/Stream/handleError_A06_t01.test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ library handleError_A06_t01;
1212
import "dart:async";
1313
import "../../../Utils/expect.dart";
1414

15-
void check<T>(Stream<T> stream, Function? onError(T event), bool test(error)) {
15+
void check<T>(Stream<T> stream, Function? onError(dynamic event), bool test(error)) {
1616
Expect.equals(stream.isBroadcast, stream.handleError(onError).isBroadcast);
1717
Expect.equals(stream.isBroadcast, stream.handleError(onError, test:test).isBroadcast);
1818
}

0 commit comments

Comments
 (0)