mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:22:12 +00:00
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:
parent
aa3d4ef958
commit
6d88b04a89
|
@ -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>();
|
||||
|
|
|
@ -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;
|
||||
|
|
2
tests/corelib/weak_mode/README
Normal file
2
tests/corelib/weak_mode/README
Normal file
|
@ -0,0 +1,2 @@
|
|||
This directory contains tests specific to null safety weak mode
|
||||
behavior.
|
17
tests/corelib/weak_mode/asyncMap_accepts_null.dart
Normal file
17
tests/corelib/weak_mode/asyncMap_accepts_null.dart
Normal 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);
|
||||
}
|
15
tests/corelib/weak_mode/future_sync_accepts_null.dart
Normal file
15
tests/corelib/weak_mode/future_sync_accepts_null.dart
Normal 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);
|
||||
}
|
Loading…
Reference in a new issue