mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:44:59 +00:00
[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>
This commit is contained in:
parent
f4b19b8c2a
commit
66c1b51c07
|
@ -28,7 +28,7 @@
|
|||
'filepath': (
|
||||
'^pkg/compiler|'
|
||||
'^sdk/lib/_internal/js_runtime|'
|
||||
'^tests/compiler/dart2js'
|
||||
'^tests/dart2js'
|
||||
)
|
||||
},
|
||||
'dartdevc': {
|
||||
|
|
|
@ -7,7 +7,7 @@ import "package:expect/expect.dart";
|
|||
// Regression test for Issue 12320, Issue 12363.
|
||||
|
||||
String log = '';
|
||||
int x;
|
||||
int? x;
|
||||
|
||||
void main() {
|
||||
(run)(run);
|
||||
|
|
|
@ -9,7 +9,7 @@ import "package:expect/expect.dart";
|
|||
void main() {
|
||||
var all = {"a": new A(), "b": new B()};
|
||||
|
||||
A a = all["a"];
|
||||
A a = all["a"] as A;
|
||||
a.load();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class A {
|
|||
|
||||
// interface scenario: we shouldn't trace B
|
||||
abstract class B implements A {
|
||||
factory B() => null;
|
||||
factory B() => null as dynamic;
|
||||
}
|
||||
|
||||
// mixin scenario: we should trace C, but we should trace _C
|
||||
|
|
|
@ -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
|
||||
|
||||
// Regression test for issue 32770.
|
||||
|
||||
import 'dart:async' show Future;
|
||||
|
||||
A<J> futureToA<T, J>(Future<T> future, [J wrapValue(T value)]) {
|
||||
A<J> futureToA<T, J>(Future<T> future, [J wrapValue(T value)?]) {
|
||||
return new A<J>(
|
||||
(void resolveFn(J value), void rejectFn(error)) {
|
||||
future.then((value) {
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
// 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
|
||||
|
||||
class A {
|
||||
void m2<T>(void Function(T) f, [a]) {}
|
||||
void m2<T>(void Function(T)? f, [a]) {}
|
||||
}
|
||||
|
||||
main() => new A().m2<String>(null);
|
||||
|
|
|
@ -46,7 +46,7 @@ class Example<T> extends ListBase<T> {
|
|||
|
||||
@override
|
||||
@pragma('dart2js:noInline')
|
||||
void sort([int compare(T a, T b)]) {
|
||||
void sort([int compare(T a, T b)?]) {
|
||||
super.sort(compare); // This super call had bad dummy interceptor.
|
||||
}
|
||||
}
|
||||
|
|
57
tests/dart2js/41449a_test.dart
Normal file
57
tests/dart2js/41449a_test.dart
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// 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=-O0
|
||||
|
||||
// Regression test for passing type parameters through call-through stub.
|
||||
//
|
||||
// We use an abstract class with two implementations to avoid the optimizer
|
||||
// 'inlining' the call-through stub, so we are testing that the stub itself
|
||||
// passes through the type parameters.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
abstract class AAA {
|
||||
dynamic get foo;
|
||||
}
|
||||
|
||||
class B1 implements AAA {
|
||||
final dynamic foo;
|
||||
B1(this.foo);
|
||||
}
|
||||
|
||||
class B2 implements AAA {
|
||||
final dynamic _arr;
|
||||
B2(foo) : _arr = [foo];
|
||||
dynamic get foo => _arr.first;
|
||||
}
|
||||
|
||||
class B3 implements AAA {
|
||||
final dynamic __foo;
|
||||
B3(this.__foo);
|
||||
dynamic get _foo => __foo;
|
||||
dynamic get foo => _foo;
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
test1<T>(AAA a, String expected) {
|
||||
// call-through getter 'foo' with one type argument.
|
||||
Expect.equals(expected, a.foo<T>());
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
test2<U, V>(AAA a, String expected) {
|
||||
// call-through getter 'foo' with two type arguments.
|
||||
Expect.equals(expected, a.foo<U, V>());
|
||||
}
|
||||
|
||||
main() {
|
||||
test1<int>(B1(<P>() => '$P'), 'int');
|
||||
test1<num>(B2(<Q>() => '$Q'), 'num');
|
||||
test1<double>(B3(<R>() => '$R'), 'double');
|
||||
|
||||
test2<int, num>(B1(<A, B>() => '$A $B'), 'int num');
|
||||
test2<num, int>(B2(<X, Y>() => '$X $Y'), 'num int');
|
||||
test2<double, String>(B3(<C, D>() => '$C $D'), 'double String');
|
||||
}
|
57
tests/dart2js/41449b_test.dart
Normal file
57
tests/dart2js/41449b_test.dart
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// 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.
|
||||
|
||||
// This test is the same as 41449a_test.dart without forcing `-O0`.
|
||||
//
|
||||
// Regression test for passing type parameters through call-through stub.
|
||||
//
|
||||
// We use an abstract class with two implementations to avoid the optimizer
|
||||
// 'inlining' the call-through stub, so we are testing that the stub itself
|
||||
// passes through the type parameters.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
abstract class AAA {
|
||||
dynamic get foo;
|
||||
}
|
||||
|
||||
class B1 implements AAA {
|
||||
final dynamic foo;
|
||||
B1(this.foo);
|
||||
}
|
||||
|
||||
class B2 implements AAA {
|
||||
final dynamic _arr;
|
||||
B2(foo) : _arr = [foo];
|
||||
dynamic get foo => _arr.first;
|
||||
}
|
||||
|
||||
class B3 implements AAA {
|
||||
final dynamic __foo;
|
||||
B3(this.__foo);
|
||||
dynamic get _foo => __foo;
|
||||
dynamic get foo => _foo;
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
test1<T>(AAA a, String expected) {
|
||||
// call-through getter 'foo' with one type argument.
|
||||
Expect.equals(expected, a.foo<T>());
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
test2<U, V>(AAA a, String expected) {
|
||||
// call-through getter 'foo' with two type arguments.
|
||||
Expect.equals(expected, a.foo<U, V>());
|
||||
}
|
||||
|
||||
main() {
|
||||
test1<int>(B1(<P>() => '$P'), 'int');
|
||||
test1<num>(B2(<Q>() => '$Q'), 'num');
|
||||
test1<double>(B3(<R>() => '$R'), 'double');
|
||||
|
||||
test2<int, num>(B1(<A, B>() => '$A $B'), 'int num');
|
||||
test2<num, int>(B2(<X, Y>() => '$X $Y'), 'num int');
|
||||
test2<double, String>(B3(<C, D>() => '$C $D'), 'double String');
|
||||
}
|
37
tests/dart2js/42189_test.dart
Normal file
37
tests/dart2js/42189_test.dart
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// 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=-O0
|
||||
|
||||
// Regression test for issue 42891. The root cause was a malformed SSA due to
|
||||
// generating a dynamic entry point argument test for an elided parameter
|
||||
// directly on the HLocalValue , which should only be an operand to HLocalGet
|
||||
// and HLocalSet.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class CCC {
|
||||
void foo([num x = 123]) {
|
||||
try {
|
||||
Expect.equals(123, x);
|
||||
x = 0;
|
||||
} finally {
|
||||
Expect.equals(0, x);
|
||||
}
|
||||
}
|
||||
|
||||
void bar([num x = 456]) {
|
||||
try {
|
||||
Expect.equals(123, x);
|
||||
x = 0;
|
||||
} finally {
|
||||
Expect.equals(0, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
CCC().foo();
|
||||
CCC().bar(123);
|
||||
}
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
@pragma('dart2js:disableFinal')
|
||||
void main() {
|
||||
String v = null;
|
||||
String? v = null;
|
||||
print('${v.hashCode}');
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ testTypeErrors() {
|
|||
}
|
||||
|
||||
check('constant type error', () {
|
||||
assert(null, 'Mumble');
|
||||
assert(null as dynamic, 'Mumble');
|
||||
});
|
||||
check('variable type error', () {
|
||||
assert(confuse(null), 'Mumble');
|
||||
|
|
|
@ -23,12 +23,12 @@ void main() {
|
|||
}
|
||||
|
||||
void conditionalTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.isFalse(x ? true : false);
|
||||
}
|
||||
|
||||
void orTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.equals(null, x || x);
|
||||
Expect.isFalse(x || false);
|
||||
Expect.isTrue(x || true);
|
||||
|
@ -37,7 +37,7 @@ void orTest() {
|
|||
}
|
||||
|
||||
void andTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.isFalse(x && x);
|
||||
Expect.isFalse(x && false);
|
||||
Expect.isFalse(x && true);
|
||||
|
@ -46,7 +46,7 @@ void andTest() {
|
|||
}
|
||||
|
||||
void ifTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.isFalse(() {
|
||||
if (x) {
|
||||
return true;
|
||||
|
@ -57,7 +57,7 @@ void ifTest() {
|
|||
}
|
||||
|
||||
void forTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.isFalse(() {
|
||||
for (; x;) {
|
||||
return true;
|
||||
|
@ -67,7 +67,7 @@ void forTest() {
|
|||
}
|
||||
|
||||
void whileTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.isFalse(() {
|
||||
while (x) {
|
||||
return true;
|
||||
|
@ -77,7 +77,7 @@ void whileTest() {
|
|||
}
|
||||
|
||||
void doTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.equals(1, () {
|
||||
int n = 0;
|
||||
do {
|
||||
|
@ -88,16 +88,16 @@ void doTest() {
|
|||
}
|
||||
|
||||
void notTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.isTrue(!x);
|
||||
}
|
||||
|
||||
void ifElementTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.listEquals([], [if (x) 1]);
|
||||
}
|
||||
|
||||
void forElementTest() {
|
||||
bool x = null;
|
||||
bool x = null as dynamic;
|
||||
Expect.listEquals([], [for (var i = 0; x; i++) i]);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import "package:expect/expect.dart";
|
|||
class A<T> {
|
||||
const A();
|
||||
void add(T x) {}
|
||||
T elementAt(int index) => index == 0 ? 42 : 'string';
|
||||
T elementAt(int index) => index == 0 ? 42 as dynamic : 'string';
|
||||
|
||||
// This call get:elementAt has a known receiver type, so is is potentially
|
||||
// eligible for a dummy receiver optimization.
|
||||
|
@ -89,7 +89,7 @@ main() {
|
|||
|
||||
for (var object in objects) {
|
||||
for (var methodName in methodNames) {
|
||||
var methodFn = methods[methodName];
|
||||
var methodFn = methods[methodName] as dynamic;
|
||||
var description = '$object';
|
||||
checkers.forEach((checkName, checkFn) {
|
||||
bool answer = trueCheckNames.contains(checkName);
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'package:expect/expect.dart';
|
|||
|
||||
class A<T> {
|
||||
/// Weird signature to ensure it isn't match by any call selector.
|
||||
call(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, {T t}) {}
|
||||
call(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, {T? t}) {}
|
||||
}
|
||||
|
||||
class B<T> {
|
||||
|
|
|
@ -17,5 +17,5 @@ class Class9 {
|
|||
const c0 = const bool.fromEnvironment("x") ? null : const Class9();
|
||||
|
||||
main() {
|
||||
Expect.equals(0, c0.field);
|
||||
Expect.equals(0, c0!.field);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
import 'package:expect/expect.dart';
|
||||
|
||||
class A {
|
||||
String field;
|
||||
String? field;
|
||||
}
|
||||
|
||||
class B {
|
||||
int field;
|
||||
int? field;
|
||||
}
|
||||
|
||||
@pragma('dart2js:noInline')
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class A {}
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
class A<T> {
|
||||
List<List> xs;
|
||||
List<List>? xs;
|
||||
|
||||
void foo() {
|
||||
// the inner closure only needs to capture 'this' if
|
||||
// `A` needs runtime type information.
|
||||
xs.map((x) => x.map((a) => a as T));
|
||||
xs!.map((x) => x.map((a) => a as T));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ main() {
|
|||
a[0] += 2;
|
||||
Expect.equals(3, a[0]);
|
||||
|
||||
List trace = new List();
|
||||
List trace = [];
|
||||
getB(trace)[getIndex(trace)] += 37;
|
||||
|
||||
Expect.listEquals([-1, -2, -3, 42, 100, -4, 101, 37, -5, 42, 102], trace);
|
||||
|
|
Loading…
Reference in a new issue