From cd5883fa851e8e44e3914fa771c7c62a775cc2db Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Thu, 20 Apr 2023 17:56:18 +0000 Subject: [PATCH] Migrate "n" through "p" directory language tests off @compile-error. The "@compile-error" comment is an old not-great way of defining static error tests. Change-Id: I6564643302f66c5920b38d2269c160099322560b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296421 Reviewed-by: Jake Macdonald Commit-Queue: Jake Macdonald Auto-Submit: Bob Nystrom --- tests/language/no_such_method/nsm5_test.dart | 5 +- tests/language/operator/equals_test.dart | 10 ++- .../operator/logical_expression3_test.dart | 5 +- tests/language/operator/operator5_test.dart | 13 ++-- .../constant_array_string_access_test.dart | 62 ------------------ tests/language/parameter/named2_test.dart | 5 +- tests/language/parameter/named3_test.dart | 5 +- tests/language/parameter/named4_test.dart | 5 +- .../language_2/no_such_method/nsm5_test.dart | 5 +- tests/language_2/operator/equals_test.dart | 10 ++- .../operator/logical_expression3_test.dart | 5 +- tests/language_2/operator/operator5_test.dart | 13 ++-- .../constant_array_string_access_test.dart | 64 ------------------- tests/language_2/parameter/named2_test.dart | 5 +- tests/language_2/parameter/named3_test.dart | 5 +- tests/language_2/parameter/named4_test.dart | 5 +- 16 files changed, 72 insertions(+), 150 deletions(-) delete mode 100644 tests/language/optimize/constant_array_string_access_test.dart delete mode 100644 tests/language_2/optimize/constant_array_string_access_test.dart diff --git a/tests/language/no_such_method/nsm5_test.dart b/tests/language/no_such_method/nsm5_test.dart index b8ddb774348..36c0560092a 100644 --- a/tests/language/no_such_method/nsm5_test.dart +++ b/tests/language/no_such_method/nsm5_test.dart @@ -15,6 +15,9 @@ abstract class Foo { int foo(); } -/*@compile-error=unspecified*/ class WarnMe extends Mock implements Foo {} +class WarnMe extends Mock implements Foo {} +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER +// [cfe] The non-abstract class 'WarnMe' is missing implementations for these members: main() {} diff --git a/tests/language/operator/equals_test.dart b/tests/language/operator/equals_test.dart index 109c7c6dc3a..1e27c63640d 100644 --- a/tests/language/operator/equals_test.dart +++ b/tests/language/operator/equals_test.dart @@ -8,11 +8,17 @@ import 'package:expect/expect.dart'; class A { - operator ==(other) => 42; /*@compile-error=unspecified*/ + operator ==(other) => 42; + // ^^ + // [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE + // [cfe] A value of type 'int' can't be returned from a function with return type 'bool'. } class B extends A { - foo() => (super == null) + 4; /*@compile-error=unspecified*/ + foo() => (super == null) + 4; + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_OPERATOR + // [cfe] The operator '+' isn't defined for the class 'bool'. } main() { diff --git a/tests/language/operator/logical_expression3_test.dart b/tests/language/operator/logical_expression3_test.dart index 9d6efa98aaa..dc1157f2863 100644 --- a/tests/language/operator/logical_expression3_test.dart +++ b/tests/language/operator/logical_expression3_test.dart @@ -22,7 +22,10 @@ main() { // When the lhs of a logical or fails, it must not assume that all negative is // checks in it, have failed. // Here, the `o is! num` check succeeds, but the length test failed. - if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) { /*@compile-error=unspecified*/ + if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) { + // ^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER + // [cfe] The getter 'length' isn't defined for the class 'Object'. Expect.fail("Type-check failed"); } } diff --git a/tests/language/operator/operator5_test.dart b/tests/language/operator/operator5_test.dart index a6d177df570..1cbda98f2e0 100644 --- a/tests/language/operator/operator5_test.dart +++ b/tests/language/operator/operator5_test.dart @@ -5,11 +5,14 @@ import "package:expect/expect.dart"; class A { - operator ==(other) => 1; /*@compile-error=unspecified*/ - operator <(other) => null; /*@compile-error=unspecified*/ - operator <=(other) => 499; /*@compile-error=unspecified*/ - operator >(other) => "foo"; /*@compile-error=unspecified*/ - operator >=(other) => 42; /*@compile-error=unspecified*/ + operator ==(other) => 1; + // ^ + // [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE + // [cfe] A value of type 'int' can't be returned from a function with return type 'bool'. + operator <(other) => null; + operator <=(other) => 499; + operator >(other) => "foo"; + operator >=(other) => 42; } // This triggered a bug in Dart2Js: equality operator was always boolified. diff --git a/tests/language/optimize/constant_array_string_access_test.dart b/tests/language/optimize/constant_array_string_access_test.dart deleted file mode 100644 index f2efc0e2f85..00000000000 --- a/tests/language/optimize/constant_array_string_access_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2012, 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. -// VMOptions=--optimization-counter-threshold=10 --no-use-osr - -import "package:expect/expect.dart"; - -// Test optimized constant string and constant array access. - -void testConstantStringAndIndexCodeUnitAt() { - int test(b) { - if (b) return "hest".codeUnitAt(400); - return "hest".codeUnitAt(2); - } - - Expect.throws(() => test(true)); - for (int i = 0; i < 20; i++) test(false); - Expect.throws(() => test(true)); -} - -void testConstantArrayAndIndexAt() { - int testPositive(b) { - var a = const [1, 2, 3, 4]; - if (b) return a[400]; - return a[2]; - } - - int testNegative(b) { - var a = const [1, 2, 3, 4]; - if (b) return a[-1]; - return a[2]; - } - - Expect.throws(() => testPositive(true)); - for (int i = 0; i < 20; i++) testPositive(false); - Expect.throws(() => testPositive(true)); - - Expect.throws(() => testNegative(true)); - for (int i = 0; i < 20; i++) testNegative(false); - Expect.throws(() => testNegative(true)); -} - -foo(a) { - if (a == 1) { - return 2; - } - var aa = const [1, 2]; - return aa[2.3]; /*@compile-error=unspecified*/ -} - -void testNonSmiIndex() { - for (int i = 0; i < 20; i++) { - foo(1); - } - Expect.throws(() => foo(2)); -} - -main() { - testConstantStringAndIndexCodeUnitAt(); - testConstantArrayAndIndexAt(); - testNonSmiIndex(); -} diff --git a/tests/language/parameter/named2_test.dart b/tests/language/parameter/named2_test.dart index 3d6f65803b4..0d2d6489b96 100644 --- a/tests/language/parameter/named2_test.dart +++ b/tests/language/parameter/named2_test.dart @@ -10,5 +10,8 @@ int test(int a, [int? b]) { main() { // Parameter b passed twice, as positional and named. - test(10, 25, b: 26); /*@compile-error=unspecified*/ + test(10, 25, b: 26); + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER + // [cfe] No named parameter with the name 'b'. } diff --git a/tests/language/parameter/named3_test.dart b/tests/language/parameter/named3_test.dart index 03f87a2b97a..2591331ae0d 100644 --- a/tests/language/parameter/named3_test.dart +++ b/tests/language/parameter/named3_test.dart @@ -10,5 +10,8 @@ int test(int a, [int? b]) { main() { // 1 positional arg, as expected. Param x does not exist. - test(10, x: 99); /*@compile-error=unspecified*/ + test(10, x: 99); + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER + // [cfe] No named parameter with the name 'x'. } diff --git a/tests/language/parameter/named4_test.dart b/tests/language/parameter/named4_test.dart index 57017583eaf..8ec1ad5679c 100644 --- a/tests/language/parameter/named4_test.dart +++ b/tests/language/parameter/named4_test.dart @@ -15,5 +15,8 @@ int test(int a) { main() { // 1 positional arg, as expected. Param x does not exist. - test(10, x: 99); /*@compile-error=unspecified*/ + test(10, x: 99); + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER + // [cfe] No named parameter with the name 'x'. } diff --git a/tests/language_2/no_such_method/nsm5_test.dart b/tests/language_2/no_such_method/nsm5_test.dart index d372da79236..79b485a8651 100644 --- a/tests/language_2/no_such_method/nsm5_test.dart +++ b/tests/language_2/no_such_method/nsm5_test.dart @@ -17,6 +17,9 @@ abstract class Foo { int foo(); } -/*@compile-error=unspecified*/ class WarnMe extends Mock implements Foo {} +class WarnMe extends Mock implements Foo {} +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER +// [cfe] The non-abstract class 'WarnMe' is missing implementations for these members: main() {} diff --git a/tests/language_2/operator/equals_test.dart b/tests/language_2/operator/equals_test.dart index a87b4d1bd1d..a6e496ee22c 100644 --- a/tests/language_2/operator/equals_test.dart +++ b/tests/language_2/operator/equals_test.dart @@ -10,11 +10,17 @@ import 'package:expect/expect.dart'; class A { - operator ==(other) => 42; /*@compile-error=unspecified*/ + operator ==(other) => 42; + // ^^ + // [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE + // [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'. } class B extends A { - foo() => (super == null) + 4; /*@compile-error=unspecified*/ + foo() => (super == null) + 4; + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_OPERATOR + // [cfe] The operator '+' isn't defined for the class 'bool'. } main() { diff --git a/tests/language_2/operator/logical_expression3_test.dart b/tests/language_2/operator/logical_expression3_test.dart index ca7197da854..04512ca1761 100644 --- a/tests/language_2/operator/logical_expression3_test.dart +++ b/tests/language_2/operator/logical_expression3_test.dart @@ -24,7 +24,10 @@ main() { // When the lhs of a logical or fails, it must not assume that all negative is // checks in it, have failed. // Here, the `o is! num` check succeeds, but the length test failed. - if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) { /*@compile-error=unspecified*/ + if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) { + // ^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER + // [cfe] The getter 'length' isn't defined for the class 'Object'. Expect.fail("Type-check failed"); } } diff --git a/tests/language_2/operator/operator5_test.dart b/tests/language_2/operator/operator5_test.dart index c892ca27079..cbcbd38d73b 100644 --- a/tests/language_2/operator/operator5_test.dart +++ b/tests/language_2/operator/operator5_test.dart @@ -7,11 +7,14 @@ import "package:expect/expect.dart"; class A { - operator ==(other) => 1; /*@compile-error=unspecified*/ - operator <(other) => null; /*@compile-error=unspecified*/ - operator <=(other) => 499; /*@compile-error=unspecified*/ - operator >(other) => "foo"; /*@compile-error=unspecified*/ - operator >=(other) => 42; /*@compile-error=unspecified*/ + operator ==(other) => 1; + // ^ + // [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE + // [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'. + operator <(other) => null; + operator <=(other) => 499; + operator >(other) => "foo"; + operator >=(other) => 42; } // This triggered a bug in Dart2Js: equality operator was always boolified. diff --git a/tests/language_2/optimize/constant_array_string_access_test.dart b/tests/language_2/optimize/constant_array_string_access_test.dart deleted file mode 100644 index 2fc2b3ff11b..00000000000 --- a/tests/language_2/optimize/constant_array_string_access_test.dart +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2012, 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. -// VMOptions=--optimization-counter-threshold=10 --no-use-osr - -// @dart = 2.9 - -import "package:expect/expect.dart"; - -// Test optimized constant string and constant array access. - -int testConstantStringAndIndexCodeUnitAt() { - int test(b) { - if (b) return "hest".codeUnitAt(400); - return "hest".codeUnitAt(2); - } - - Expect.throws(() => test(true)); - for (int i = 0; i < 20; i++) test(false); - Expect.throws(() => test(true)); -} - -int testConstantArrayAndIndexAt() { - int testPositive(b) { - var a = const [1, 2, 3, 4]; - if (b) return a[400]; - return a[2]; - } - - int testNegative(b) { - var a = const [1, 2, 3, 4]; - if (b) return a[-1]; - return a[2]; - } - - Expect.throws(() => testPositive(true)); - for (int i = 0; i < 20; i++) testPositive(false); - Expect.throws(() => testPositive(true)); - - Expect.throws(() => testNegative(true)); - for (int i = 0; i < 20; i++) testNegative(false); - Expect.throws(() => testNegative(true)); -} - -foo(a) { - if (a == 1) { - return 2; - } - var aa = const [1, 2]; - return aa[2.3]; /*@compile-error=unspecified*/ -} - -int testNonSmiIndex() { - for (int i = 0; i < 20; i++) { - foo(1); - } - Expect.throws(() => foo(2)); -} - -main() { - testConstantStringAndIndexCodeUnitAt(); - testConstantArrayAndIndexAt(); - testNonSmiIndex(); -} diff --git a/tests/language_2/parameter/named2_test.dart b/tests/language_2/parameter/named2_test.dart index de1413ccba2..c58c842023e 100644 --- a/tests/language_2/parameter/named2_test.dart +++ b/tests/language_2/parameter/named2_test.dart @@ -12,5 +12,8 @@ int test(int a, [int b]) { main() { // Parameter b passed twice, as positional and named. - test(10, 25, b: 26); /*@compile-error=unspecified*/ + test(10, 25, b: 26); + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER + // [cfe] No named parameter with the name 'b'. } diff --git a/tests/language_2/parameter/named3_test.dart b/tests/language_2/parameter/named3_test.dart index fcd8a239bb4..20f340ec827 100644 --- a/tests/language_2/parameter/named3_test.dart +++ b/tests/language_2/parameter/named3_test.dart @@ -12,5 +12,8 @@ int test(int a, [int b]) { main() { // 1 positional arg, as expected. Param x does not exist. - test(10, x: 99); /*@compile-error=unspecified*/ + test(10, x: 99); + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER + // [cfe] No named parameter with the name 'x'. } diff --git a/tests/language_2/parameter/named4_test.dart b/tests/language_2/parameter/named4_test.dart index 509b86d9572..a107cef33f3 100644 --- a/tests/language_2/parameter/named4_test.dart +++ b/tests/language_2/parameter/named4_test.dart @@ -17,5 +17,8 @@ int test(int a) { main() { // 1 positional arg, as expected. Param x does not exist. - test(10, x: 99); /*@compile-error=unspecified*/ + test(10, x: 99); + // ^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER + // [cfe] No named parameter with the name 'x'. }