Skip to content

Commit

Permalink
[dart2js] Port some tests to nnbd #5.
Browse files Browse the repository at this point in the history
Change-Id: Ic9912d94e1248df70a92e2504af87d42d5ca0528
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152617
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
  • Loading branch information
joshualitt authored and commit-bot@chromium.org committed Jul 14, 2020
1 parent b19fefa commit cfeb1d6
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 94 deletions.
2 changes: 1 addition & 1 deletion tests/dart2js/panda_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "package:expect/expect.dart";
import 'panda_lib.dart' as p;

void main() {
p.Panda x = new p.Panda();
p.Panda? x = new p.Panda();
Expect.isTrue(x is p.Panda);
x = null;
Expect.isFalse(x is p.Panda);
Expand Down
2 changes: 1 addition & 1 deletion tests/dart2js/regress_40349_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dynamic x = Wrapper<int>();

class A<E> {
int _foo = 0;
List<E> list = [null];
List<E?> list = [null];

@pragma('dart2js:tryInline')
void internalMethod(E value) {
Expand Down
14 changes: 4 additions & 10 deletions tests/dart2js/regress_null_aware_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
// Regression test for failure on CFE null-aware encoding.

class Class {
Map<String, Set<String>> map;
Map<String, Set<String>>? map;

List<String> method(String node, Set<String> set) =>
set.add(node)
? [
node,
...?map[node]
?.expand((node) => method(node, set))
?.toList()
]
: [];
List<String> method(String node, Set<String> set) => set.add(node)
? [node, ...?map![node]?.expand((node) => method(node, set))?.toList()]
: [];
}

main(args) {
Expand Down
6 changes: 3 additions & 3 deletions tests/dart2js/return_setter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import "package:expect/expect.dart";

class A {
int foo;
int? foo;

static int invocations;
static int? invocations;

static bar() {
Expect.equals(0, invocations);
invocations++;
invocations = invocations! + 1;
return 2;
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/dart2js/runtime_type_closure_equals1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

class Class<T> {
Expand All @@ -19,5 +17,5 @@ main() {

Expect.isTrue(local1a.runtimeType == local1b.runtimeType);
Expect.isFalse(local1a.runtimeType == local2.runtimeType);
new Class();
Class();
}
8 changes: 3 additions & 5 deletions tests/dart2js/runtime_type_closure_equals2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

class Class<T> {
Class();
}

main() {
T local1a<T>() => null;
T local1a<T>() => throw 'unreachable';

T local1b<T>() => null;
T local1b<T>() => throw 'unreachable';

T local2<T>(T t, String s) => t;

Expect.isTrue(local1a.runtimeType == local1b.runtimeType);
Expect.isFalse(local1a.runtimeType == local2.runtimeType);
new Class();
Class();
}
12 changes: 5 additions & 7 deletions tests/dart2js/runtime_type_closure_equals3_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

String method() => null;
String method() => throw 'unreachable';

class Class1<T> {
Class1();

method() {
T local1a() => null;
T local1a() => throw 'unreachable';

T local1b() => null;
T local1b() => throw 'unreachable';

T local2(T t, String s) => t;

Expand All @@ -29,6 +27,6 @@ class Class2<T> {
}

main() {
new Class1<int>().method();
new Class2<int>();
Class1<int>().method();
Class2<int>();
}
6 changes: 2 additions & 4 deletions tests/dart2js/runtime_type_closure_equals4_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

class Class1<T> {
Expand All @@ -21,9 +19,9 @@ class Class2<T> {
}

main() {
var c = new Class1<int>();
var c = Class1<int>();

Expect.isTrue(c.method1a.runtimeType == c.method1b.runtimeType);
Expect.isFalse(c.method1a.runtimeType == c.method2.runtimeType);
new Class2<int>();
Class2<int>();
}
10 changes: 4 additions & 6 deletions tests/dart2js/runtime_type_closure_equals5_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

class Class1<T> {
Class1();

T method1a() => null;
T method1a() => throw 'unreachable';

T method1b() => null;
T method1b() => throw 'unreachable';

T method2(T t, String s) => t;
}
Expand All @@ -21,9 +19,9 @@ class Class2<T> {
}

main() {
var c = new Class1<int>();
var c = Class1<int>();

Expect.isTrue(c.method1a.runtimeType == c.method1b.runtimeType);
Expect.isFalse(c.method1a.runtimeType == c.method2.runtimeType);
new Class2<int>();
Class2<int>();
}
4 changes: 1 addition & 3 deletions tests/dart2js/runtime_type_closure_equals6_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

method1a() => null;
Expand All @@ -19,5 +17,5 @@ class Class<T> {
main() {
Expect.isTrue(method1a.runtimeType == method1b.runtimeType);
Expect.isFalse(method1a.runtimeType == method2.runtimeType);
new Class<int>();
Class<int>();
}
8 changes: 3 additions & 5 deletions tests/dart2js/runtime_type_closure_equals7_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

T method1a<T>() => null;
T method1a<T>() => throw 'unreachable';

T method1b<T>() => null;
T method1b<T>() => throw 'unreachable';

T method2<T>(T t, String s) => t;

Expand All @@ -19,5 +17,5 @@ class Class<T> {
main() {
Expect.isTrue(method1a.runtimeType == method1b.runtimeType);
Expect.isFalse(method1a.runtimeType == method2.runtimeType);
new Class<int>();
Class<int>();
}
10 changes: 4 additions & 6 deletions tests/dart2js/runtime_type_closure_equals8_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// dart2jsOptions=--strong

import 'package:expect/expect.dart';

class Class1<S> {
Class1();

T method1a<T>() => null;
T method1a<T>() => throw 'unreachable';

T method1b<T>() => null;
T method1b<T>() => throw 'unreachable';

T method2<T>(T t, String s) => t;
}
Expand All @@ -21,9 +19,9 @@ class Class2<T> {
}

main() {
var c = new Class1<int>();
var c = Class1<int>();

Expect.isTrue(c.method1a.runtimeType == c.method1b.runtimeType);
Expect.isFalse(c.method1a.runtimeType == c.method2.runtimeType);
new Class2<int>();
Class2<int>();
}
2 changes: 1 addition & 1 deletion tests/dart2js/static_field2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import "package:expect/expect.dart";

class A {
static int b;
static int? b;
}

main() {
Expand Down
4 changes: 2 additions & 2 deletions tests/dart2js/static_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import "package:expect/expect.dart";

class A {
static int b;
static int? b;

setA(val) {
b = val;
Expand All @@ -21,7 +21,7 @@ class A {
}

main() {
A a = new A();
A a = A();
a.setA(42);
Expect.equals(42, a.bar());
Expect.equals(42, a.bar2());
Expand Down
8 changes: 4 additions & 4 deletions tests/dart2js/static_var_no_initializer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import "package:expect/expect.dart";

int one;
int x;
int? one;
int? x;

void testOne() {
Expect.equals(1, one);
Expand All @@ -16,7 +16,7 @@ void testX(var expected) {
}

void increaseX() {
x = x + 1;
x = x! + 1;
}

void main() {
Expand All @@ -26,7 +26,7 @@ void main() {
testOne();
Expect.equals(5, x);
testX(5);
x = x + 1;
x = x! + 1;
Expect.equals(6, x);
testX(6);
increaseX();
Expand Down
6 changes: 3 additions & 3 deletions tests/dart2js/string_interpolation_opt1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:math';

// Test that String interpolation works in some optimized cases.

bool get inscrutableFalse => new Random().nextDouble() > 2;
bool get inscrutableFalse => Random().nextDouble() > 2;

returnsNullOrString(x) {
if (inscrutableFalse) return 'hi';
Expand All @@ -27,7 +27,7 @@ spoil(a) {
}

void testString() {
var a = new List(100); // 'null' values in here are JavaScript undefined.
var a = []..length = 100; // 'null' values in here are JavaScript undefined.
spoil(a);
var s = returnsNullOrString('hi');
var x = a[2];
Expand All @@ -39,7 +39,7 @@ void testString() {
}

void testInt() {
var a = new List(100); // 'null' values in here are JavaScript undefined.
var a = []..length = 100; // 'null' values in here are JavaScript undefined.
spoil(a);
var s = returnsNullOrInt(123);
var x = a[2];
Expand Down
4 changes: 2 additions & 2 deletions tests/dart2js/super_constructor1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import "package:expect/expect.dart";

String message;
String? message;

class A {
int x;
Expand Down Expand Up @@ -33,7 +33,7 @@ class C extends B {

main() {
message = '';
var c = new C(7);
var c = C(7);
Expect.equals(27, c.x);
Expect.equals(21, c.y);
Expect.equals(7, c.z);
Expand Down
18 changes: 9 additions & 9 deletions tests/dart2js/tear_off_types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ test1() {
Expect.isFalse(_test1(method1c));
}

B1 method1a() => null;
A1<int> method1b() => null;
A1<String> method1c() => null;
B1 method1a() => throw 'unreachable';
A1<int> method1b() => throw 'unreachable';
A1<String> method1c() => throw 'unreachable';

@pragma('dart2js:noInline')
bool _test1(f) => f is A1<int> Function();
Expand Down Expand Up @@ -81,9 +81,9 @@ test4() {
Expect.isFalse(_test4(method4c));
}

B4 method4a() => null;
A4<int> method4b() => null;
A4<String> method4c() => null;
B4 method4a() => throw 'unreachable';
A4<int> method4b() => throw 'unreachable';
A4<String> method4c() => throw 'unreachable';

@pragma('dart4js:noInline')
_test4(f) => f is B4 Function();
Expand Down Expand Up @@ -117,9 +117,9 @@ test6() {
Expect.isFalse(_test6(method6c));
}

void Function(B6) method6a() => null;
void Function(A6<int>) method6b() => null;
void Function(A6<String>) method6c() => null;
void Function(B6) method6a() => throw 'unreachable';
void Function(A6<int>) method6b() => throw 'unreachable';
void Function(A6<String>) method6c() => throw 'unreachable';

@pragma('dart6js:noInline')
_test6(f) => f is void Function(B6) Function();
Expand Down
Loading

0 comments on commit cfeb1d6

Please sign in to comment.