From 4bde1f1851a13ccffe96db9227c9493cacc0dc03 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 13 Feb 2020 20:23:18 +0000 Subject: [PATCH] Migration: test to make sure exact nullability isn't applied too much. This is a regression test that would have caught the mistake in https://dart-review.googlesource.com/c/sdk/+/135351 (see that CL for additional details). Change-Id: Ideaf83df6deae3f6688fc89cfd8b3568344c5d4d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135660 Reviewed-by: Mike Fairhurst Commit-Queue: Paul Berry --- pkg/nnbd_migration/test/api_test.dart | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/nnbd_migration/test/api_test.dart b/pkg/nnbd_migration/test/api_test.dart index 8e857deb6c3..7f7d53bd33c 100644 --- a/pkg/nnbd_migration/test/api_test.dart +++ b/pkg/nnbd_migration/test/api_test.dart @@ -1544,6 +1544,37 @@ void h() { await _checkSingleFileChanges(content, expected); } + Future test_exact_nullability_counterexample() async { + var content = ''' +void f(List x) { + x.add(1); +} +void g() { + f([null]); +} +void h(List x) { + f(x); +} +'''; + // The `null` in `g` causes `f`'s `x` argument to have type `List`. + // Even though `f` calls a method that uses `List`'s type parameter + // contravariantly (the `add` method), that is not sufficient to cause exact + // nullability propagation, since value passed to `add` has a + // non-nullable type. So nullability is *not* propagated back to `h`. + var expected = ''' +void f(List x) { + x.add(1); +} +void g() { + f([null]); +} +void h(List x) { + f(x); +} +'''; + await _checkSingleFileChanges(content, expected); + } + Future test_explicit_nullable_overrides_hard_edge() async { var content = ''' int f(int/*?*/ i) => i + 1;