Skip to content

Commit f825e7a

Browse files
[nnbd_migration] Add tests for uncheckable+functions, #40625
Tests currently pass, so we can close that bug. However, if for some reason it becomes an issue such that these tests fail, they will link to a bug with detailed info on a potential cause. Bug: 40625 Change-Id: I212eb5401622a189de4998247b0ff521077e30e3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135763 Reviewed-by: Paul Berry <[email protected]>
1 parent 0216ac8 commit f825e7a

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

pkg/nnbd_migration/test/api_test.dart

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,106 @@ void h(List<int> x) {
15751575
await _checkSingleFileChanges(content, expected);
15761576
}
15771577

1578+
Future<void> test_exact_nullability_doesnt_affect_function_args() async {
1579+
// Test attempting to create a bug from #40625. Currently passes, but if it
1580+
// breaks, that bug may need to be reopened.
1581+
var content = '''
1582+
class C<T> {
1583+
int Function(T) f;
1584+
}
1585+
void main() {
1586+
C<String> c;
1587+
int Function(String) f1 = c.f; // should not have a nullable arg
1588+
c.f(null); // exact nullability induced here
1589+
}
1590+
''';
1591+
var expected = '''
1592+
class C<T> {
1593+
int Function(T)? f;
1594+
}
1595+
void main() {
1596+
C<String?> c;
1597+
int Function(String)? f1 = c.f; // should not have a nullable arg
1598+
c.f!(null); // exact nullability induced here
1599+
}
1600+
''';
1601+
await _checkSingleFileChanges(content, expected);
1602+
}
1603+
1604+
Future<void> test_exact_nullability_doesnt_affect_function_returns() async {
1605+
// Test attempting to create a bug from #40625. Currently passes, but if it
1606+
// breaks, that bug may need to be reopened.
1607+
var content = '''
1608+
class C<T> {
1609+
T Function(String) f;
1610+
}
1611+
int Function(String) f1; // should not have a nullable return
1612+
void main() {
1613+
C<int> c;
1614+
c.f = f1;
1615+
c.f = (_) => null; // exact nullability induced here
1616+
}
1617+
''';
1618+
var expected = '''
1619+
class C<T> {
1620+
T Function(String)? f;
1621+
}
1622+
int Function(String) f1; // should not have a nullable return
1623+
void main() {
1624+
C<int?> c;
1625+
c.f = f1;
1626+
c.f = (_) => null; // exact nullability induced here
1627+
}
1628+
''';
1629+
await _checkSingleFileChanges(content, expected);
1630+
}
1631+
1632+
Future<void> test_exact_nullability_doesnt_affect_typedef_args() async {
1633+
// Test attempting to create a bug from #40625. Currently passes, but if it
1634+
// breaks, that bug may need to be reopened.
1635+
var content = '''
1636+
typedef F<T> = int Function(T);
1637+
F<String> f1;
1638+
1639+
void main() {
1640+
f1(null); // induce exact nullability
1641+
int Function(String) f2 = f1; // shouldn't have a nullable arg
1642+
}
1643+
''';
1644+
var expected = '''
1645+
typedef F<T> = int Function(T);
1646+
F<String?> f1;
1647+
1648+
void main() {
1649+
f1(null); // induce exact nullability
1650+
int Function(String) f2 = f1; // shouldn't have a nullable arg
1651+
}
1652+
''';
1653+
await _checkSingleFileChanges(content, expected);
1654+
}
1655+
1656+
Future<void> test_exact_nullability_doesnt_affect_typedef_returns() async {
1657+
// Test attempting to create a bug from #40625. Currently passes, but if it
1658+
// breaks, that bug may need to be reopened.
1659+
var content = '''
1660+
typedef F<T> = T Function(String);
1661+
int Function(String) f1; // should not have a nullable return
1662+
void main() {
1663+
F<int> f2 = f1;
1664+
f2 = (_) => null; // exact nullability induced here
1665+
}
1666+
''';
1667+
var expected = '''
1668+
typedef F<T> = T Function(String);
1669+
int Function(String) f1; // should not have a nullable return
1670+
void main() {
1671+
F<int?> f2 = f1;
1672+
f2 = (_) => null; // exact nullability induced here
1673+
}
1674+
''';
1675+
await _checkSingleFileChanges(content, expected);
1676+
}
1677+
15781678
Future<void> test_explicit_nullable_overrides_hard_edge() async {
15791679
var content = '''
15801680
int f(int/*?*/ i) => i + 1;

0 commit comments

Comments
 (0)