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 <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2020-02-13 20:23:18 +00:00 committed by commit-bot@chromium.org
parent ed705e8c84
commit 4bde1f1851

View file

@ -1544,6 +1544,37 @@ void h() {
await _checkSingleFileChanges(content, expected);
}
Future<void> test_exact_nullability_counterexample() async {
var content = '''
void f(List<int> x) {
x.add(1);
}
void g() {
f([null]);
}
void h(List<int> x) {
f(x);
}
''';
// The `null` in `g` causes `f`'s `x` argument to have type `List<int?>`.
// 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<int?> x) {
x.add(1);
}
void g() {
f([null]);
}
void h(List<int> x) {
f(x);
}
''';
await _checkSingleFileChanges(content, expected);
}
Future<void> test_explicit_nullable_overrides_hard_edge() async {
var content = '''
int f(int/*?*/ i) => i + 1;