From 5723f42f6921b501b7e60682125e5ab3406dc0f1 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 14 May 2026 09:40:43 -0700 Subject: [PATCH] CQ. Trim diagnostic messages in expectations. See https://dart-review.googlesource.com/c/sdk/+/501764/comment/6a88eca8_ab5cf6e4/ Change-Id: Ic7752669660b88003460167f9d9e3926e0d19c3e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503541 Reviewed-by: Paul Berry Commit-Queue: Konstantin Shcheglov --- .../argument_type_not_assignable_test.dart | 92 +++++++++---------- ..._constructor_param_type_mismatch_test.dart | 12 +-- .../const_eval_throws_exception_test.dart | 8 +- .../const_eval_type_bool_int_test.dart | 10 +- .../diagnostics/const_eval_type_num_test.dart | 20 ++-- .../src/diagnostics/could_not_infer_test.dart | 14 +-- .../duplicate_field_name_test.dart | 12 +-- ...one_positional_no_trailing_comma_test.dart | 4 +- .../lib/src/expected_diagnostics.dart | 11 ++- 9 files changed, 93 insertions(+), 90 deletions(-) diff --git a/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart index b14e4751041..e796e9a483f 100644 --- a/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart @@ -30,7 +30,7 @@ class _A {} f() { g((_A a) {}); // ^^^^^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'Null Function(_A)' can't be assigned to the parameter type 'dynamic Function(_A)'. +// [diag.argumentTypeNotAssignable] The argument type 'Null Function(_A)' can't be assigned to the parameter type 'dynamic Function(_A)'. }'''); // The name _A is private to the library it's defined in, so this is a type // mismatch. Furthermore, the error message should mention both _A and the @@ -45,7 +45,7 @@ extension type const A(String _) {} @A(0) // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. void f() {} '''); } @@ -57,7 +57,7 @@ class A { } @A.fromInt('0') // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. main() {} '''); } @@ -69,7 +69,7 @@ class A { } @A.fromInt('0') // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. main() { }'''); } @@ -92,7 +92,7 @@ class A { } @A('0') // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. main() { }'''); } @@ -105,7 +105,7 @@ class A { f(A a) { a + '0'; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -118,10 +118,10 @@ class A { void f(A a, A? aq) { a == 0; // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'. aq == 1; // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'. aq == aq; aq == null; } @@ -137,7 +137,7 @@ Predicate f() => (String s) => false; void main() { f().call(3); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -155,7 +155,7 @@ main() { A a = new A(); a.. ma().mb(0); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -167,7 +167,7 @@ class A { main() { const A(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. // [diag.constConstructorParamTypeMismatch] A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor. }'''); } @@ -180,7 +180,7 @@ class A { class B extends A { const B() : super(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -190,7 +190,7 @@ m() { num y = 1; n(y); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'num' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'num' can't be assigned to the parameter type 'int'. } n(int x) {} '''); @@ -202,7 +202,7 @@ m() { int? y; n(y); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int?' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'int?' can't be assigned to the parameter type 'int'. } n(int x) {} '''); @@ -223,7 +223,7 @@ n(int i) {} enum E { v(0); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. // [diag.constConstructorParamTypeMismatch] A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor. const E(String a); } @@ -270,7 +270,7 @@ class C { var g = C.new; var x = g('Hello'); // ^^^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } @@ -299,7 +299,7 @@ void f(T a) {} var g = f; var x = g('Hello'); // ^^^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } @@ -330,7 +330,7 @@ void f(Iterable Function() g, void Function(T) h) { main() { (int x) {} (''); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -340,7 +340,7 @@ m() { var a = new A(); a.n(() => 0); // ^^^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'void Function()' can't be assigned to the parameter type 'void Function(int)'. +// [diag.argumentTypeNotAssignable] The argument type 'void Function()' can't be assigned to the parameter type 'void Function(int)'. } class A { n(void f(int i)) {} @@ -406,7 +406,7 @@ class A { f(A a) { a['0']; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -419,13 +419,13 @@ class A { f(A a) { a['0'] += 0; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. ++a['0']; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. a['0']++; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -437,7 +437,7 @@ class A { f(A a) { a['0'] = 0; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -450,13 +450,13 @@ class A { f(A a) { a['0'] += 0; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. ++a['0']; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. a['0']++; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -466,7 +466,7 @@ m() { var i = ''; n(i); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } n(int i) {} '''); @@ -480,7 +480,7 @@ class A { f(A a) { a('0'); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -493,7 +493,7 @@ main() { A a = new A(); a('0'); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -502,7 +502,7 @@ main() { a(b(int p)) { b('0'); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -512,7 +512,7 @@ class A { m(f(K k), V v) { f(v); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'V' can't be assigned to the parameter type 'K'. +// [diag.argumentTypeNotAssignable] The argument type 'V' can't be assigned to the parameter type 'K'. } }'''); } @@ -524,7 +524,7 @@ void funBool(bool b) {} main() { acceptFunOptBool(funBool); // ^^^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'. +// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'. }'''); } @@ -537,7 +537,7 @@ class C { main() { acceptFunOptBool(C.funBool); // ^^^^^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'. +// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'. }'''); } @@ -549,7 +549,7 @@ class A { f(A a) { a.m(1); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -559,7 +559,7 @@ f({String p = ''}) {} main() { f(p: 42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -569,7 +569,7 @@ f([String p = '']) {} main() { f(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -579,7 +579,7 @@ f(String p) {} main() { f(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -589,7 +589,7 @@ typedef A(T p); f(A a) { a('1'); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -601,7 +601,7 @@ main() { A a = getA(); a('1'); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -611,7 +611,7 @@ typedef A(int p); f(A a) { a('1'); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. }'''); } @@ -632,7 +632,7 @@ main() { Map m = {}; m['x'] = 0; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } '''); } @@ -644,7 +644,7 @@ main() { Map m = {}; m['x'] ??= 0; // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } '''); } @@ -657,7 +657,7 @@ class A { main() { new A(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -669,7 +669,7 @@ class A { main() { new A(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } @@ -681,7 +681,7 @@ class A { main() { new A(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. }'''); } diff --git a/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart b/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart index 1f8cad267b5..206ed985ea0 100644 --- a/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart +++ b/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart @@ -54,7 +54,7 @@ class A { foo(x) => 1; var v = const A(foo); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'dynamic Function(dynamic)' can't be assigned to the parameter type 'Int2String'. +// [diag.argumentTypeNotAssignable] The argument type 'dynamic Function(dynamic)' can't be assigned to the parameter type 'Int2String'. // [diag.constConstructorParamTypeMismatch] A value of type 'dynamic Function(dynamic)' can't be assigned to a parameter of type 'String Function(int)' in a const constructor. '''); } @@ -212,7 +212,7 @@ class C { const A u = const A(); var v = const C(u); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'A' can't be assigned to the parameter type 'B'. +// [diag.argumentTypeNotAssignable] The argument type 'A' can't be assigned to the parameter type 'B'. // [diag.constConstructorParamTypeMismatch] A value of type 'A' can't be assigned to a parameter of type 'B' in a const constructor. '''); } @@ -229,7 +229,7 @@ class A { int foo(String x) => 1; var v = const A(foo); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'int Function(String)' can't be assigned to the parameter type 'Int2String'. +// [diag.argumentTypeNotAssignable] The argument type 'int Function(String)' can't be assigned to the parameter type 'Int2String'. // [diag.constConstructorParamTypeMismatch] A value of type 'int Function(String)' can't be assigned to a parameter of type 'String Function(int)' in a const constructor. '''); } @@ -242,7 +242,7 @@ class A { } var v = const A('foo'); // ^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. // [diag.constConstructorParamTypeMismatch] A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor. '''); } @@ -266,7 +266,7 @@ class A { } var v = const A('foo'); // ^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. // [diag.constConstructorParamTypeMismatch] A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor. '''); } @@ -278,7 +278,7 @@ class A { } var v = const A('foo'); // ^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. // [diag.constConstructorParamTypeMismatch] A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor. '''); } diff --git a/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart b/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart index 158464f0b61..2f8b33e4c6d 100644 --- a/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart +++ b/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart @@ -376,12 +376,12 @@ var b1 = const bool.fromEnvironment(1); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. var b2 = const bool.fromEnvironment('x', defaultValue: 1); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'bool'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'bool'. '''); } @@ -394,7 +394,7 @@ var b = const bool.fromEnvironment('x', defaultValue: 1); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'bool'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'bool'. '''); } @@ -463,7 +463,7 @@ var s2 = const Symbol(3); // ^^^^^^^^^^^^^^^ // [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. '''); } diff --git a/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_int_test.dart b/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_int_test.dart index 3ebb40cfc29..8f138632eae 100644 --- a/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_int_test.dart +++ b/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_int_test.dart @@ -21,7 +21,7 @@ const b = a & ''; // ^^^^^^ // [diag.constEvalTypeBoolInt] In constant expressions, operands of this operator must be of type 'bool' or 'int'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } @@ -32,7 +32,7 @@ const b = a | ''; // ^^^^^^ // [diag.constEvalTypeBoolInt] In constant expressions, operands of this operator must be of type 'bool' or 'int'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } @@ -43,7 +43,7 @@ const b = a ^ ''; // ^^^^^^ // [diag.constEvalTypeBoolInt] In constant expressions, operands of this operator must be of type 'bool' or 'int'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } @@ -54,7 +54,7 @@ const b = a << ''; // ^^^^^^^ // [diag.constEvalTypeInt] In constant expressions, operands of this operator must be of type 'int'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } @@ -65,7 +65,7 @@ const b = a >> ''; // ^^^^^^^ // [diag.constEvalTypeInt] In constant expressions, operands of this operator must be of type 'int'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. '''); } } diff --git a/pkg/analyzer/test/src/diagnostics/const_eval_type_num_test.dart b/pkg/analyzer/test/src/diagnostics/const_eval_type_num_test.dart index 6cfcff8a6c0..cdc7d51641e 100644 --- a/pkg/analyzer/test/src/diagnostics/const_eval_type_num_test.dart +++ b/pkg/analyzer/test/src/diagnostics/const_eval_type_num_test.dart @@ -21,7 +21,7 @@ const b = a + ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -32,7 +32,7 @@ const b = a / ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -43,7 +43,7 @@ const b = a >= ''; // ^^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -54,7 +54,7 @@ const b = a > ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -65,7 +65,7 @@ const b = a <= ''; // ^^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -76,7 +76,7 @@ const b = a < ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -87,7 +87,7 @@ const b = a % ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -98,7 +98,7 @@ const b = a * ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -109,7 +109,7 @@ const b = a - ''; // ^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } @@ -120,7 +120,7 @@ const b = a ~/ ''; // ^^^^^^^ // [diag.constEvalTypeNum] In constant expressions, operands of this operator must be of type 'num'. // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'. '''); } } diff --git a/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart b/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart index facc9c7dccc..49e0c2340d4 100644 --- a/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart @@ -77,7 +77,7 @@ main() { // ^ // [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'NotA Function()' can't be assigned to the parameter type 'F'. +// [diag.argumentTypeNotAssignable] The argument type 'NotA Function()' can't be assigned to the parameter type 'F'. } '''); } @@ -207,7 +207,7 @@ void g(num cb(Object a, Object b)) {} void main() { g(f); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'num Function(Object, Object)'. +// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'num Function(Object, Object)'. } '''); } @@ -222,7 +222,7 @@ void g(num cb(Object a, Object b)) {} void main() { g(a.f); // ^^^ -// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'num Function(Object, Object)'. +// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'num Function(Object, Object)'. } '''); } @@ -234,7 +234,7 @@ void g(int cb(Object a, Object b)) {} void main() { g(f); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'int Function(Object, Object)'. +// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'int Function(Object, Object)'. } '''); } @@ -250,7 +250,7 @@ void g(int cb(Object a, Object b)) {} void main() { g(C().m); // ^^^^^ -// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'int Function(Object, Object)'. +// [diag.argumentTypeNotAssignable] The argument type 'num Function(num, num)' can't be assigned to the parameter type 'int Function(Object, Object)'. } '''); } @@ -312,7 +312,7 @@ class Foo { main() { new Foo().method(42); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. } '''); } @@ -364,7 +364,7 @@ class C

