Skip to content

Commit 108a80b

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
NNBD: Mark some good tests as passing; add FailingTests for some GitHub issues
Change-Id: Ia5a55b5c6f1e7d7c7bef32c0afecf689952e17eb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127761 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 2015c55 commit 108a80b

File tree

3 files changed

+110
-47
lines changed

3 files changed

+110
-47
lines changed

pkg/analysis_server/lib/src/edit/nnbd_migration/info_builder.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class InfoBuilder {
152152
}
153153
return "This field is initialized by a field formal parameter and a "
154154
"nullable value is passed as an argument";
155+
} else if (parent is DefaultFormalParameter) {
156+
return "This parameter has ${aNullableDefault(parent)}";
155157
} else if (parent is AsExpression) {
156158
return "The value of the expression is nullable";
157159
}

pkg/analysis_server/test/src/edit/nnbd_migration/info_builder_test.dart

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -227,33 +227,6 @@ void g() {
227227
assertDetail(detail: regions[0].details[0], offset: 104, length: 1);
228228
}
229229

230-
test_exactNullable_exactNullable() async {
231-
UnitInfo unit = await buildInfoForSingleTestFile('''
232-
void g(List<int> list1, List<int> list2) {
233-
list1[0] = null;
234-
list2[0] = list1[0];
235-
}
236-
''', migratedContent: '''
237-
void g(List<int?> list1, List<int?> list2) {
238-
list1[0] = null;
239-
list2[0] = list1[0];
240-
}
241-
''');
242-
List<RegionInfo> regions = unit.regions;
243-
expect(regions, hasLength(4));
244-
// regions[0] is the hard edge that list1 is unconditionally indexed
245-
assertRegion(region: regions[1], offset: 15, details: [
246-
"An explicit 'null' is assigned",
247-
// TODO(mfairhurst): Fix this bug.
248-
'exact nullable node with no info (Substituted(type(32), migrated))'
249-
]);
250-
// regions[2] is the hard edge that list2 is unconditionally indexed
251-
assertRegion(
252-
region: regions[3],
253-
offset: 33,
254-
details: ["A nullable value is assigned"]);
255-
}
256-
257230
test_exactNullable() async {
258231
UnitInfo unit = await buildInfoForSingleTestFile('''
259232
void f(List<int> list) {
@@ -284,6 +257,33 @@ void g() {
284257
details: ["This is later required to accept null."]);
285258
}
286259

260+
test_exactNullable_exactNullable() async {
261+
UnitInfo unit = await buildInfoForSingleTestFile('''
262+
void g(List<int> list1, List<int> list2) {
263+
list1[0] = null;
264+
list2[0] = list1[0];
265+
}
266+
''', migratedContent: '''
267+
void g(List<int?> list1, List<int?> list2) {
268+
list1[0] = null;
269+
list2[0] = list1[0];
270+
}
271+
''');
272+
List<RegionInfo> regions = unit.regions;
273+
expect(regions, hasLength(4));
274+
// regions[0] is the hard edge that list1 is unconditionally indexed
275+
assertRegion(region: regions[1], offset: 15, details: [
276+
"An explicit 'null' is assigned",
277+
// TODO(mfairhurst): Fix this bug.
278+
'exact nullable node with no info (Substituted(type(32), migrated))'
279+
]);
280+
// regions[2] is the hard edge that list2 is unconditionally indexed
281+
assertRegion(
282+
region: regions[3],
283+
offset: 33,
284+
details: ["A nullable value is assigned"]);
285+
}
286+
287287
test_expressionFunctionReturnTarget() async {
288288
UnitInfo unit = await buildInfoForSingleTestFile('''
289289
String g() => 1 == 2 ? "Hello" : null;
@@ -321,6 +321,26 @@ class A {
321321
]);
322322
}
323323

