Skip to content

Commit

Permalink
NNBD: Mark some good tests as passing; add FailingTests for some GitH…
Browse files Browse the repository at this point in the history
…ub issues

Change-Id: Ia5a55b5c6f1e7d7c7bef32c0afecf689952e17eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127761
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and commit-bot@chromium.org committed Dec 9, 2019
1 parent 2015c55 commit 108a80b
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class InfoBuilder {
}
return "This field is initialized by a field formal parameter and a "
"nullable value is passed as an argument";
} else if (parent is DefaultFormalParameter) {
return "This parameter has ${aNullableDefault(parent)}";
} else if (parent is AsExpression) {
return "The value of the expression is nullable";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,33 +227,6 @@ void g() {
assertDetail(detail: regions[0].details[0], offset: 104, length: 1);
}

test_exactNullable_exactNullable() async {
UnitInfo unit = await buildInfoForSingleTestFile('''
void g(List<int> list1, List<int> list2) {
list1[0] = null;
list2[0] = list1[0];
}
''', migratedContent: '''
void g(List<int?> list1, List<int?> list2) {
list1[0] = null;
list2[0] = list1[0];
}
''');
List<RegionInfo> regions = unit.regions;
expect(regions, hasLength(4));
// regions[0] is the hard edge that list1 is unconditionally indexed
assertRegion(region: regions[1], offset: 15, details: [
"An explicit 'null' is assigned",
// TODO(mfairhurst): Fix this bug.
'exact nullable node with no info (Substituted(type(32), migrated))'
]);
// regions[2] is the hard edge that list2 is unconditionally indexed
assertRegion(
region: regions[3],
offset: 33,
details: ["A nullable value is assigned"]);
}

test_exactNullable() async {
UnitInfo unit = await buildInfoForSingleTestFile('''
void f(List<int> list) {
Expand Down Expand Up @@ -284,6 +257,33 @@ void g() {
details: ["This is later required to accept null."]);
}

test_exactNullable_exactNullable() async {
UnitInfo unit = await buildInfoForSingleTestFile('''
void g(List<int> list1, List<int> list2) {
list1[0] = null;
list2[0] = list1[0];
}
''', migratedContent: '''
void g(List<int?> list1, List<int?> list2) {
list1[0] = null;
list2[0] = list1[0];
}
''');
List<RegionInfo> regions = unit.regions;
expect(regions, hasLength(4));
// regions[0] is the hard edge that list1 is unconditionally indexed
assertRegion(region: regions[1], offset: 15, details: [
"An explicit 'null' is assigned",
// TODO(mfairhurst): Fix this bug.
'exact nullable node with no info (Substituted(type(32), migrated))'
]);
// regions[2] is the hard edge that list2 is unconditionally indexed
assertRegion(
region: regions[3],
offset: 33,
details: ["A nullable value is assigned"]);
}

test_expressionFunctionReturnTarget() async {
UnitInfo unit = await buildInfoForSingleTestFile('''
String g() => 1 == 2 ? "Hello" : null;
Expand Down Expand Up @@ -321,6 +321,26 @@ class A {
]);
}

test_field_fieldFormalInitializer_optional_defaultNull() async {
UnitInfo unit = await buildInfoForSingleTestFile('''
class A {
int _f;
A([this._f = null]);
}
''', migratedContent: '''
class A {
int? _f;
A([this._f = null]);
}
''');
List<RegionInfo> regions = unit.regions;
expect(regions, hasLength(1));
assertRegion(region: regions[0], offset: 15, details: [
"This field is initialized by an optional field formal parameter that "
"has an explicit default value of 'null'"
]);
}

test_field_fieldFormalInitializer_required() async {
UnitInfo unit = await buildInfoForSingleTestFile('''
class A {
Expand Down Expand Up @@ -679,28 +699,25 @@ void g() {
details: ["An explicit 'null' is passed as an argument"]);
}

@failingTest
test_parameter_fromInvocation_implicit() async {
// Failing because the upstream edge ("always -(hard)-> type(13)")
// associated with the reason (a _NullabilityNodeSimple) had a `null` origin
// when the listener's `graphEdge` method was called.
UnitInfo unit = await buildInfoForSingleTestFile('''
void f(String s) {}
void g(p) {
f(p);
}
void h() => g(null);
''', migratedContent: '''
void f(String? s) {}
void g(p) {
f(p);
}
void h() => g(null);
''');
List<RegionInfo> regions = unit.regions;
expect(regions, hasLength(1));
assertRegion(
region: regions[0],
offset: 13,
details: ["A nullable value is explicitly passed as an argument"]);
assertRegion(region: regions[0], offset: 13, details: [
"A dynamic value, which is nullable is passed as an argument"
]);
}

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

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

@failingTest
test_parameter_optional_explicitDefault_nullable() async {
// Failing because we appear to never get an origin when the upstream node
// for an edge is 'always'.
UnitInfo unit = await buildInfoForSingleTestFile('''
const sd = null;
String sd = null;
void f({String s = sd}) {}
''', migratedContent: '''
const sd = null;
String? sd = null;
void f({String? s = sd}) {}
''');
List<RegionInfo> regions = unit.fixRegions;
expect(regions, hasLength(1));
expect(regions, hasLength(2));
assertRegion(
region: regions[0],
offset: 31,
details: ["This parameter has an explicit default value of 'null'"]);
region: regions[1],
offset: 33,
details: ["This parameter has a nullable default value"]);
}

test_parameter_optional_implicitDefault_named() async {
Expand Down
50 changes: 50 additions & 0 deletions pkg/nnbd_migration/test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,17 @@ C<int, num?> f(List<int> a) => a;
await _checkSingleFileChanges(content, expected);
}

@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/39609')
test_dynamic_dispatch_to_object_method() async {
var content = '''
String f(dynamic x) => x.toString();
''';
var expected = '''
String f(dynamic x) => x.toString();
''';
await _checkSingleFileChanges(content, expected);
}

test_dynamic_method_call() async {
var content = '''
class C {
Expand Down Expand Up @@ -1922,6 +1933,30 @@ int? g(C c) => c.f();
await _checkSingleFileChanges(content, expected);
}

@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/38469')
test_inserted_nodes_properly_wrapped() async {
addMetaPackage();
var content = '''
class C {
C operator+(C other) => null;
}
void f(C x, C y) {
C z = x + y;
assert(z != null);
}
''';
var expected = '''
class C {
C operator+(C other) => null;
}
void f(C x, C y) {
C z = (x + y)!;
assert(z != null);
}
''';
await _checkSingleFileChanges(content, expected);
}

test_instance_creation_generic() async {
var content = '''
class C<T> {
Expand Down Expand Up @@ -2542,6 +2577,21 @@ test(int?/*?*/ j) {
await _checkSingleFileChanges(content, expected);
}

@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/39269')
test_null_in_conditional_expression() async {
var content = '''
void f() {
List<int> x = false ? [] : null;
}
''';
var expected = '''
void f() {
List<int>? x = false ? [] : null;
}
''';
await _checkSingleFileChanges(content, expected);
}

test_operator_eq_with_inferred_parameter_type() async {
var content = '''
class C {
Expand Down

0 comments on commit 108a80b

Please sign in to comment.