From 51fe275a62e8ad6b95495ac6b071389673feb4e9 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Thu, 20 Apr 2023 19:55:31 +0000 Subject: [PATCH] Migrate "t" directory language tests off @compile-error. The "@compile-error" comment is an old not-great way of defining static error tests. See: https://github.com/dart-lang/sdk/issues/45634 Change-Id: I4c2840deffe5d790a22facebbcc8a02c1cb98020 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296425 Auto-Submit: Bob Nystrom Reviewed-by: Nate Bosch Commit-Queue: Bob Nystrom --- tests/language/top_level/getter_no_setter1_test.dart | 5 ++++- tests/language/top_level/getter_no_setter2_test.dart | 5 ++++- tests/language/top_level/unresolved_method_test.dart | 5 ++++- tests/language/top_level/unresolved_var_test.dart | 5 ++++- .../type/check_const_function_typedef2_test.dart | 6 +++++- tests/language/type_variable/bounds2_test.dart | 8 ++++++-- .../type_variable/identifier_expression_test.dart | 5 ++++- tests/language/type_variable/scope2_test.dart | 5 ++++- tests/language/type_variable/static_context_test.dart | 11 +++++++++-- tests/language/typedef/check_bounds_generic_test.dart | 6 +++++- tests/language/typedef/check_bounds_test.dart | 6 +++++- tests/language/typedef/check_bounds_unused_test.dart | 6 +++++- .../language_2/top_level/getter_no_setter1_test.dart | 5 ++++- .../language_2/top_level/getter_no_setter2_test.dart | 5 ++++- .../language_2/top_level/unresolved_method_test.dart | 5 ++++- tests/language_2/top_level/unresolved_var_test.dart | 5 ++++- .../type/check_const_function_typedef2_test.dart | 6 +++++- tests/language_2/type_variable/bounds2_test.dart | 8 ++++++-- .../type_variable/identifier_expression_test.dart | 5 ++++- tests/language_2/type_variable/scope2_test.dart | 5 ++++- .../language_2/type_variable/static_context_test.dart | 7 +++++-- .../language_2/typedef/check_bounds_generic_test.dart | 6 +++++- tests/language_2/typedef/check_bounds_test.dart | 6 +++++- .../language_2/typedef/check_bounds_unused_test.dart | 6 +++++- 24 files changed, 114 insertions(+), 28 deletions(-) diff --git a/tests/language/top_level/getter_no_setter1_test.dart b/tests/language/top_level/getter_no_setter1_test.dart index a8b0fa2ec12..8b48ce30dde 100644 --- a/tests/language/top_level/getter_no_setter1_test.dart +++ b/tests/language/top_level/getter_no_setter1_test.dart @@ -13,7 +13,10 @@ int get getter { class Class { method() { - getter++; /*@compile-error=unspecified*/ + getter++; +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL +// [cfe] Setter not found: 'getter'. } } diff --git a/tests/language/top_level/getter_no_setter2_test.dart b/tests/language/top_level/getter_no_setter2_test.dart index 45458390e65..120f2526d20 100644 --- a/tests/language/top_level/getter_no_setter2_test.dart +++ b/tests/language/top_level/getter_no_setter2_test.dart @@ -13,7 +13,10 @@ final int getter = () { class Class { method() { - getter++; /*@compile-error=unspecified*/ + getter++; +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL +// [cfe] Setter not found: 'getter'. } } diff --git a/tests/language/top_level/unresolved_method_test.dart b/tests/language/top_level/unresolved_method_test.dart index 1aa0503549d..f2be01abcb3 100644 --- a/tests/language/top_level/unresolved_method_test.dart +++ b/tests/language/top_level/unresolved_method_test.dart @@ -5,7 +5,10 @@ // Test that an unresolved method call at the top level creates a compile- // time error. -var a = b(); /*@compile-error=unspecified*/ +var a = b(); +// ^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION +// [cfe] Method not found: 'b'. main() { print(a); diff --git a/tests/language/top_level/unresolved_var_test.dart b/tests/language/top_level/unresolved_var_test.dart index c2e5f727f1e..25c326d2dcd 100644 --- a/tests/language/top_level/unresolved_var_test.dart +++ b/tests/language/top_level/unresolved_var_test.dart @@ -5,7 +5,10 @@ // Test that an unresolved identifier at the top level causes a compile-time // error. -var a = b; /*@compile-error=unspecified*/ +var a = b; +// ^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER +// [cfe] Undefined name 'b'. main() { print(a); diff --git a/tests/language/type/check_const_function_typedef2_test.dart b/tests/language/type/check_const_function_typedef2_test.dart index c3674117d14..33ffd6abee9 100644 --- a/tests/language/type/check_const_function_typedef2_test.dart +++ b/tests/language/type/check_const_function_typedef2_test.dart @@ -15,7 +15,11 @@ class A { int foo(String x) => 499; -const a = const A(foo); /*@compile-error=unspecified*/ +const a = const A(foo); +// ^^^ +// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE +// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH +// [cfe] The argument type 'int Function(String)' can't be assigned to the parameter type 'String Function(int)'. main() { a.f(499); diff --git a/tests/language/type_variable/bounds2_test.dart b/tests/language/type_variable/bounds2_test.dart index ecb6c9f62a7..fba737e312a 100644 --- a/tests/language/type_variable/bounds2_test.dart +++ b/tests/language/type_variable/bounds2_test.dart @@ -10,10 +10,14 @@ abstract class J {} abstract class I {} -class A implements I, J {} +class A implements I, J {} +// ^ +// [cfe] Type argument 'T' doesn't conform to the bound 'num' of the type variable 'T' on 'I'. +// ^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { // We are only interested in the instance creation, hence // the result is assigned to `dynamic`. - dynamic a = /*@compile-error=unspecified*/ new A(); + dynamic a = new A(); } diff --git a/tests/language/type_variable/identifier_expression_test.dart b/tests/language/type_variable/identifier_expression_test.dart index 1827c56a2a7..f816b4769a4 100644 --- a/tests/language/type_variable/identifier_expression_test.dart +++ b/tests/language/type_variable/identifier_expression_test.dart @@ -11,7 +11,10 @@ class A { class B { doFunc() { - T.func(); /*@compile-error=unspecified*/ + T.func(); + //^^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD + // [cfe] The method 'func' isn't defined for the class 'Type'. } } diff --git a/tests/language/type_variable/scope2_test.dart b/tests/language/type_variable/scope2_test.dart index 6893e2d771f..997ad98c298 100644 --- a/tests/language/type_variable/scope2_test.dart +++ b/tests/language/type_variable/scope2_test.dart @@ -8,7 +8,10 @@ import "package:expect/expect.dart"; class Foo { // T is not in scope for a static method. - static Foo m() { /*@compile-error=unspecified*/ + static Foo m() { + // ^ + // [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC + // [cfe] Type variables can't be used in static members. return new Foo(); } } diff --git a/tests/language/type_variable/static_context_test.dart b/tests/language/type_variable/static_context_test.dart index e0cd2bc2902..d3ec20ddcad 100644 --- a/tests/language/type_variable/static_context_test.dart +++ b/tests/language/type_variable/static_context_test.dart @@ -6,9 +6,16 @@ class A { static int method() { + // ^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY + // [cfe] A non-null value must be returned since the return type 'int' doesn't allow null. + // error, can't reference a type variable in a static context - var foo = - new T(); /*@compile-error=unspecified*/ + var foo = new T(); + // ^ + // [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE + // [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC + // [cfe] Couldn't find constructor 'T'. } } diff --git a/tests/language/typedef/check_bounds_generic_test.dart b/tests/language/typedef/check_bounds_generic_test.dart index a96fd1fa2c1..a267991b7d1 100644 --- a/tests/language/typedef/check_bounds_generic_test.dart +++ b/tests/language/typedef/check_bounds_generic_test.dart @@ -6,7 +6,11 @@ typedef F = T Function(T x); -void g(/*@compile-error=unspecified*/ F? f) {} +void g(F? f) {} +// ^ +// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'. +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { g(null); diff --git a/tests/language/typedef/check_bounds_test.dart b/tests/language/typedef/check_bounds_test.dart index 45018ec87e1..79e5ff49088 100644 --- a/tests/language/typedef/check_bounds_test.dart +++ b/tests/language/typedef/check_bounds_test.dart @@ -6,7 +6,11 @@ typedef T F(T x); -void g(/*@compile-error=unspecified*/ F? f) {} +void g(F? f) {} +// ^ +// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'. +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { g(null); diff --git a/tests/language/typedef/check_bounds_unused_test.dart b/tests/language/typedef/check_bounds_unused_test.dart index 8f9bed51abf..b7b64244519 100644 --- a/tests/language/typedef/check_bounds_unused_test.dart +++ b/tests/language/typedef/check_bounds_unused_test.dart @@ -7,7 +7,11 @@ typedef void F(); -void g(/*@compile-error=unspecified*/ F? f) {} +void g(F? f) {} +// ^ +// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'. +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { g(null); diff --git a/tests/language_2/top_level/getter_no_setter1_test.dart b/tests/language_2/top_level/getter_no_setter1_test.dart index 65490af3395..3b6ca9dcf4c 100644 --- a/tests/language_2/top_level/getter_no_setter1_test.dart +++ b/tests/language_2/top_level/getter_no_setter1_test.dart @@ -14,7 +14,10 @@ int get getter { class Class { method() { - getter++; /*@compile-error=unspecified*/ + getter++; +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL +// [cfe] Setter not found: 'getter'. } } diff --git a/tests/language_2/top_level/getter_no_setter2_test.dart b/tests/language_2/top_level/getter_no_setter2_test.dart index 57fefcfd90f..c3042ada17b 100644 --- a/tests/language_2/top_level/getter_no_setter2_test.dart +++ b/tests/language_2/top_level/getter_no_setter2_test.dart @@ -14,7 +14,10 @@ final int getter = () { class Class { method() { - getter++; /*@compile-error=unspecified*/ + getter++; +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL +// [cfe] Setter not found: 'getter'. } } diff --git a/tests/language_2/top_level/unresolved_method_test.dart b/tests/language_2/top_level/unresolved_method_test.dart index d32533e4883..2e9e531f86e 100644 --- a/tests/language_2/top_level/unresolved_method_test.dart +++ b/tests/language_2/top_level/unresolved_method_test.dart @@ -7,7 +7,10 @@ // Test that an unresolved method call at the top level creates a compile- // time error. -var a = b(); /*@compile-error=unspecified*/ +var a = b(); +// ^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION +// [cfe] Method not found: 'b'. main() { print(a); diff --git a/tests/language_2/top_level/unresolved_var_test.dart b/tests/language_2/top_level/unresolved_var_test.dart index 9f2ce17774f..40ebb852b81 100644 --- a/tests/language_2/top_level/unresolved_var_test.dart +++ b/tests/language_2/top_level/unresolved_var_test.dart @@ -7,7 +7,10 @@ // Test that an unresolved identifier at the top level causes a compile-time // error. -var a = b; /*@compile-error=unspecified*/ +var a = b; +// ^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER +// [cfe] Undefined name 'b'. main() { print(a); diff --git a/tests/language_2/type/check_const_function_typedef2_test.dart b/tests/language_2/type/check_const_function_typedef2_test.dart index d29555cd165..bea07a038e6 100644 --- a/tests/language_2/type/check_const_function_typedef2_test.dart +++ b/tests/language_2/type/check_const_function_typedef2_test.dart @@ -17,7 +17,11 @@ class A { int foo(String x) => 499; -const a = const A(foo); /*@compile-error=unspecified*/ +const a = const A(foo); +// ^^^ +// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE +// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH +// [cfe] The argument type 'int Function(String)' can't be assigned to the parameter type 'String Function(int)'. main() { a.f(499); diff --git a/tests/language_2/type_variable/bounds2_test.dart b/tests/language_2/type_variable/bounds2_test.dart index 0e82f3c1850..c1e7805dcfd 100644 --- a/tests/language_2/type_variable/bounds2_test.dart +++ b/tests/language_2/type_variable/bounds2_test.dart @@ -12,10 +12,14 @@ abstract class J {} abstract class I {} -class A implements I, J {} +class A implements I, J {} +// ^ +// [cfe] Type argument 'T' doesn't conform to the bound 'num' of the type variable 'T' on 'I'. +// ^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { // We are only interested in the instance creation, hence // the result is assigned to `dynamic`. - dynamic a = /*@compile-error=unspecified*/ new A(); + dynamic a = new A(); } diff --git a/tests/language_2/type_variable/identifier_expression_test.dart b/tests/language_2/type_variable/identifier_expression_test.dart index 497a27dccb4..db821c834dc 100644 --- a/tests/language_2/type_variable/identifier_expression_test.dart +++ b/tests/language_2/type_variable/identifier_expression_test.dart @@ -13,7 +13,10 @@ class A { class B { doFunc() { - T.func(); /*@compile-error=unspecified*/ + T.func(); + //^^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD + // [cfe] The method 'func' isn't defined for the class 'Type'. } } diff --git a/tests/language_2/type_variable/scope2_test.dart b/tests/language_2/type_variable/scope2_test.dart index 86d4c291494..dd7cade611f 100644 --- a/tests/language_2/type_variable/scope2_test.dart +++ b/tests/language_2/type_variable/scope2_test.dart @@ -10,7 +10,10 @@ import "package:expect/expect.dart"; class Foo { // T is not in scope for a static method. - static Foo m() { /*@compile-error=unspecified*/ + static Foo m() { + // ^ + // [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC + // [cfe] Type variables can't be used in static members. return new Foo(); } } diff --git a/tests/language_2/type_variable/static_context_test.dart b/tests/language_2/type_variable/static_context_test.dart index 5f613f7b03d..f579e8b33d0 100644 --- a/tests/language_2/type_variable/static_context_test.dart +++ b/tests/language_2/type_variable/static_context_test.dart @@ -9,8 +9,11 @@ class A { static int method() { // error, can't reference a type variable in a static context - var foo = - new T(); /*@compile-error=unspecified*/ + var foo = new T(); + // ^ + // [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE + // [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC + // [cfe] Couldn't find constructor 'T'. } } diff --git a/tests/language_2/typedef/check_bounds_generic_test.dart b/tests/language_2/typedef/check_bounds_generic_test.dart index dfd20ccf411..7cab6acf693 100644 --- a/tests/language_2/typedef/check_bounds_generic_test.dart +++ b/tests/language_2/typedef/check_bounds_generic_test.dart @@ -8,7 +8,11 @@ typedef F = T Function(T x); -void g(/*@compile-error=unspecified*/ F f) {} +void g(F f) {} +// ^ +// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'. +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { g(null); diff --git a/tests/language_2/typedef/check_bounds_test.dart b/tests/language_2/typedef/check_bounds_test.dart index 382a68e013f..5fba1eb9a19 100644 --- a/tests/language_2/typedef/check_bounds_test.dart +++ b/tests/language_2/typedef/check_bounds_test.dart @@ -8,7 +8,11 @@ typedef T F(T x); -void g(/*@compile-error=unspecified*/ F f) {} +void g(F f) {} +// ^ +// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'. +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { g(null); diff --git a/tests/language_2/typedef/check_bounds_unused_test.dart b/tests/language_2/typedef/check_bounds_unused_test.dart index b4fc11bbcff..53ac761ab6a 100644 --- a/tests/language_2/typedef/check_bounds_unused_test.dart +++ b/tests/language_2/typedef/check_bounds_unused_test.dart @@ -9,7 +9,11 @@ typedef void F(); -void g(/*@compile-error=unspecified*/ F f) {} +void g(F f) {} +// ^ +// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'. +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS main() { g(null);