324+
test_field_fieldFormalInitializer_optional_defaultNull() async {
325+
UnitInfo unit = await buildInfoForSingleTestFile('''
326+
class A {
327+
int _f;
328+
A([this._f = null]);
329+
}
330+
''', migratedContent: '''
331+
class A {
332+
int? _f;
333+
A([this._f = null]);
334+
}
335+
''');
336+
List<RegionInfo> regions = unit.regions;
337+
expect(regions, hasLength(1));
338+
assertRegion(region: regions[0], offset: 15, details: [
339+
"This field is initialized by an optional field formal parameter that "
340+
"has an explicit default value of 'null'"
341+
]);
342+
}
343+
324344
test_field_fieldFormalInitializer_required() async {
325345
UnitInfo unit = await buildInfoForSingleTestFile('''
326346
class A {
@@ -679,28 +699,25 @@ void g() {
679699
details: ["An explicit 'null' is passed as an argument"]);
680700
}
681701

682-
@failingTest
683702
test_parameter_fromInvocation_implicit() async {
684-
// Failing because the upstream edge ("always -(hard)-> type(13)")
685-
// associated with the reason (a _NullabilityNodeSimple) had a `null` origin
686-
// when the listener's `graphEdge` method was called.
687703
UnitInfo unit = await buildInfoForSingleTestFile('''
688704
void f(String s) {}
689705
void g(p) {
690706
f(p);
691707
}
708+
void h() => g(null);
692709
''', migratedContent: '''
693710
void f(String? s) {}
694711
void g(p) {
695712
f(p);
696713
}
714+
void h() => g(null);
697715
''');
698716
List<RegionInfo> regions = unit.regions;
699717
expect(regions, hasLength(1));
700-
assertRegion(
701-
region: regions[0],
702-
offset: 13,
703-
details: ["A nullable value is explicitly passed as an argument"]);
718+
assertRegion(region: regions[0], offset: 13, details: [
719+
"A dynamic value, which is nullable is passed as an argument"
720+
]);
704721
}
705722

706723
test_parameter_fromMultipleOverridden_explicit() async {
@@ -857,10 +874,7 @@ void g({int? i}) {}
857874
assertDetail(detail: regions[0].details[0], offset: 11, length: 3);
858875
}
859876

860-
@failingTest
861877
test_parameter_optional_explicitDefault_null() async {
862-
// Failing because we appear to never get an origin when the upstream node
863-
// for an edge is 'always'.
864878
UnitInfo unit = await buildInfoForSingleTestFile('''
865879
void f({String s = null}) {}
866880
''', migratedContent: '''
@@ -874,23 +888,20 @@ void f({String? s = null}) {}
874888
details: ["This parameter has an explicit default value of 'null'"]);
875889
}
876890

877-
@failingTest
878891
test_parameter_optional_explicitDefault_nullable() async {
879-
// Failing because we appear to never get an origin when the upstream node
880-
// for an edge is 'always'.
881892
UnitInfo unit = await buildInfoForSingleTestFile('''
882-
const sd = null;
893+
String sd = null;
883894
void f({String s = sd}) {}
884895
''', migratedContent: '''
885-
const sd = null;
896+
String? sd = null;
886897
void f({String? s = sd}) {}
887898
''');
888899
List<RegionInfo> regions = unit.fixRegions;
889-
expect(regions, hasLength(1));
900+
expect(regions, hasLength(2));
890901
assertRegion(
891-
region: regions[0],
892-
offset: 31,
893-
details: ["This parameter has an explicit default value of 'null'"]);
902+
region: regions[1],
903+
offset: 33,
904+
details: ["This parameter has a nullable default value"]);
894905
}
895906

896907
test_parameter_optional_implicitDefault_named() async {

pkg/nnbd_migration/test/api_test.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,17 @@ C<int, num?> f(List<int> a) => a;
10601060
await _checkSingleFileChanges(content, expected);
10611061
}
10621062

1063+
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/39609')
1064+
test_dynamic_dispatch_to_object_method() async {
1065+
var content = '''
1066+
String f(dynamic x) => x.toString();
1067+
''';
1068+
var expected = '''
1069+
String f(dynamic x) => x.toString();
1070+
''';
1071+
await _checkSingleFileChanges(content, expected);
1072+
}
1073+
10631074
test_dynamic_method_call() async {
10641075
var content = '''
10651076
class C {
@@ -1922,6 +1933,30 @@ int? g(C c) => c.f();
19221933
await _checkSingleFileChanges(content, expected);
19231934
}
19241935

1936+
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/38469')
1937+
test_inserted_nodes_properly_wrapped() async {
1938+
addMetaPackage();
1939+
var content = '''
1940+
class C {
1941+
C operator+(C other) => null;
1942+
}
1943+
void f(C x, C y) {
1944+
C z = x + y;
1945+
assert(z != null);
1946+
}
1947+
''';
1948+
var expected = '''
1949+
class C {
1950+
C operator+(C other) => null;
1951+
}
1952+
void f(C x, C y) {
1953+
C z = (x + y)!;
1954+
assert(z != null);
1955+
}
1956+
''';
1957+
await _checkSingleFileChanges(content, expected);
1958+
}
1959+
19251960
test_instance_creation_generic() async {
19261961
var content = '''
19271962
class C<T> {
@@ -2542,6 +2577,21 @@ test(int?/*?*/ j) {
25422577
await _checkSingleFileChanges(content, expected);
25432578
}
25442579

2580+
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/39269')
2581+
test_null_in_conditional_expression() async {
2582+
var content = '''
2583+
void f() {
2584+
List<int> x = false ? [] : null;
2585+
}
2586+
''';
2587+
var expected = '''
2588+
void f() {
2589+
List<int>? x = false ? [] : null;
2590+
}
2591+
''';
2592+
await _checkSingleFileChanges(content, expected);
2593+
}
2594+
25452595
test_operator_eq_with_inferred_parameter_type() async {
25462596
var content = '''
25472597
class C {

0 commit comments

Comments
 (0)