Make CastStreamSubscription.onData handle a null callback

Fixes #33166

Change-Id: I52e8bcb6c782c84e8a474b0fc40ada24f31bf602
Reviewed-on: https://dart-review.googlesource.com/55984
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Leaf Petersen 2018-05-22 16:24:57 +00:00
parent 2a8eb8089d
commit 580e486386
2 changed files with 14 additions and 1 deletions

View file

@ -32,7 +32,8 @@ class CastStreamSubscription<S, T> implements StreamSubscription<T> {
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) {

View file

@ -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<int>().drain().then((_) => 'Done'), 'Done');
}