Skip to content

Commit

Permalink
[dart2js] 20 dart2js tests ported to nnbd #1.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joshualitt authored and commit-bot@chromium.org committed Jun 26, 2020
1 parent f4b19b8 commit 66c1b51
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 32 deletions.
2 changes: 1 addition & 1 deletion WATCHLISTS
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'filepath': (
'^pkg/compiler|'
'^sdk/lib/_internal/js_runtime|'
'^tests/compiler/dart2js'
'^tests/dart2js'
)
},
'dartdevc': {
Expand Down
2 changes: 1 addition & 1 deletion tests/dart2js/12320_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/dart2js/17856_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/dart2js/29130_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/dart2js/32770c_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

// 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) {
Expand Down
4 changes: 1 addition & 3 deletions tests/dart2js/32828_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion tests/dart2js/37494_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 57 additions & 0 deletions tests/dart2js/41449a_test.dart
Original file line number Diff line number Diff line change
@@ -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 changes: 57 additions & 0 deletions tests/dart2js/41449b_test.dart
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions tests/dart2js/42189_test.dart
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion tests/dart2js/881_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@pragma('dart2js:disableFinal')
void main() {
String v = null;
String? v = null;
print('${v.hashCode}');
}
2 changes: 1 addition & 1 deletion tests/dart2js/assert_with_message_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
20 changes: 10 additions & 10 deletions tests/dart2js/boolean_conversion_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -46,7 +46,7 @@ void andTest() {
}

void ifTest() {
bool x = null;
bool x = null as dynamic;
Expect.isFalse(() {
if (x) {
return true;
Expand All @@ -57,7 +57,7 @@ void ifTest() {
}

void forTest() {
bool x = null;
bool x = null as dynamic;
Expect.isFalse(() {
for (; x;) {
return true;
Expand All @@ -67,7 +67,7 @@ void forTest() {
}

void whileTest() {
bool x = null;
bool x = null as dynamic;
Expect.isFalse(() {
while (x) {
return true;
Expand All @@ -77,7 +77,7 @@ void whileTest() {
}

void doTest() {
bool x = null;
bool x = null as dynamic;
Expect.equals(1, () {
int n = 0;
do {
Expand All @@ -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]);
}
4 changes: 2 additions & 2 deletions tests/dart2js/bound_closure_interceptor_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/dart2js/call_signature_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion tests/dart2js/cfe_instance_constant_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions tests/dart2js/checked_setter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import 'package:expect/expect.dart';

class A {
String field;
String? field;
}

class B {
int field;
int? field;
}

@pragma('dart2js:noInline')
Expand Down
1 change: 1 addition & 0 deletions tests/dart2js/class_hierarchy_extends_clause_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
4 changes: 2 additions & 2 deletions tests/dart2js/closure_capture7_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Loading

0 comments on commit 66c1b51

Please sign in to comment.