Skip to content

Commit 66c1b51

Browse files
joshualittcommit-bot@chromium.org
authored andcommitted
[dart2js] 20 dart2js tests ported to nnbd #1.
Change-Id: I8cb1bb03655762669ac88775b5aee763e79c4b11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152594 Reviewed-by: Stephen Adams <[email protected]> Commit-Queue: Joshua Litt <[email protected]>
1 parent f4b19b8 commit 66c1b51

20 files changed

+180
-32
lines changed

WATCHLISTS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'filepath': (
2929
'^pkg/compiler|'
3030
'^sdk/lib/_internal/js_runtime|'
31-
'^tests/compiler/dart2js'
31+
'^tests/dart2js'
3232
)
3333
},
3434
'dartdevc': {

tests/dart2js/12320_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "package:expect/expect.dart";
77
// Regression test for Issue 12320, Issue 12363.
88

99
String log = '';
10-
int x;
10+
int? x;
1111

1212
void main() {
1313
(run)(run);

tests/dart2js/17856_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import "package:expect/expect.dart";
99
void main() {
1010
var all = {"a": new A(), "b": new B()};
1111

12-
A a = all["a"];
12+
A a = all["a"] as A;
1313
a.load();
1414
}
1515

tests/dart2js/29130_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class A {
2020

2121
// interface scenario: we shouldn't trace B
2222
abstract class B implements A {
23-
factory B() => null;
23+
factory B() => null as dynamic;
2424
}
2525

2626
// mixin scenario: we should trace C, but we should trace _C

tests/dart2js/32770c_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// dart2jsOptions=--strong
6-
75
// Regression test for issue 32770.
86

97
import 'dart:async' show Future;
108

11-
A<J> futureToA<T, J>(Future<T> future, [J wrapValue(T value)]) {
9+
A<J> futureToA<T, J>(Future<T> future, [J wrapValue(T value)?]) {
1210
return new A<J>(
1311
(void resolveFn(J value), void rejectFn(error)) {
1412
future.then((value) {

tests/dart2js/32828_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// dart2jsOptions=--strong
6-
75
class A {
8-
void m2<T>(void Function(T) f, [a]) {}
6+
void m2<T>(void Function(T)? f, [a]) {}
97
}
108

119
main() => new A().m2<String>(null);

tests/dart2js/37494_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Example<T> extends ListBase<T> {
4646

4747
@override
4848
@pragma('dart2js:noInline')
49-
void sort([int compare(T a, T b)]) {
49+
void sort([int compare(T a, T b)?]) {
5050
super.sort(compare); // This super call had bad dummy interceptor.
5151
}
5252
}

tests/dart2js/41449a_test.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// dart2jsOptions=-O0
6+
7+
// Regression test for passing type parameters through call-through stub.
8+
//
9+
// We use an abstract class with two implementations to avoid the optimizer
10+
// 'inlining' the call-through stub, so we are testing that the stub itself
11+
// passes through the type parameters.
12+
13+
import 'package:expect/expect.dart';
14+
15+
abstract class AAA {
16+
dynamic get foo;
17+
}
18+
19+
class B1 implements AAA {
20+
final dynamic foo;
21+
B1(this.foo);
22+
}
23+
24+
class B2 implements AAA {
25+
final dynamic _arr;
26+
B2(foo) : _arr = [foo];
27+
dynamic get foo => _arr.first;
28+
}
29+
30+
class B3 implements AAA {
31+
final dynamic __foo;
32+
B3(this.__foo);
33+
dynamic get _foo => __foo;
34+
dynamic get foo => _foo;
35+
}
36+
37+
@pragma('dart2js:noInline')
38+
test1<T>(AAA a, String expected) {
39+
// call-through getter 'foo' with one type argument.
40+
Expect.equals(expected, a.foo<T>());
41+
}
42+
43+
@pragma('dart2js:noInline')
44+
test2<U, V>(AAA a, String expected) {
45+
// call-through getter 'foo' with two type arguments.
46+
Expect.equals(expected, a.foo<U, V>());
47+
}
48+
49+
main() {
50+
test1<int>(B1(<P>() => '$P'), 'int');
51+
test1<num>(B2(<Q>() => '$Q'), 'num');
52+
test1<double>(B3(<R>() => '$R'), 'double');
53+
54+
test2<int, num>(B1(<A, B>() => '$A $B'), 'int num');
55+
test2<num, int>(B2(<X, Y>() => '$X $Y'), 'num int');
56+
test2<double, String>(B3(<C, D>() => '$C $D'), 'double String');
57+
}

tests/dart2js/41449b_test.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// This test is the same as 41449a_test.dart without forcing `-O0`.
6+
//
7+
// Regression test for passing type parameters through call-through stub.
8+
//
9+
// We use an abstract class with two implementations to avoid the optimizer
10+
// 'inlining' the call-through stub, so we are testing that the stub itself
11+
// passes through the type parameters.
12+
13+
import 'package:expect/expect.dart';
14+
15+
abstract class AAA {
16+
dynamic get foo;
17+
}
18+
19+
class B1 implements AAA {
20+
final dynamic foo;
21+
B1(this.foo);
22+
}
23+
24+
class B2 implements AAA {
25+
final dynamic _arr;
26+
B2(foo) : _arr = [foo];
27+
dynamic get foo => _arr.first;
28+
}
29+
30+
class B3 implements AAA {
31+
final dynamic __foo;
32+
B3(this.__foo);
33+
dynamic get _foo => __foo;
34+
dynamic get foo => _foo;
35+
}
36+
37+
@pragma('dart2js:noInline')
38+
test1<T>(AAA a, String expected) {
39+
// call-through getter 'foo' with one type argument.
40+
Expect.equals(expected, a.foo<T>());
41+
}
42+
43+
@pragma('dart2js:noInline')
44+
test2<U, V>(AAA a, String expected) {
45+
// call-through getter 'foo' with two type arguments.
46+
Expect.equals(expected, a.foo<U, V>());
47+
}
48+
49+
main() {
50+
test1<int>(B1(<P>() => '$P'), 'int');
51+
test1<num>(B2(<Q>() => '$Q'), 'num');
52+
test1<double>(B3(<R>() => '$R'), 'double');
53+
54+
test2<int, num>(B1(<A, B>() => '$A $B'), 'int num');
55+
test2<num, int>(B2(<X, Y>() => '$X $Y'), 'num int');
56+
test2<double, String>(B3(<C, D>() => '$C $D'), 'double String');
57+
}

tests/dart2js/42189_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// dart2jsOptions=-O0
6+
7+
// Regression test for issue 42891. The root cause was a malformed SSA due to
8+
// generating a dynamic entry point argument test for an elided parameter
9+
// directly on the HLocalValue , which should only be an operand to HLocalGet
10+
// and HLocalSet.
11+
12+
import "package:expect/expect.dart";
13+
14+
class CCC {
15+
void foo([num x = 123]) {
16+
try {
17+
Expect.equals(123, x);
18+
x = 0;
19+
} finally {
20+
Expect.equals(0, x);
21+
}
22+
}
23+
24+
void bar([num x = 456]) {
25+
try {
26+
Expect.equals(123, x);
27+
x = 0;
28+
} finally {
29+
Expect.equals(0, x);
30+
}
31+
}
32+
}
33+
34+
void main() {
35+
CCC().foo();
36+
CCC().bar(123);
37+
}

tests/dart2js/881_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
@pragma('dart2js:disableFinal')
88
void main() {
9-
String v = null;
9+
String? v = null;
1010
print('${v.hashCode}');
1111
}

tests/dart2js/assert_with_message_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ testTypeErrors() {
4444
}
4545

4646
check('constant type error', () {
47-
assert(null, 'Mumble');
47+
assert(null as dynamic, 'Mumble');
4848
});
4949
check('variable type error', () {
5050
assert(confuse(null), 'Mumble');

tests/dart2js/boolean_conversion_test.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ void main() {
2323
}
2424

2525
void conditionalTest() {
26-
bool x = null;
26+
bool x = null as dynamic;
2727
Expect.isFalse(x ? true : false);
2828
}
2929

3030
void orTest() {
31-
bool x = null;
31+
bool x = null as dynamic;
3232
Expect.equals(null, x || x);
3333
Expect.isFalse(x || false);
3434
Expect.isTrue(x || true);
@@ -37,7 +37,7 @@ void orTest() {
3737
}
3838

3939
void andTest() {
40-
bool x = null;
40+
bool x = null as dynamic;
4141
Expect.isFalse(x && x);
4242
Expect.isFalse(x && false);
4343
Expect.isFalse(x && true);
@@ -46,7 +46,7 @@ void andTest() {
4646
}
4747

4848
void ifTest() {
49-
bool x = null;
49+
bool x = null as dynamic;
5050
Expect.isFalse(() {
5151
if (x) {
5252
return true;
@@ -57,7 +57,7 @@ void ifTest() {
5757
}
5858

5959
void forTest() {
60-
bool x = null;
60+
bool x = null as dynamic;
6161
Expect.isFalse(() {
6262
for (; x;) {
6363
return true;
@@ -67,7 +67,7 @@ void forTest() {
6767
}
6868

6969
void whileTest() {
70-
bool x = null;
70+
bool x = null as dynamic;
7171
Expect.isFalse(() {
7272
while (x) {
7373
return true;
@@ -77,7 +77,7 @@ void whileTest() {
7777
}
7878

7979
void doTest() {
80-
bool x = null;
80+
bool x = null as dynamic;
8181
Expect.equals(1, () {
8282
int n = 0;
8383
do {
@@ -88,16 +88,16 @@ void doTest() {
8888
}
8989

9090
void notTest() {
91-
bool x = null;
91+
bool x = null as dynamic;
9292
Expect.isTrue(!x);
9393
}
9494

9595
void ifElementTest() {
96-
bool x = null;
96+
bool x = null as dynamic;
9797
Expect.listEquals([], [if (x) 1]);
9898
}
9999

100100
void forElementTest() {
101-
bool x = null;
101+
bool x = null as dynamic;
102102
Expect.listEquals([], [for (var i = 0; x; i++) i]);
103103
}

tests/dart2js/bound_closure_interceptor_type_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import "package:expect/expect.dart";
1515
class A<T> {
1616
const A();
1717
void add(T x) {}
18-
T elementAt(int index) => index == 0 ? 42 : 'string';
18+
T elementAt(int index) => index == 0 ? 42 as dynamic : 'string';
1919

2020
// This call get:elementAt has a known receiver type, so is is potentially
2121
// eligible for a dummy receiver optimization.
@@ -89,7 +89,7 @@ main() {
8989

9090
for (var object in objects) {
9191
for (var methodName in methodNames) {
92-
var methodFn = methods[methodName];
92+
var methodFn = methods[methodName] as dynamic;
9393
var description = '$object';
9494
checkers.forEach((checkName, checkFn) {
9595
bool answer = trueCheckNames.contains(checkName);

tests/dart2js/call_signature_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:expect/expect.dart';
99

1010
class A<T> {
1111
/// Weird signature to ensure it isn't match by any call selector.
12-
call(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, {T t}) {}
12+
call(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, {T? t}) {}
1313
}
1414

1515
class B<T> {

tests/dart2js/cfe_instance_constant_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ class Class9 {
1717
const c0 = const bool.fromEnvironment("x") ? null : const Class9();
1818

1919
main() {
20-
Expect.equals(0, c0.field);
20+
Expect.equals(0, c0!.field);
2121
}

tests/dart2js/checked_setter_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import 'package:expect/expect.dart';
66

77
class A {
8-
String field;
8+
String? field;
99
}
1010

1111
class B {
12-
int field;
12+
int? field;
1313
}
1414

1515
@pragma('dart2js:noInline')

tests/dart2js/class_hierarchy_extends_clause_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:expect/expect.dart';
56

67
class A {}
78

tests/dart2js/closure_capture7_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
class A<T> {
6-
List<List> xs;
6+
List<List>? xs;
77

88
void foo() {
99
// the inner closure only needs to capture 'this' if
1010
// `A` needs runtime type information.
11-
xs.map((x) => x.map((a) => a as T));
11+
xs!.map((x) => x.map((a) => a as T));
1212
}
1313
}
1414

0 commit comments

Comments
 (0)