From 66c1b51c07b74f98911ddbb7fa5a612618afc128 Mon Sep 17 00:00:00 2001 From: Joshua Litt Date: Fri, 26 Jun 2020 15:21:42 +0000 Subject: [PATCH] [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 Commit-Queue: Joshua Litt --- WATCHLISTS | 2 +- tests/dart2js/12320_test.dart | 2 +- tests/dart2js/17856_test.dart | 2 +- tests/dart2js/29130_test.dart | 2 +- tests/dart2js/32770c_test.dart | 4 +- tests/dart2js/32828_test.dart | 4 +- tests/dart2js/37494_test.dart | 2 +- tests/dart2js/41449a_test.dart | 57 +++++++++++++++++++ tests/dart2js/41449b_test.dart | 57 +++++++++++++++++++ tests/dart2js/42189_test.dart | 37 ++++++++++++ tests/dart2js/881_test.dart | 2 +- tests/dart2js/assert_with_message_test.dart | 2 +- tests/dart2js/boolean_conversion_test.dart | 20 +++---- .../bound_closure_interceptor_type_test.dart | 4 +- tests/dart2js/call_signature_test.dart | 2 +- tests/dart2js/cfe_instance_constant_test.dart | 2 +- tests/dart2js/checked_setter_test.dart | 4 +- .../class_hierarchy_extends_clause_test.dart | 1 + tests/dart2js/closure_capture7_test.dart | 4 +- .../dart2js/compound_operator_index_test.dart | 2 +- 20 files changed, 180 insertions(+), 32 deletions(-) create mode 100644 tests/dart2js/41449a_test.dart create mode 100644 tests/dart2js/41449b_test.dart create mode 100644 tests/dart2js/42189_test.dart diff --git a/WATCHLISTS b/WATCHLISTS index a07b66516f73..46723638ed47 100644 --- a/WATCHLISTS +++ b/WATCHLISTS @@ -28,7 +28,7 @@ 'filepath': ( '^pkg/compiler|' '^sdk/lib/_internal/js_runtime|' - '^tests/compiler/dart2js' + '^tests/dart2js' ) }, 'dartdevc': { diff --git a/tests/dart2js/12320_test.dart b/tests/dart2js/12320_test.dart index d47c05a0b3a7..6871ab1a755b 100644 --- a/tests/dart2js/12320_test.dart +++ b/tests/dart2js/12320_test.dart @@ -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); diff --git a/tests/dart2js/17856_test.dart b/tests/dart2js/17856_test.dart index aa5a243308d2..27cebd5f9fc7 100644 --- a/tests/dart2js/17856_test.dart +++ b/tests/dart2js/17856_test.dart @@ -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(); } diff --git a/tests/dart2js/29130_test.dart b/tests/dart2js/29130_test.dart index e4daa3410766..4426f262634e 100644 --- a/tests/dart2js/29130_test.dart +++ b/tests/dart2js/29130_test.dart @@ -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 diff --git a/tests/dart2js/32770c_test.dart b/tests/dart2js/32770c_test.dart index 15ac166ab6a6..72602a8801f0 100644 --- a/tests/dart2js/32770c_test.dart +++ b/tests/dart2js/32770c_test.dart @@ -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 futureToA(Future future, [J wrapValue(T value)]) { +A futureToA(Future future, [J wrapValue(T value)?]) { return new A( (void resolveFn(J value), void rejectFn(error)) { future.then((value) { diff --git a/tests/dart2js/32828_test.dart b/tests/dart2js/32828_test.dart index c56a90491f01..12b82ca57a25 100644 --- a/tests/dart2js/32828_test.dart +++ b/tests/dart2js/32828_test.dart @@ -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(void Function(T) f, [a]) {} + void m2(void Function(T)? f, [a]) {} } main() => new A().m2(null); diff --git a/tests/dart2js/37494_test.dart b/tests/dart2js/37494_test.dart index d2d8283b2177..c9402994ba00 100644 --- a/tests/dart2js/37494_test.dart +++ b/tests/dart2js/37494_test.dart @@ -46,7 +46,7 @@ class Example extends ListBase { @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. } } diff --git a/tests/dart2js/41449a_test.dart b/tests/dart2js/41449a_test.dart new file mode 100644 index 000000000000..5115f50da552 --- /dev/null +++ b/tests/dart2js/41449a_test.dart @@ -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(AAA a, String expected) { + // call-through getter 'foo' with one type argument. + Expect.equals(expected, a.foo()); +} + +@pragma('dart2js:noInline') +test2(AAA a, String expected) { + // call-through getter 'foo' with two type arguments. + Expect.equals(expected, a.foo()); +} + +main() { + test1(B1(

() => '$P'), 'int'); + test1(B2(() => '$Q'), 'num'); + test1(B3(() => '$R'), 'double'); + + test2(B1(() => '$A $B'), 'int num'); + test2(B2(() => '$X $Y'), 'num int'); + test2(B3(() => '$C $D'), 'double String'); +} diff --git a/tests/dart2js/41449b_test.dart b/tests/dart2js/41449b_test.dart new file mode 100644 index 000000000000..addeb57829ee --- /dev/null +++ b/tests/dart2js/41449b_test.dart @@ -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(AAA a, String expected) { + // call-through getter 'foo' with one type argument. + Expect.equals(expected, a.foo()); +} + +@pragma('dart2js:noInline') +test2(AAA a, String expected) { + // call-through getter 'foo' with two type arguments. + Expect.equals(expected, a.foo()); +} + +main() { + test1(B1(

() => '$P'), 'int'); + test1(B2(() => '$Q'), 'num'); + test1(B3(() => '$R'), 'double'); + + test2(B1(() => '$A $B'), 'int num'); + test2(B2(() => '$X $Y'), 'num int'); + test2(B3(() => '$C $D'), 'double String'); +} diff --git a/tests/dart2js/42189_test.dart b/tests/dart2js/42189_test.dart new file mode 100644 index 000000000000..a581061b912e --- /dev/null +++ b/tests/dart2js/42189_test.dart @@ -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); +} diff --git a/tests/dart2js/881_test.dart b/tests/dart2js/881_test.dart index 5be849c430fe..59c00afea7e3 100644 --- a/tests/dart2js/881_test.dart +++ b/tests/dart2js/881_test.dart @@ -6,6 +6,6 @@ @pragma('dart2js:disableFinal') void main() { - String v = null; + String? v = null; print('${v.hashCode}'); } diff --git a/tests/dart2js/assert_with_message_test.dart b/tests/dart2js/assert_with_message_test.dart index 993ab115d39a..f84873452200 100644 --- a/tests/dart2js/assert_with_message_test.dart +++ b/tests/dart2js/assert_with_message_test.dart @@ -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'); diff --git a/tests/dart2js/boolean_conversion_test.dart b/tests/dart2js/boolean_conversion_test.dart index 64cd44157176..48c1cb672f8c 100644 --- a/tests/dart2js/boolean_conversion_test.dart +++ b/tests/dart2js/boolean_conversion_test.dart @@ -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]); } diff --git a/tests/dart2js/bound_closure_interceptor_type_test.dart b/tests/dart2js/bound_closure_interceptor_type_test.dart index 7d4ea1039d58..3410dbee6cc2 100644 --- a/tests/dart2js/bound_closure_interceptor_type_test.dart +++ b/tests/dart2js/bound_closure_interceptor_type_test.dart @@ -15,7 +15,7 @@ import "package:expect/expect.dart"; class A { 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); diff --git a/tests/dart2js/call_signature_test.dart b/tests/dart2js/call_signature_test.dart index 20978d52b595..b675f3bed23a 100644 --- a/tests/dart2js/call_signature_test.dart +++ b/tests/dart2js/call_signature_test.dart @@ -9,7 +9,7 @@ import 'package:expect/expect.dart'; class A { /// 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 { diff --git a/tests/dart2js/cfe_instance_constant_test.dart b/tests/dart2js/cfe_instance_constant_test.dart index 0c202c1ce041..3bd991789d2d 100644 --- a/tests/dart2js/cfe_instance_constant_test.dart +++ b/tests/dart2js/cfe_instance_constant_test.dart @@ -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); } diff --git a/tests/dart2js/checked_setter_test.dart b/tests/dart2js/checked_setter_test.dart index 60ca4fafa8e8..9b86f4db33f9 100644 --- a/tests/dart2js/checked_setter_test.dart +++ b/tests/dart2js/checked_setter_test.dart @@ -5,11 +5,11 @@ import 'package:expect/expect.dart'; class A { - String field; + String? field; } class B { - int field; + int? field; } @pragma('dart2js:noInline') diff --git a/tests/dart2js/class_hierarchy_extends_clause_test.dart b/tests/dart2js/class_hierarchy_extends_clause_test.dart index b6131c90d735..b61ec0fc7bab 100644 --- a/tests/dart2js/class_hierarchy_extends_clause_test.dart +++ b/tests/dart2js/class_hierarchy_extends_clause_test.dart @@ -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 {} diff --git a/tests/dart2js/closure_capture7_test.dart b/tests/dart2js/closure_capture7_test.dart index 045f6a528503..9b8482d277fd 100644 --- a/tests/dart2js/closure_capture7_test.dart +++ b/tests/dart2js/closure_capture7_test.dart @@ -3,12 +3,12 @@ // BSD-style license that can be found in the LICENSE file. class A { - List xs; + 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)); } } diff --git a/tests/dart2js/compound_operator_index_test.dart b/tests/dart2js/compound_operator_index_test.dart index 508a9e0aad58..0c527d27bb85 100644 --- a/tests/dart2js/compound_operator_index_test.dart +++ b/tests/dart2js/compound_operator_index_test.dart @@ -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);