{ var c = C([]); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'List' can't be assigned to the parameter type 'Iterable'. +// [diag.argumentTypeNotAssignable] The argument type 'List' can't be assigned to the parameter type 'Iterable'. '''); } } diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_field_name_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_field_name_test.dart index bf5ab9f4754..5ef12cc615d 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_field_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_field_name_test.dart @@ -19,7 +19,7 @@ class DuplicateFieldName_RecordLiteralTest extends PubPackageResolutionTest { await resolveTestCodeWithDiagnostics(r''' var r = (a: 1, a: 2); // ^ -// [context 1] The first +// [context 1] The first // ^ // [diag.duplicateFieldName][context 1] The field name 'a' is already used in this record. '''); @@ -39,7 +39,7 @@ class DuplicateFieldName_RecordTypeAnnotationTest await resolveTestCodeWithDiagnostics(r''' void f(({int a, int a}) r) {} // ^ -// [context 1] The first +// [context 1] The first // ^ // [diag.duplicateFieldName][context 1] The field name 'a' is already used in this record. '''); @@ -49,7 +49,7 @@ void f(({int a, int a}) r) {} await resolveTestCodeWithDiagnostics(r''' void f((int a, int a) r) {} // ^ -// [context 1] The first +// [context 1] The first // ^ // [diag.duplicateFieldName][context 1] The field name 'a' is already used in this record. '''); @@ -59,7 +59,7 @@ void f((int a, int a) r) {} await resolveTestCodeWithDiagnostics(r''' void f((int a, {int a}) r) {} // ^ -// [context 1] The first +// [context 1] The first // ^ // [diag.duplicateFieldName][context 1] The field name 'a' is already used in this record. '''); @@ -69,7 +69,7 @@ void f((int a, {int a}) r) {} await resolveTestCodeWithDiagnostics(r''' void f(({int _, int _}) r) {} // ^ -// [context 1] The first +// [context 1] The first // [diag.invalidFieldNamePrivate] Record field names can't be private. // ^ // [diag.duplicateFieldName][context 1] The field name '_' is already used in this record. @@ -90,7 +90,7 @@ void f((int _, int _) r) {} void f((int _, int _) r) {} // ^ -// [context 1] The first +// [context 1] The first // [diag.invalidFieldNamePrivate] Record field names can't be private. // ^ // [diag.duplicateFieldName][context 1] The field name '_' is already used in this record. diff --git a/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart b/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart index 0bfdf0e1373..da97019ab39 100644 --- a/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart +++ b/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart @@ -22,7 +22,7 @@ class RecordLiteralOnePositionalNoTrailingCommaTest void f((int,) i) { f(('')); // ^^ -// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type '(int,)'. +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type '(int,)'. } '''); } @@ -32,7 +32,7 @@ void f((int,) i) { void f((int,) i) { f(1); // ^ -// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type '(int,)'. +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type '(int,)'. } '''); } diff --git a/pkg/analyzer_testing/lib/src/expected_diagnostics.dart b/pkg/analyzer_testing/lib/src/expected_diagnostics.dart index 44b2f5c5295..5896a33b695 100644 --- a/pkg/analyzer_testing/lib/src/expected_diagnostics.dart +++ b/pkg/analyzer_testing/lib/src/expected_diagnostics.dart @@ -77,7 +77,7 @@ final class _ExpectedDiagnosticsUpdater { length: contextMessage.length, caretLength: presentation.caretLength, includeExplicitLocation: presentation.includeExplicitLocation, - message: _toPosixPaths(contextMessage.messageText(includeUrl: false)), + message: _messageText(contextMessage), ), ); } @@ -103,9 +103,7 @@ final class _ExpectedDiagnosticsUpdater { caretLength: presentation.caretLength, includeExplicitLocation: presentation.includeExplicitLocation, contextRefs: contextRefs, - message: _toPosixPaths( - diagnostic.problemMessage.messageText(includeUrl: false), - ), + message: _messageText(diagnostic.problemMessage), ), ); } @@ -254,6 +252,11 @@ final class _ExpectedDiagnosticsUpdater { return buffer.toString(); } + static String _messageText(DiagnosticMessage message) { + var text = message.messageText(includeUrl: false); + return _toPosixPaths(text).trim(); + } + static String _toPosixPaths(String message) { return message.replaceAllMapped(RegExp(r'C:\\([a-zA-Z0-9_.\\]+)'), (match) { var path = match.group(1)!;