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 <sra@google.com> Commit-Queue: Joshua Litt <joshualitt@google.com>
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+
}

0 commit comments

Comments
 (0)