Fix incorrect instance checks.

Several instance checks added during the null safety core library
migration were incorrectly rejecting null values in places where null
values can still flow in legacy mode.  This eliminates the instance
checks in favor of casts which will behave as desired.

Bug: https://github.com/dart-lang/sdk/issues/41465
Change-Id: I50fb9e6cef41d645d5312871932c7168f2d80c29
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143333
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
This commit is contained in:
Leaf Petersen 2020-04-14 19:25:45 +00:00 committed by commit-bot@chromium.org
parent aa3d4ef958
commit 6d88b04a89
5 changed files with 38 additions and 7 deletions

View file

@ -223,9 +223,8 @@ abstract class Future<T> {
if (result is Future<T>) {
return result;
} else {
if (result is! T)
throw "unreachable"; // TODO(lrn): Remove when type promotion works.
return new _Future<T>.value(result);
// TODO(40014): Remove cast when type promotion works.
return new _Future<T>.value(result as dynamic);
}
} catch (error, stackTrace) {
var future = new _Future<T>();

View file

@ -523,10 +523,8 @@ abstract class Stream<T> {
subscription.pause();
newValue.then(add, onError: addError).whenComplete(resume);
} else {
if (newValue is! E) {
throw "unreachable"; // TODO(lrn): Remove when type promotion works.
}
controller.add(newValue);
// TODO(40014): Remove cast when type promotion works.
controller.add(newValue as dynamic);
}
});
controller.onCancel = subscription.cancel;

View file

@ -0,0 +1,2 @@
This directory contains tests specific to null safety weak mode
behavior.

View file

@ -0,0 +1,17 @@
// Copyright (c) 2020, 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.
// @dart = 2.7
import "dart:async";
import "package:expect/expect.dart";
// Regression test for https://github.com/dart-lang/sdk/issues/41465
void main() {
var stream = Stream.fromIterable([1, 2, 3, 4]);
var eventsStream =
stream.asyncMap((i) => i % 2 == 0 ? i : null).where((i) => i != null);
eventsStream.listen(Expect.isNotNull);
}

View file

@ -0,0 +1,15 @@
// Copyright (c) 2020, 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.
// @dart = 2.7
import "dart:async";
import "package:expect/expect.dart";
// Regression test for https://github.com/dart-lang/sdk/issues/41465
void main() async {
var f = Future<int>.sync(() => null);
Expect.isNull(await f);
}