From 580e486386daabc22f342b02f5f587346243bb31 Mon Sep 17 00:00:00 2001 From: Leaf Petersen Date: Tue, 22 May 2018 16:24:57 +0000 Subject: [PATCH] Make CastStreamSubscription.onData handle a null callback Fixes #33166 Change-Id: I52e8bcb6c782c84e8a474b0fc40ada24f31bf602 Reviewed-on: https://dart-review.googlesource.com/55984 Reviewed-by: Nate Bosch Reviewed-by: Lasse R.H. Nielsen --- sdk/lib/internal/async_cast.dart | 3 ++- tests/corelib_2/regress_33166_test.dart | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/corelib_2/regress_33166_test.dart diff --git a/sdk/lib/internal/async_cast.dart b/sdk/lib/internal/async_cast.dart index eb59a7d08bd..eee09b95881 100644 --- a/sdk/lib/internal/async_cast.dart +++ b/sdk/lib/internal/async_cast.dart @@ -32,7 +32,8 @@ class CastStreamSubscription implements StreamSubscription { Future cancel() => _source.cancel(); void onData(void handleData(T data)) { - _source.onData((S data) => handleData(data as T)); + _source + .onData(handleData == null ? null : (S data) => handleData(data as T)); } void onError(Function handleError) { diff --git a/tests/corelib_2/regress_33166_test.dart b/tests/corelib_2/regress_33166_test.dart new file mode 100644 index 00000000000..03f0faf21d2 --- /dev/null +++ b/tests/corelib_2/regress_33166_test.dart @@ -0,0 +1,12 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; +import "package:expect/expect.dart"; + +// Regression test for https://github.com/dart-lang/sdk/issues/33166 +void main() async { + var stream = new Stream.fromIterable([1, 2, 3]); + Expect.equals(await stream.cast().drain().then((_) => 'Done'), 'Done'); +}