diff --git a/pkg/analyzer/test/src/diagnostics/label_in_outer_scope_test.dart b/pkg/analyzer/test/src/diagnostics/label_in_outer_scope_test.dart index a7b1e935095..5ee54d403b4 100644 --- a/pkg/analyzer/test/src/diagnostics/label_in_outer_scope_test.dart +++ b/pkg/analyzer/test/src/diagnostics/label_in_outer_scope_test.dart @@ -2,33 +2,35 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(LabelInOuterScopeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class LabelInOuterScopeTest extends PubPackageResolutionTest { test_label_in_outer_scope() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void m(int i) { l: while (i > 0) { void f() { +// ^ +// [diag.unusedElement] The declaration 'f' isn't referenced. break l; +// ^ +// [diag.labelInOuterScope] Can't reference label 'l' declared in an outer method. }; } } } -''', - [error(diag.unusedElement, 62, 1), error(diag.labelInOuterScope, 82, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/label_undefined_test.dart b/pkg/analyzer/test/src/diagnostics/label_undefined_test.dart index a4f62361941..66960f02484 100644 --- a/pkg/analyzer/test/src/diagnostics/label_undefined_test.dart +++ b/pkg/analyzer/test/src/diagnostics/label_undefined_test.dart @@ -2,68 +2,69 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(LabelUndefinedTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class LabelUndefinedTest extends PubPackageResolutionTest { test_break() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { x: while (true) { +//^^ +// [diag.unusedLabel] The label 'x' isn't used. break y; +// ^ +// [diag.labelUndefined] Can't reference an undefined label 'y'. } } -''', - [error(diag.unusedLabel, 8, 2), error(diag.labelUndefined, 36, 1)], - ); +'''); } test_break_notLabel() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(int x) { while (true) { break x; +// ^ +// [diag.labelUndefined] Can't reference an undefined label 'x'. } } -''', - [error(diag.labelUndefined, 38, 1)], - ); +'''); } test_continue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { x: while (true) { +//^^ +// [diag.unusedLabel] The label 'x' isn't used. continue y; +// ^ +// [diag.labelUndefined] Can't reference an undefined label 'y'. } } -''', - [error(diag.unusedLabel, 8, 2), error(diag.labelUndefined, 39, 1)], - ); +'''); } test_continue_notLabel() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(int x) { while (true) { continue x; +// ^ +// [diag.labelUndefined] Can't reference an undefined label 'x'. } } -''', - [error(diag.labelUndefined, 41, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/late_final_local_already_assigned_test.dart b/pkg/analyzer/test/src/diagnostics/late_final_local_already_assigned_test.dart index a55f056ec15..84750e95953 100644 --- a/pkg/analyzer/test/src/diagnostics/late_final_local_already_assigned_test.dart +++ b/pkg/analyzer/test/src/diagnostics/late_final_local_already_assigned_test.dart @@ -2,62 +2,60 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(LateFinalLocalAlreadyAssignedTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class LateFinalLocalAlreadyAssignedTest extends PubPackageResolutionTest { test_assignmentExpression_compound() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { late final int v; v = 0; v += 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. v; } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 40, 1)], - ); +'''); } test_assignmentExpression_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { late final int v; v = 0; v = 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. v; } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 40, 1)], - ); +'''); } test_assignmentExpression_simple_initialized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { late final int v = 0; v = 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. v; } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 35, 1)], - ); +'''); } test_localVariable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f() { late final int a; a = 1; @@ -67,60 +65,56 @@ void f() { } test_localVariable_forEach() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { late final int i; for (i in [1, 2, 3]) { +// ^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. print(i); } } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 33, 1)], - ); +'''); } test_postfixExpression_inc() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { late final int v = 0; v++; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. v; } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 35, 1)], - ); +'''); } test_postfixExpression_nullCheck() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { late final int v = 0; v!; +// ^ +// [diag.unnecessaryNonNullAssertion] The '!' will have no effect because the receiver can't be null. v; } -''', - [error(diag.unnecessaryNonNullAssertion, 36, 1)], - ); +'''); } test_prefixExpression_inc() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { late final int v = 0; ++v; +// ^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. v; } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 37, 1)], - ); +'''); } test_prefixExpression_negation() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' main() { late final bool v = true; !v; diff --git a/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart index b23c65d18ca..c74e217c3c7 100644 --- a/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart @@ -6,18 +6,20 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ListElementTypeNotAssignableTest); defineReflectiveTests(ListElementTypeNotAssignableWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ListElementTypeNotAssignableTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 0; var v = const [if (1 < 0) a else b]; @@ -25,114 +27,107 @@ var v = const [if (1 < 0) a else b]; } test_const_ifElement_thenElseFalse_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 'b'; var v = const [if (1 < 0) a else b]; -''', - [error(diag.listElementTypeNotAssignable, 82, 1)], - ); +// ^ +// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'. +'''); } test_const_ifElement_thenFalse_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const [if (1 < 0) 'a']; -''', - [error(diag.listElementTypeNotAssignable, 31, 3)], - ); +// ^^^ +// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'. +'''); } test_const_ifElement_thenFalse_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const [if (1 < 0) a]; '''); } test_const_ifElement_thenTrue_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const [if (true) a]; '''); } test_const_ifElement_thenTrue_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const [if (true) a]; -''', - [error(diag.listElementTypeNotAssignable, 53, 1)], - ); +// ^ +// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'. +'''); } test_const_intInt() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' var v1 = [42]; var v2 = const [42]; '''); } test_const_intNull_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const a = null; var v = const [a]; -''', - [error(diag.listElementTypeNotAssignableNullability, 36, 1)], - ); +// ^ +// [diag.listElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the list type 'int'. +'''); } test_const_intNull_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const [null]; -''', - [error(diag.listElementTypeNotAssignableNullability, 20, 4)], - ); +// ^^^^ +// [diag.listElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the list type 'int'. +'''); } test_const_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const [...[0, 1]]; '''); } test_const_stringInt() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const [42]; -''', - [error(diag.listElementTypeNotAssignable, 23, 2)], - ); +// ^^ +// [diag.listElementTypeNotAssignable] The element type 'int' can't be assigned to the list type 'String'. +'''); } test_const_stringInt_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic x = 42; var v = const [x]; -''', - [error(diag.listElementTypeNotAssignable, 45, 1)], - ); +// ^ +// [diag.listElementTypeNotAssignable] The element type 'int' can't be assigned to the list type 'String'. +'''); } test_const_stringQuestion_null_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const [null]; '''); } test_const_voidInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const [42]; '''); } test_nonConst_genericFunction_genericContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' List(U)> foo(T Function(T a) f) { return [f]; } @@ -140,18 +135,17 @@ List(U)> foo(T Function(T a) f) { } test_nonConst_genericFunction_genericContext_nonAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' List(U, int)> foo(T Function(T a) f) { return [f]; +// ^ +// [diag.listElementTypeNotAssignable] The element type 'T Function(T)' can't be assigned to the list type 'U Function(U, int)'. } -''', - [error(diag.listElementTypeNotAssignable, 66, 1)], - ); +'''); } test_nonConst_genericFunction_nonGenericContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' List foo(T Function(T a) f) { return [f]; } @@ -159,18 +153,17 @@ List foo(T Function(T a) f) { } test_nonConst_genericFunction_nonGenericContext_nonAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' List foo(T Function(T a) f) { return [f]; +// ^ +// [diag.listElementTypeNotAssignable] The element type 'dynamic Function(dynamic)' can't be assigned to the list type 'int Function(int, int)'. } -''', - [error(diag.listElementTypeNotAssignable, 67, 1)], - ); +'''); } test_nonConst_ifElement_thenElseFalse_intDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; const dynamic b = 'b'; var v = [if (1 < 0) a else b]; @@ -178,7 +171,7 @@ var v = [if (1 < 0) a else b]; } test_nonConst_ifElement_thenElseFalse_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 0; var v = [if (1 < 0) a else b]; @@ -186,52 +179,50 @@ var v = [if (1 < 0) a else b]; } test_nonConst_ifElement_thenFalse_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = [if (1 < 0) 'a']; -''', - [error(diag.listElementTypeNotAssignable, 25, 3)], - ); +// ^^^ +// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'. +'''); } test_nonConst_ifElement_thenTrue_intDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = [if (true) a]; '''); } test_nonConst_ifElement_thenTrue_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = [if (true) a]; '''); } test_nonConst_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = [...[0, 1]]; '''); } test_nonConst_stringInt() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = [42]; -''', - [error(diag.listElementTypeNotAssignable, 17, 2)], - ); +// ^^ +// [diag.listElementTypeNotAssignable] The element type 'int' can't be assigned to the list type 'String'. +'''); } test_nonConst_stringInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic x = 42; var v = [x]; '''); } test_nonConst_voidInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = [42]; '''); } diff --git a/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart b/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart index e9876dd4f42..df9755de3f7 100644 --- a/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart @@ -2,78 +2,82 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MainFirstPositionalParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MainFirstPositionalParameterTest extends PubPackageResolutionTest { test_positionalOptional_listOfInt() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main([List args = const []]) {} +// ^^^^^^^^^ +// [diag.mainFirstPositionalParameterType] The type of the first positional parameter of the 'main' function must be a supertype of 'List'. '''); - assertErrorsInResult([error(diag.mainFirstPositionalParameterType, 11, 9)]); } test_positionalRequired_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(dynamic args) {} '''); } test_positionalRequired_functionTypedFormal() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(void args()) {} +// ^^^^ +// [diag.mainFirstPositionalParameterType] The type of the first positional parameter of the 'main' function must be a supertype of 'List'. '''); - assertErrorsInResult([error(diag.mainFirstPositionalParameterType, 10, 4)]); } test_positionalRequired_iterableOfString() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(Iterable args) {} '''); } test_positionalRequired_listOfInt() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(List args) {} +// ^^^^^^^^^ +// [diag.mainFirstPositionalParameterType] The type of the first positional parameter of the 'main' function must be a supertype of 'List'. '''); - assertErrorsInResult([error(diag.mainFirstPositionalParameterType, 10, 9)]); } test_positionalRequired_listOfString() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(List args) {} '''); } test_positionalRequired_listOfStringQuestion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(List args) {} '''); } test_positionalRequired_listQuestionOfString() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(List? args) {} '''); } test_positionalRequired_object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(Object args) {} '''); } test_positionalRequired_objectQuestion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main(Object? args) {} '''); } diff --git a/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart b/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart index 944b3dcceb2..1b7aaa27606 100644 --- a/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart +++ b/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart @@ -2,32 +2,31 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MainHasRequiredNamedParametersTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MainHasRequiredNamedParametersTest extends PubPackageResolutionTest { test_namedOptional() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main({int a = 0}) {} '''); - assertNoErrorsInResult(); } test_namedRequired() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void main({required List a}) {} -''', - [error(diag.mainHasRequiredNamedParameters, 5, 4)], - ); +// ^^^^ +// [diag.mainHasRequiredNamedParameters] The function 'main' can't have any required named parameters. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart b/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart index 00fafe70a97..b64e33f4797 100644 --- a/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart +++ b/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MainHasTooManyRequiredPositionalParametersTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,72 +18,63 @@ main() { class MainHasTooManyRequiredPositionalParametersTest extends PubPackageResolutionTest { test_namedOptional_1() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main({int a = 0}) {} '''); - assertNoErrorsInResult(); } test_positionalOptional_1() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void f([int a = 0]) {} '''); - assertNoErrorsInResult(); } test_positionalRequired_0() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main() {} '''); - assertNoErrorsInResult(); } test_positionalRequired_1() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(args) {} '''); - assertNoErrorsInResult(); } test_positionalRequired_2() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(args, int a) {} '''); - assertNoErrorsInResult(); } test_positionalRequired_2_positionalOptional_1() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(args, int a, [int b = 0]) {} '''); - assertNoErrorsInResult(); } test_positionalRequired_3() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(args, int a, int b) {} +// ^^^^ +// [diag.mainHasTooManyRequiredPositionalParameters] The function 'main' can't have more than two required positional parameters. '''); - assertErrorsInResult([ - error(diag.mainHasTooManyRequiredPositionalParameters, 5, 4), - ]); } test_positionalRequired_3_namedOptional_1() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(args, int a, int b, {int c = 0}) {} +// ^^^^ +// [diag.mainHasTooManyRequiredPositionalParameters] The function 'main' can't have more than two required positional parameters. '''); - assertErrorsInResult([ - error(diag.mainHasTooManyRequiredPositionalParameters, 5, 4), - ]); } test_positionalRequired_3_namedRequired_1() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' void main(args, int a, int b, {required int c}) {} +// ^^^^ +// [diag.mainHasTooManyRequiredPositionalParameters] The function 'main' can't have more than two required positional parameters. +// [diag.mainHasRequiredNamedParameters] The function 'main' can't have any required named parameters. '''); - assertErrorsInResult([ - error(diag.mainHasRequiredNamedParameters, 5, 4), - error(diag.mainHasTooManyRequiredPositionalParameters, 5, 4), - ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart b/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart index 383341709d1..27ce7c82307 100644 --- a/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart @@ -2,83 +2,92 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MainIsNotFunctionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MainIsNotFunctionTest extends PubPackageResolutionTest { test_class() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' class main {} +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 6, 4)]); } test_classAlias() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin M {} class main = A with M; +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 28, 4)]); } test_enum() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' enum main { +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. v } '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 5, 4)]); } test_function() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main() {} '''); } test_getter() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' int get main => 0; +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 8, 4)]); } test_mixin() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin main on A {} +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 17, 4)]); } test_typedef() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' typedef main = void Function(); +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 8, 4)]); } test_typedef_legacy() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' typedef void main(); +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 13, 4)]); } test_variable() async { - await resolveTestCode(''' + await resolveTestCodeWithDiagnostics(''' var main = 0; +// ^^^^ +// [diag.mainIsNotFunction] The declaration named 'main' must be a function. '''); - assertErrorsInResult([error(diag.mainIsNotFunction, 4, 4)]); } } diff --git a/pkg/analyzer/test/src/diagnostics/map_entry_not_in_map_test.dart b/pkg/analyzer/test/src/diagnostics/map_entry_not_in_map_test.dart index d7f93185f25..3c2fcf16714 100644 --- a/pkg/analyzer/test/src/diagnostics/map_entry_not_in_map_test.dart +++ b/pkg/analyzer/test/src/diagnostics/map_entry_not_in_map_test.dart @@ -2,34 +2,33 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MapEntryNotInMapTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MapEntryNotInMapTest extends PubPackageResolutionTest { test_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var c = {1:2}; -''', - [error(diag.mapEntryNotInMap, 14, 3)], - ); +// ^^^ +// [diag.mapEntryNotInMap] Map entries can only be used in a map literal. +'''); } test_set_const() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var c = const {1:2}; -''', - [error(diag.mapEntryNotInMap, 20, 3)], - ); +// ^^^ +// [diag.mapEntryNotInMap] Map entries can only be used in a map literal. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart index 5bf4935071e..c6c70a4be4e 100644 --- a/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart @@ -6,18 +6,20 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MapKeyTypeNotAssignableTest); defineReflectiveTests(MapKeyTypeNotAssignableWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MapKeyTypeNotAssignableTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 0; var v = const {if (1 < 0) a: true else b: false}; @@ -25,141 +27,132 @@ var v = const {if (1 < 0) a: true else b: false}; } test_const_ifElement_thenElseFalse_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 'b'; var v = const {if (1 < 0) a: true else b: false}; -''', - [error(diag.mapKeyTypeNotAssignable, 94, 1)], - ); +// ^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_const_ifElement_thenFalse_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {if (1 < 0) a: true}; '''); } test_const_ifElement_thenFalse_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const {if (1 < 0) 'a': true}; -''', - [error(diag.mapKeyTypeNotAssignable, 37, 3)], - ); +// ^^^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_const_ifElement_thenTrue_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (true) a: true}; '''); } test_const_ifElement_thenTrue_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {if (true) a: true}; -''', - [error(diag.mapKeyTypeNotAssignable, 59, 1)], - ); +// ^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_const_ifElement_thenTrue_notConst() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final a = 0; var v = const {if (1 < 2) a: true}; -''', - [error(diag.nonConstantMapKey, 50, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {a : true}; '''); } test_const_intNull_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = null; var v = const {a : true}; -''', - [error(diag.mapKeyTypeNotAssignableNullability, 50, 1)], - ); +// ^ +// [diag.mapKeyTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map key type 'int'. +'''); } test_const_intNull_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const {null : true}; -''', - [error(diag.mapKeyTypeNotAssignableNullability, 26, 4)], - ); +// ^^^^ +// [diag.mapKeyTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map key type 'int'. +'''); } test_const_intQuestion_null_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = null; var v = const {a : true}; '''); } test_const_intQuestion_null_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const {null : true}; '''); } test_const_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {a : true}; -''', - [error(diag.mapKeyTypeNotAssignable, 49, 1)], - ); +// ^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_const_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const {'a' : true}; -''', - [error(diag.mapKeyTypeNotAssignable, 26, 3)], - ); +// ^^^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_const_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const {...{1: 'a'}}; '''); } test_const_spread_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {...{a: 'a'}}; -''', - [error(diag.mapKeyTypeNotAssignable, 55, 1)], - ); +// ^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_key_type_is_assignable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = {'a' : 1}; '''); } test_nonConst_ifElement_thenElseFalse_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 0; var v = {if (1 < 0) a: true else b: false}; @@ -167,7 +160,7 @@ var v = {if (1 < 0) a: true else b: false}; } test_nonConst_ifElement_thenElseFalse_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 'b'; var v = {if (1 < 0) a: true else b: false}; @@ -175,68 +168,65 @@ var v = {if (1 < 0) a: true else b: false}; } test_nonConst_ifElement_thenFalse_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {if (1 < 0) 'a': true}; -''', - [error(diag.mapKeyTypeNotAssignable, 31, 3)], - ); +// ^^^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_nonConst_ifElement_thenTrue_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = {if (true) a: true}; '''); } test_nonConst_ifElement_thenTrue_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = {if (true) a: true}; '''); } test_nonConst_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = {a : true}; '''); } test_nonConst_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = {a : true}; '''); } test_nonConst_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {'a' : true}; -''', - [error(diag.mapKeyTypeNotAssignable, 20, 3)], - ); +// ^^^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_nonConst_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = {...{1: 'a'}}; '''); } test_nonConst_spread_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {...{'a': 'a'}}; -''', - [error(diag.mapKeyTypeNotAssignable, 26, 3)], - ); +// ^^^ +// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'. +'''); } test_nonConst_spread_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' dynamic a = 'a'; var v = {...{a: 'a'}}; '''); diff --git a/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart index 0ebeff49d0d..e9e68a90916 100644 --- a/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart @@ -6,18 +6,20 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MapValueTypeNotAssignableTest); defineReflectiveTests(MapValueTypeNotAssignableWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MapValueTypeNotAssignableTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 0; var v = const {if (1 < 0) true: a else false: b}; @@ -25,135 +27,126 @@ var v = const {if (1 < 0) true: a else false: b}; } test_const_ifElement_thenElseFalse_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 'b'; var v = const {if (1 < 0) true: a else false: b}; -''', - [error(diag.mapValueTypeNotAssignable, 101, 1)], - ); +// ^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_const_ifElement_thenFalse_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {if (1 < 0) true: a}; '''); } test_const_ifElement_thenFalse_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const {if (1 < 0) true: 'a'}; -''', - [error(diag.mapValueTypeNotAssignable, 43, 3)], - ); +// ^^^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_const_ifElement_thenTrue_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (true) true: a}; '''); } test_const_ifElement_thenTrue_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {if (true) true: a}; -''', - [error(diag.mapValueTypeNotAssignable, 65, 1)], - ); +// ^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_const_ifElement_thenTrue_notConst() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final a = 0; var v = const {if (1 < 2) true: a}; -''', - [error(diag.nonConstantMapValue, 56, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {true: a}; '''); } test_const_intNull_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = null; var v = const {true: a}; -''', - [error(diag.mapValueTypeNotAssignableNullability, 56, 1)], - ); +// ^ +// [diag.mapValueTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map value type 'int'. +'''); } test_const_intNull_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const {true: null}; -''', - [error(diag.mapValueTypeNotAssignableNullability, 32, 4)], - ); +// ^^^^ +// [diag.mapValueTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map value type 'int'. +'''); } test_const_intQuestion_null_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = null; var v = const {true: a}; '''); } test_const_intQuestion_null_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const {true: null}; '''); } test_const_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {true: a}; -''', - [error(diag.mapValueTypeNotAssignable, 55, 1)], - ); +// ^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_const_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = const {true: 'a'}; -''', - [error(diag.mapValueTypeNotAssignable, 32, 3)], - ); +// ^^^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_const_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = const {...{true: 1}}; '''); } test_const_spread_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = const {...{true: a}}; -''', - [error(diag.mapValueTypeNotAssignable, 59, 1)], - ); +// ^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_nonConst_ifElement_thenElseFalse_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 0; var v = {if (1 < 0) true: a else false: b}; @@ -161,7 +154,7 @@ var v = {if (1 < 0) true: a else false: b}; } test_nonConst_ifElement_thenElseFalse_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; const dynamic b = 'b'; var v = {if (1 < 0) true: a else false: b}; @@ -169,68 +162,65 @@ var v = {if (1 < 0) true: a else false: b}; } test_nonConst_ifElement_thenFalse_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {if (1 < 0) true: 'a'}; -''', - [error(diag.mapValueTypeNotAssignable, 37, 3)], - ); +// ^^^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_nonConst_ifElement_thenTrue_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = {if (true) true: a}; '''); } test_nonConst_ifElement_thenTrue_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = {if (true) true: a}; '''); } test_nonConst_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = {true: a}; '''); } test_nonConst_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = {true: a}; '''); } test_nonConst_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {true: 'a'}; -''', - [error(diag.mapValueTypeNotAssignable, 26, 3)], - ); +// ^^^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_nonConst_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = {...{true: 1}}; '''); } test_nonConst_spread_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {...{true: 'a'}}; -''', - [error(diag.mapValueTypeNotAssignable, 30, 3)], - ); +// ^^^ +// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'. +'''); } test_nonConst_spread_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 'a'; var v = {...{true: a}}; '''); diff --git a/pkg/analyzer/test/src/diagnostics/member_with_class_name_test.dart b/pkg/analyzer/test/src/diagnostics/member_with_class_name_test.dart index fc66811d318..abd68ec544d 100644 --- a/pkg/analyzer/test/src/diagnostics/member_with_class_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/member_with_class_name_test.dart @@ -2,61 +2,58 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MemberWithClassNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MemberWithClassNameTest extends PubPackageResolutionTest { test_class_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int A = 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 16, 1)], - ); +'''); } test_class_field_multiple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int z = 0, A = 0, b = 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 23, 1)], - ); +'''); } test_class_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { get A => 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 16, 1)], - ); +'''); } test_class_getter_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get A => 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 27, 1)], - ); +'''); } test_class_method() async { @@ -65,128 +62,117 @@ class A { } test_class_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { set A(_) {} +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 16, 1)], - ); +'''); } test_class_setter_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static set A(_) {} +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 23, 1)], - ); +'''); } test_enum_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int E = 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 26, 1)], - ); +'''); } test_enum_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int get E => 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 24, 1)], - ); +'''); } test_enum_getter_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int get E => 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 31, 1)], - ); +'''); } test_enum_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; set E(int _) {} +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 20, 1)], - ); +'''); } test_enum_setter_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static set E(int _) {} +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 27, 1)], - ); +'''); } test_mixin_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int get M => 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 20, 1)], - ); +'''); } test_mixin_getter_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int get M => 0; +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 27, 1)], - ); +'''); } test_mixin_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { void set M(_) {} +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 21, 1)], - ); +'''); } test_mixin_setter_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static void set M(_) {} +// ^ +// [diag.memberWithClassName] A class member can't have the same name as the enclosing class. } -''', - [error(diag.memberWithClassName, 28, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mismatched_annotation_on_struct_field_test.dart b/pkg/analyzer/test/src/diagnostics/mismatched_annotation_on_struct_field_test.dart index 908d2dc6b92..32f6b9a3ab3 100644 --- a/pkg/analyzer/test/src/diagnostics/mismatched_annotation_on_struct_field_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mismatched_annotation_on_struct_field_test.dart @@ -2,42 +2,41 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MismatchedAnnotationOnStructFieldTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MismatchedAnnotationOnStructFieldTest extends PubPackageResolutionTest { test_double_on_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Double() +//^^^^^^^^^ +// [diag.mismatchedAnnotationOnStructField] The annotation doesn't match the declared type of the field. external int x; } -''', - [error(diag.mismatchedAnnotationOnStructField, 52, 9)], - ); +'''); } test_int32_on_double() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Int32() +//^^^^^^^^ +// [diag.mismatchedAnnotationOnStructField] The annotation doesn't match the declared type of the field. external double x; } -''', - [error(diag.mismatchedAnnotationOnStructField, 52, 8)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/missing_annotation_on_struct_field_test.dart b/pkg/analyzer/test/src/diagnostics/missing_annotation_on_struct_field_test.dart index 2dc5aa7286e..981b01be0b3 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_annotation_on_struct_field_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_annotation_on_struct_field_test.dart @@ -2,33 +2,33 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingAnnotationOnStructFieldTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingAnnotationOnStructFieldTest extends PubPackageResolutionTest { test_missing_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { external int x; +// ^^^ +// [diag.missingAnnotationOnStructField] Fields of type 'int' in a subclass of 'Struct' must have an annotation indicating the native type. } -''', - [error(diag.missingAnnotationOnStructField, 61, 3)], - ); +'''); } test_notMissing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Int32() diff --git a/pkg/analyzer/test/src/diagnostics/missing_default_value_for_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/missing_default_value_for_parameter_test.dart index 563eccca27f..47a3d292c4b 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_default_value_for_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_default_value_for_parameter_test.dart @@ -2,52 +2,51 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingDefaultValueForParameterTest); defineReflectiveTests(MissingDefaultValueForParameterWithAnnotationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingDefaultValueForParameterTest extends PubPackageResolutionTest { test_closure_nonNullable_named_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var f = ({int a = 0}) {}; '''); } test_closure_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var f = ({int a}) {}; -''', - [error(diag.missingDefaultValueForParameter, 14, 1)], - ); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. +'''); } test_closure_nonNullable_positional_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var f = ([int a = 0]) {}; '''); } test_closure_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var f = ([int a]) {}; -''', - [error(diag.missingDefaultValueForParameterPositional, 14, 1)], - ); +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. +'''); } test_constructor_externalFactory_nonNullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { external factory C({int a}); } @@ -55,7 +54,7 @@ class C { } test_constructor_externalFactory_nonNullable_positional_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { external factory C([int a]); } @@ -63,7 +62,7 @@ class C { } test_constructor_externalFactory_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { external factory C({int? a}); } @@ -71,31 +70,29 @@ class C { } test_constructor_factory_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { factory C({int a}) => C._(); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. C._(); } -''', - [error(diag.missingDefaultValueForParameter, 27, 1)], - ); +'''); } test_constructor_factory_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { factory C([int a]) => C._(); +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. C._(); } -''', - [error(diag.missingDefaultValueForParameterPositional, 27, 1)], - ); +'''); } test_constructor_factory_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { factory C({int? a}) => C._(); C._(); @@ -104,18 +101,17 @@ class C { } test_constructor_generative_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { C({int a}); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameter, 19, 1)], - ); +'''); } test_constructor_generative_nonNullable_named_optional_super_hasDefault_explicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { A({required int a}); } @@ -126,7 +122,7 @@ class B extends A{ } test_constructor_generative_nonNullable_named_optional_super_hasDefault_fromSuper() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { A({int a = 0}); } @@ -137,7 +133,7 @@ class B extends A{ } test_constructor_generative_nonNullable_named_optional_super_hasDefault_fromSuper_extensionType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' extension type const E(int it) {} class A { @@ -151,46 +147,43 @@ class B extends A { } test_constructor_generative_nonNullable_named_optional_super_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A({int? a}); } class B extends A{ B({int super.a}); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameter, 61, 1)], - ); +'''); } test_constructor_generative_nonNullable_named_optional_super_noDefault_fromSuper() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A({num a = 1.2}); } class B extends A{ B({int super.a}); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameter, 66, 1)], - ); +'''); } test_constructor_generative_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { C([int a]); +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameterPositional, 19, 1)], - ); +'''); } test_constructor_generative_nonNullable_positional_optional_super_hasDefault_explicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { A(int a); } @@ -201,7 +194,7 @@ class B extends A{ } test_constructor_generative_nonNullable_positional_optional_super_hasDefault_fromSuper() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { A([int a = 0]); } @@ -212,35 +205,33 @@ class B extends A{ } test_constructor_generative_nonNullable_positional_optional_super_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A([int? a]); } class B extends A{ B([int super.a]); +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameterPositional, 61, 1)], - ); +'''); } test_constructor_generative_nonNullable_positional_optional_super_noDefault_fromSuper() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A([num a = 1.2]); } class B extends A{ B([int super.a]); +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameterPositional, 66, 1)], - ); +'''); } test_constructor_generative_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { C({int? a}); } @@ -248,7 +239,7 @@ class C { } test_constructor_generative_nullable_named_optional_noDefault_fieldFormal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { int? f; C({this.f}); @@ -257,8 +248,7 @@ class C { } test_constructor_generative_super_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { final int a; A({this.a = 0}); @@ -270,14 +260,14 @@ class B extends A { class C extends B { C({super.a}); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameter, 126, 1)], - ); +'''); } test_constructor_generative_super_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { final int? a; A({this.a}); @@ -294,7 +284,7 @@ class C extends B { } test_constructor_redirectingFactory_nonNullable_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { factory A({int a}) = B; } @@ -306,7 +296,7 @@ class B implements A { } test_constructor_redirectingFactory_nonNullable_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { factory A([int a]) = B; } @@ -318,7 +308,7 @@ class B implements A { } test_constructor_redirectingFactory_nullable_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { factory A({int? a}) = B; } @@ -330,7 +320,7 @@ class B implements A { } test_fieldFormalParameter_functionTyped_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { dynamic f; A(void this.f({int a, int? b})); @@ -339,7 +329,7 @@ class A { } test_fieldFormalParameter_functionTyped_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { dynamic f; A(void this.f([int a, int? b])); @@ -348,211 +338,205 @@ class A { } test_function_external_nonNullable_named_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f({int a = 0}); '''); } test_function_external_nonNullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f({int a}); '''); } test_function_external_nonNullable_named_required_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f({required int a}); '''); } test_function_external_nonNullable_positional_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f([int a = 0]); '''); } test_function_external_nonNullable_positional_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f([int a]); '''); } test_function_external_nonNullable_positional_required_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f(int a); '''); } test_function_external_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f({int? a}); '''); } test_function_external_nullable_positional_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' external void f([int? a]); '''); } test_function_native_nonNullable_named_optional_default() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f({int a = 0}) native; -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 20, 7)], - ); +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. +'''); } test_function_native_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f({int a}) native; -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 16, 7)], - ); +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. +'''); } test_function_native_nonNullable_positional_optional_default() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f([int a = 0]) native; -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 20, 7)], - ); +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. +'''); } test_function_native_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f([int a]) native; -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 16, 7)], - ); +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. +'''); } test_function_nonNullable_named_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({int a = 0}) {} '''); } test_function_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f({int a}) {} -''', - [error(diag.missingDefaultValueForParameter, 12, 1)], - ); +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. +'''); } test_function_nonNullable_named_required() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({required int a}) {} '''); } test_function_nonNullable_positional_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f([int a = 0]) {} '''); } test_function_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f([int a]) {} -''', - [error(diag.missingDefaultValueForParameterPositional, 12, 1)], - ); +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. +'''); } test_function_nonNullable_positional_required() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(int a) {} '''); } test_function_nullable_named_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({int? a = 0}) {} '''); } test_function_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({int? a}) {} '''); } test_function_nullable_named_required() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({required int? a}) {} '''); } test_function_nullable_positional_optional_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f([int? a = 0]) {} '''); } test_function_nullable_positional_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f([int? a]) {} '''); } test_function_nullable_positional_required() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(int? a) {} '''); } test_functionTypeAlias_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' typedef void F({int a, int? b}); '''); } test_functionTypeAlias_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' typedef void F([int a, int? b]); '''); } test_functionTypedFormalParameter_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(void p({int a, int? b})) {} '''); } test_functionTypedFormalParameter_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(void p([int a, int? b])) {} '''); } test_genericFunctionType_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(void Function({int a, int? b}) p) {} '''); } test_genericFunctionType_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(void Function([int a, int? b]) p) {} '''); } test_genericFunctionType_positional_optional2() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(void Function([int, int?]) p) {} '''); } test_method_abstract_nonNullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void foo({int a}); } @@ -560,7 +544,7 @@ abstract class C { } test_method_abstract_nonNullable_positional_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void foo([int a]); } @@ -568,7 +552,7 @@ abstract class C { } test_method_abstract_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void foo({int? a}); } @@ -576,7 +560,7 @@ abstract class C { } test_method_abstract_potentiallyNonNullable_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { void foo({T a}); } @@ -584,7 +568,7 @@ abstract class A { } test_method_abstract_potentiallyNonNullable_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { void foo([T a]); } @@ -592,7 +576,7 @@ abstract class A { } test_method_external_nonNullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { external void foo({int a}); } @@ -600,7 +584,7 @@ class C { } test_method_external_nonNullable_positional_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { external void foo([int a]); } @@ -608,7 +592,7 @@ class C { } test_method_external_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { external void foo({int? a}); } @@ -616,7 +600,7 @@ class C { } test_method_external_potentiallyNonNullable_named_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { external void foo({T a}); } @@ -624,7 +608,7 @@ class A { } test_method_external_potentiallyNonNullable_positional_optional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { external void foo([T a]); } @@ -632,84 +616,77 @@ class A { } test_method_native_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { void foo({int a}) native; +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 30, 7)], - ); +'''); } test_method_native_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { void foo([int a]) native; +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 30, 7)], - ); +'''); } test_method_native_nullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { void foo({int? a}) native; +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 31, 7)], - ); +'''); } test_method_native_potentiallyNonNullable_named_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void foo({T a}) native; +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 31, 7)], - ); +'''); } test_method_native_potentiallyNonNullable_positional_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void foo([T a]) native; +// ^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 47, 7)], - ); +'''); } test_method_nonNullable_named_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { void foo({int a}) {} +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameter, 26, 1)], - ); +'''); } test_method_nonNullable_positional_optional_noDefault() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { void foo([int a]) {} +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameterPositional, 26, 1)], - ); +'''); } test_method_nullable_named_optional_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { void foo({int? a}) {} } @@ -717,29 +694,27 @@ class C { } test_method_potentiallyNonNullable_named_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void foo({T a}) {} +// ^ +// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameter, 43, 1)], - ); +'''); } test_method_potentiallyNonNullable_positional_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void foo([T a]) {} +// ^ +// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'. } -''', - [error(diag.missingDefaultValueForParameterPositional, 43, 1)], - ); +'''); } test_super_forward_wildcards() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { final int x, y; A(this.x, [this.y = 0]); @@ -758,16 +733,15 @@ class MissingDefaultValueForParameterWithAnnotationTest extends PubPackageResolutionTest { test_method_withAnnotation() async { writeTestPackageConfigWithMeta(); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class C { // ignore: deprecated_member_use void foo({@required int a}) {} +// ^ +// [diag.missingDefaultValueForParameterWithAnnotation] With null safety, use the 'required' keyword, not the '@required' annotation. } -''', - [error(diag.missingDefaultValueForParameterWithAnnotation, 105, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart b/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart index f298086c2b4..85d31ecc8af 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart @@ -2,38 +2,23 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingEnumConstantInSwitchTest); defineReflectiveTests(MissingEnumConstantInSwitchTest_Language219); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class MissingEnumConstantInSwitchTest extends PubPackageResolutionTest - with MissingEnumConstantInSwitchTestCases { - @override - bool get _arePatternsEnabled => true; -} - -@reflectiveTest -class MissingEnumConstantInSwitchTest_Language219 - extends PubPackageResolutionTest - with WithLanguage219Mixin, MissingEnumConstantInSwitchTestCases { - @override - bool get _arePatternsEnabled => false; -} - -mixin MissingEnumConstantInSwitchTestCases on PubPackageResolutionTest { - bool get _arePatternsEnabled; - +class MissingEnumConstantInSwitchTest extends PubPackageResolutionTest { test_all_enhanced() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two; @@ -52,7 +37,7 @@ void f(E e) { } test_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two, three } void f(E e) { @@ -67,95 +52,71 @@ void f(E e) { } test_first() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two, three } void f(E e) { switch (e) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.one'. case E.two: case E.three: break; } } -''', - [ - if (!_arePatternsEnabled) - error(diag.missingEnumConstantInSwitch, 44, 10) - else - error(diag.nonExhaustiveSwitchStatement, 44, 6), - ], - ); +'''); } test_last() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two, three } void f(E e) { switch (e) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.three'. case E.one: case E.two: break; } } -''', - [ - if (!_arePatternsEnabled) - error(diag.missingEnumConstantInSwitch, 44, 10) - else - error(diag.nonExhaustiveSwitchStatement, 44, 6), - ], - ); +'''); } test_middle() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two, three } void f(E e) { switch (e) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.two'. case E.one: case E.three: break; } } -''', - [ - if (!_arePatternsEnabled) - error(diag.missingEnumConstantInSwitch, 44, 10) - else - error(diag.nonExhaustiveSwitchStatement, 44, 6), - ], - ); +'''); } test_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two } void f(E? e) { switch (e) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E?' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'null'. case E.one: case E.two: break; } } -''', - [ - if (!_arePatternsEnabled) - error(diag.missingEnumConstantInSwitch, 38, 10) - else - error(diag.nonExhaustiveSwitchStatement, 38, 6), - ], - ); +'''); } test_nullable_default() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two } void f(E? e) { @@ -170,7 +131,142 @@ void f(E? e) { } test_nullable_null() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' +enum E { one, two } + +void f(E? e) { + switch (e) { + case E.one: + break; + case E.two: + break; + case null: + break; + } +} +'''); + } +} + +@reflectiveTest +class MissingEnumConstantInSwitchTest_Language219 + extends PubPackageResolutionTest + with WithLanguage219Mixin { + test_all_enhanced() async { + await resolveTestCodeWithDiagnostics(''' +enum E { + one, two; + + static const x = 0; +} + +void f(E e) { + switch (e) { + case E.one: + break; + case E.two: + break; + } +} +'''); + } + + test_default() async { + await resolveTestCodeWithDiagnostics(''' +enum E { one, two, three } + +void f(E e) { + switch (e) { + case E.one: + break; + default: + break; + } +} +'''); + } + + test_first() async { + await resolveTestCodeWithDiagnostics(''' +enum E { one, two, three } + +void f(E e) { + switch (e) { +//^^^^^^^^^^ +// [diag.missingEnumConstantInSwitch] Missing case clause for 'one'. + case E.two: + case E.three: + break; + } +} +'''); + } + + test_last() async { + await resolveTestCodeWithDiagnostics(''' +enum E { one, two, three } + +void f(E e) { + switch (e) { +//^^^^^^^^^^ +// [diag.missingEnumConstantInSwitch] Missing case clause for 'three'. + case E.one: + case E.two: + break; + } +} +'''); + } + + test_middle() async { + await resolveTestCodeWithDiagnostics(''' +enum E { one, two, three } + +void f(E e) { + switch (e) { +//^^^^^^^^^^ +// [diag.missingEnumConstantInSwitch] Missing case clause for 'two'. + case E.one: + case E.three: + break; + } +} +'''); + } + + test_nullable() async { + await resolveTestCodeWithDiagnostics(''' +enum E { one, two } + +void f(E? e) { + switch (e) { +//^^^^^^^^^^ +// [diag.missingEnumConstantInSwitch] Missing case clause for 'null'. + case E.one: + case E.two: + break; + } +} +'''); + } + + test_nullable_default() async { + await resolveTestCodeWithDiagnostics(''' +enum E { one, two } + +void f(E? e) { + switch (e) { + case E.one: + break; + default: + break; + } +} +'''); + } + + test_nullable_null() async { + await resolveTestCodeWithDiagnostics(''' enum E { one, two } void f(E? e) { @@ -188,8 +284,7 @@ void f(E? e) { test_parenthesized() async { // TODO(johnniwinther): Re-enable this test for the patterns feature. - if (_arePatternsEnabled) return; - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' enum E { one, two, three } void f(E e) { diff --git a/pkg/analyzer/test/src/diagnostics/missing_exception_value_test.dart b/pkg/analyzer/test/src/diagnostics/missing_exception_value_test.dart index ab5aeabd0ea..0fcec278071 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_exception_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_exception_value_test.dart @@ -2,30 +2,30 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingExceptionValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingExceptionValueTest extends PubPackageResolutionTest { test_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Int8 Function(Int8); int f(int i) => i * 2; void g() { Pointer.fromFunction(f); +// ^^^^^^^^^^^^ +// [diag.missingExceptionValue] The method fromFunction must have an exceptional return value (the second argument) when the return type of the function is neither 'void', 'Handle', nor 'Pointer'. } -''', - [error(diag.missingExceptionValue, 96, 12)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/missing_field_type_in_struct_test.dart b/pkg/analyzer/test/src/diagnostics/missing_field_type_in_struct_test.dart index 44767ca1275..17deac63d24 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_field_type_in_struct_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_field_type_in_struct_test.dart @@ -2,35 +2,35 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingFieldTypeInStructTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingFieldTypeInStructTest extends PubPackageResolutionTest { test_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { external var str; +// ^^^ +// [diag.missingFieldTypeInStruct] Fields in struct classes must have an explicitly declared type of 'int', 'double' or 'Pointer'. external Pointer notEmpty; } -''', - [error(diag.missingFieldTypeInStruct, 65, 3)], - ); +'''); } test_valid() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { external Pointer p; diff --git a/pkg/analyzer/test/src/diagnostics/missing_override_of_must_be_overridden_test.dart b/pkg/analyzer/test/src/diagnostics/missing_override_of_must_be_overridden_test.dart index e38a647f5a0..a72a708cf84 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_override_of_must_be_overridden_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_override_of_must_be_overridden_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingOverrideOfMustBeOverriddenTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,8 +23,7 @@ class MissingOverrideOfMustBeOverriddenTest extends PubPackageResolutionTest { } test_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -32,27 +32,25 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 86, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'. +'''); } test_field_declaredInPrimaryConstructor() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A(@mustBeOverridden var int f); class B(super.f) extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 79, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'. +'''); } test_field_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -64,20 +62,13 @@ class A { } class B extends A {} -''', - [ - error( - diag.missingOverrideOfMustBeOverriddenTwo, - 121, - 1, - messageContains: ["'f'", "'m'"], - ), - ], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenTwo] Missing a required override of 'm' and 'f'. +'''); } test_field_overriddenWithField() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -92,7 +83,7 @@ class B extends A { } test_field_overriddenWithField_inPrimaryConstructor() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -105,7 +96,7 @@ class B(var int f) extends A; } test_field_overriddenWithGetterSetterPair() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -122,8 +113,7 @@ class B extends A { } test_field_overriddenWithOnlyGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -132,15 +122,15 @@ class A { } class B extends A { +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'. int get f => 0; } -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 86, 1)], - ); +'''); } test_finalField_overriddenWithOnlyGetter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -155,8 +145,7 @@ class B extends A { } test_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -165,13 +154,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 91, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'. +'''); } test_getter_overriddenWithField() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -186,7 +175,7 @@ class B extends A { } test_getter_overriddenWithField_inPrimaryConstructor() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -199,7 +188,7 @@ class B(var int f) extends A; } test_getter_overriddenWithGetter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -214,8 +203,7 @@ class B extends A { } test_method_directMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; mixin M { @@ -224,14 +212,13 @@ mixin M { } class A with M {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 87, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'. +'''); } test_method_directSuperclass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -240,14 +227,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 87, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'. +'''); } test_method_directSuperclass_three() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -262,14 +248,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenThreePlus, 157, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenThreePlus] Missing a required override of 'm', 'n', and 1 more. +'''); } test_method_directSuperclass_two() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -281,13 +266,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenTwo, 122, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenTwo] Missing a required override of 'm' and 'n'. +'''); } test_method_hasAbstractOverride_isOkBecauseNotConcreteClass() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -302,7 +287,7 @@ abstract class B extends A { } test_method_hasConcreteOverride() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -317,7 +302,7 @@ class B extends A { } test_method_hasNoSuchMethod() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -332,8 +317,7 @@ class B extends A { } test_method_indirectMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; mixin M { @@ -346,14 +330,13 @@ class A with M { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 121, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'. +'''); } test_method_indirectSuperclass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -366,14 +349,13 @@ class B extends A { } class C extends B {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 124, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'. +'''); } test_method_indirectSuperclass_oneErrorPerName() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -387,14 +369,13 @@ class B extends A { } class C extends B {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 144, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'. +'''); } test_method_mixinApplication() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; mixin A { @@ -403,9 +384,9 @@ mixin A { } class B = Object with A; -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 87, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'. +'''); } test_method_notVisible() async { @@ -418,7 +399,7 @@ class A { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:test/a.dart'; class B extends A {} @@ -426,7 +407,7 @@ class B extends A {} } test_method_overriddenWithMethod_wildcardParams() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class C { @@ -442,7 +423,7 @@ class A extends C { } test_method_overriddenWithMethod_wildcardParams_preWildcards() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' // @dart = 3.4 // (pre wildcard-variables) @@ -461,7 +442,7 @@ class A extends C { } test_method_sealedClassIsImplicitlyAbstract() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -474,7 +455,7 @@ sealed class B extends A {} } test_method_superconstraint_isOkBecauseMixinsAreNotConcrete() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -487,8 +468,7 @@ mixin M on A {} } test_operator_directSuperclass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -497,14 +477,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 107, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of '+'. +'''); } test_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -513,14 +492,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 100, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'. +'''); } test_unary_operator() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @@ -529,13 +507,13 @@ class A { } class B extends A {} -''', - [error(diag.missingOverrideOfMustBeOverriddenOne, 96, 1)], - ); +// ^ +// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of '-'. +'''); } test_unary_operator_overriden() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @mustBeOverridden diff --git a/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart b/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart index 524b7518076..94e20b2c99f 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart @@ -2,45 +2,43 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingRequiredParamTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingRequiredParamTest extends PubPackageResolutionTest { test_annotation_noImportPrefix_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.named({required int a}); } @A.named() +// ^^^^^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. void f() {} -''', - [error(diag.missingRequiredArgument, 51, 5)], - ); +'''); } test_annotation_noImportPrefix_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A({required int a}); } @A() +// [diag.missingRequiredArgument][column 2][length 1] The named parameter 'a' is required, but there's no corresponding argument. void f() {} -''', - [error(diag.missingRequiredArgument, 43, 1)], - ); +'''); } test_annotation_withImportPrefix_named() async { @@ -50,15 +48,14 @@ class A { } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as a; @a.A.named() +// ^^^^^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. void f() {} -''', - [error(diag.missingRequiredArgument, 28, 5)], - ); +'''); } test_annotation_withImportPrefix_unnamed() async { @@ -68,19 +65,18 @@ class A { } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as a; @a.A() +// ^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. void f() {} -''', - [error(diag.missingRequiredArgument, 26, 1)], - ); +'''); } test_constructor_argumentGiven() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { C({required int a}) {} } @@ -92,67 +88,62 @@ main() { } test_constructor_fieldFormal_missingName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required this.}) +// ^^^^^^^^^^^^^^ +// [diag.initializingFormalForNonExistentField] '' isn't a field in the enclosing class. +// ^ +// [diag.missingIdentifier] Expected an identifier. } +// [diag.missingFunctionBody][column 1][length 1] A function body must be provided. void f() { A(); } -''', - [ - error(diag.initializingFormalForNonExistentField, 15, 14), - error(diag.missingIdentifier, 29, 1), - error(diag.missingFunctionBody, 32, 1), - ], - ); +'''); } test_constructor_missingArgument() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { C({required int a}) {} } main() { new C(); +// ^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 52, 1)], - ); +'''); } test_constructor_redirectingConstructorCall() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { C({required int x}); C.named() : this(); +// ^^^^^^ +// [diag.missingRequiredArgument] The named parameter 'x' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 47, 6)], - ); +'''); } test_constructor_superCall() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { C({required int a}) {} } class D extends C { D() : super(); +// ^^^^^^^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 66, 7)], - ); +'''); } test_constructor_superFormalParameter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int a}); } @@ -164,79 +155,73 @@ class B extends A { } test_enumConstant_withArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(); +//^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. const E({required int a}); } -''', - [error(diag.missingRequiredArgument, 11, 1)], - ); +'''); } test_enumConstant_withoutArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; +//^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. const E({required int a}); } -''', - [error(diag.missingRequiredArgument, 11, 1)], - ); +'''); } test_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f({required int a}) {} main() { f(); +//^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 40, 1)], - ); +'''); } test_function_call() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f({required int a}) {} main() { f.call(); +// ^^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 46, 2)], - ); +'''); } test_functionInvocation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void Function({required int a}) f() => throw ''; g() { f()(); +//^^^^^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 57, 5)], - ); +'''); } test_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void m({required int a}) {} } f() { new A().m(); +// ^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 58, 1)], - ); +'''); } test_method_inOtherLib() async { @@ -245,29 +230,27 @@ class A { void m({required int a}) {} } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import "a_lib.dart"; f() { new A().m(); +// ^ +// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument. } -''', - [error(diag.missingRequiredArgument, 37, 1)], - ); +'''); } test_typedef_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' String test(C c) => c.m()(); +// ^^^^^^^ +// [diag.missingRequiredArgument] The named parameter 'x' is required, but there's no corresponding argument. typedef String F({required String x}); class C { F m() => ({required String x}) => throw ''; } -''', - [error(diag.missingRequiredArgument, 20, 7)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/missing_size_annotation_carray_test.dart b/pkg/analyzer/test/src/diagnostics/missing_size_annotation_carray_test.dart index 9852130be0d..da4a6775a73 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_size_annotation_carray_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_size_annotation_carray_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingSizeAnnotationArray); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingSizeAnnotationArray extends PubPackageResolutionTest { test_one() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @@ -27,15 +28,14 @@ final class C extends Struct { } test_two() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { external Array a0; +// ^^^^^^^^^^^^ +// [diag.missingSizeAnnotationCarray] Fields of type 'Array' must have exactly one 'Array' annotation. } -''', - [error(diag.missingSizeAnnotationCarray, 62, 12)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/missing_variable_pattern_test.dart b/pkg/analyzer/test/src/diagnostics/missing_variable_pattern_test.dart index 5af18100622..1c22de0955f 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_variable_pattern_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_variable_pattern_test.dart @@ -2,33 +2,32 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingVariablePatternTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MissingVariablePatternTest extends PubPackageResolutionTest { test_ifCase_differentStatements_nested() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case final a) { +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. if (x case final b) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used. } } -''', - [ - error(diag.unusedLocalVariable, 35, 1), - error(diag.unusedLocalVariable, 61, 1), - ], - ); +'''); var node1 = findNode.caseClause('case final a').guardedPattern; assertResolvedNodeText(node1, r''' @@ -48,7 +47,7 @@ GuardedPattern pattern: DeclaredVariablePattern keyword: final name: b - declaredFragment: isFinal isPublic b@61 + declaredFragment: isFinal isPublic b@160 element: hasImplicitType isFinal isPublic type: int matchedValueType: int @@ -56,18 +55,16 @@ GuardedPattern } test_ifCase_differentStatements_sibling() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case final a) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. if (x case final b) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 35, 1), - error(diag.unusedLocalVariable, 60, 1), - ], - ); +'''); var node1 = findNode.caseClause('case final a').guardedPattern; assertResolvedNodeText(node1, r''' @@ -87,7 +84,7 @@ GuardedPattern pattern: DeclaredVariablePattern keyword: final name: b - declaredFragment: isFinal isPublic b@60 + declaredFragment: isFinal isPublic b@159 element: hasImplicitType isFinal isPublic type: int matchedValueType: int @@ -95,18 +92,17 @@ GuardedPattern } test_ifCase_logicalOr2_both_direct() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case final a || final a) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 35, 1), - error(diag.deadCode, 37, 10), - error(diag.unusedLocalVariable, 46, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -130,17 +126,15 @@ LogicalOrPattern } test_ifCase_logicalOr2_both_nested_logicalAnd() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case 0 && final a || final a) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 40, 1), - error(diag.unusedLocalVariable, 51, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -172,17 +166,15 @@ LogicalOrPattern } test_ifCase_logicalOr2_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case final int a || 2) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. } -''', - [ - error(diag.unusedLocalVariable, 39, 1), - error(diag.missingVariablePattern, 44, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -208,17 +200,15 @@ LogicalOrPattern } test_ifCase_logicalOr2_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case 1 || final a) {} +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.missingVariablePattern, 29, 1), - error(diag.unusedLocalVariable, 40, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -240,18 +230,17 @@ LogicalOrPattern } test_ifCase_logicalOr3_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case final int a || 2 || 3) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. } -''', - [ - error(diag.unusedLocalVariable, 39, 1), - error(diag.missingVariablePattern, 44, 1), - error(diag.missingVariablePattern, 49, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -285,18 +274,17 @@ LogicalOrPattern } test_ifCase_logicalOr3_12() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case final int a || final int a || 3) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. } -''', - [ - error(diag.unusedLocalVariable, 39, 1), - error(diag.unusedLocalVariable, 54, 1), - error(diag.missingVariablePattern, 59, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -336,20 +324,21 @@ LogicalOrPattern } test_ifCase_logicalOr3_123() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case final a || final a || final a) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 35, 1), - error(diag.deadCode, 37, 10), - error(diag.unusedLocalVariable, 46, 1), - error(diag.deadCode, 48, 10), - error(diag.unusedLocalVariable, 57, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -383,18 +372,17 @@ LogicalOrPattern } test_ifCase_logicalOr3_13() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case final int a || 2 || final int a) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 39, 1), - error(diag.missingVariablePattern, 44, 1), - error(diag.unusedLocalVariable, 59, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -434,18 +422,17 @@ LogicalOrPattern } test_ifCase_logicalOr3_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case 1 || final int a || 3) {} +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. } -''', - [ - error(diag.missingVariablePattern, 29, 1), - error(diag.unusedLocalVariable, 44, 1), - error(diag.missingVariablePattern, 49, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -479,19 +466,19 @@ LogicalOrPattern } test_ifCase_logicalOr3_23() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case 1 || final a || final a) {} +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.missingVariablePattern, 29, 1), - error(diag.unusedLocalVariable, 40, 1), - error(diag.deadCode, 42, 10), - error(diag.unusedLocalVariable, 51, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -523,17 +510,15 @@ LogicalOrPattern } test_ifCase_logicalOr3_3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case 1 || 2 || final a) {} +// ^^^^^^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.missingVariablePattern, 29, 6), - error(diag.unusedLocalVariable, 45, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -563,21 +548,20 @@ LogicalOrPattern } test_switchStatement_case1_logicalOr2_both() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { case final a || final a: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. return; } } -''', - [ - error(diag.unusedLocalVariable, 46, 1), - error(diag.deadCode, 48, 10), - error(diag.unusedLocalVariable, 57, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -601,22 +585,20 @@ LogicalOrPattern } test_switchStatement_case1_logicalOr2_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { switch (x) { case final int a || 2: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. return; default: return; } } -''', - [ - error(diag.unusedLocalVariable, 50, 1), - error(diag.missingVariablePattern, 55, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -642,20 +624,18 @@ LogicalOrPattern } test_switchStatement_case1_logicalOr2_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { case 1 || final a: +// ^ +// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. return; } } -''', - [ - error(diag.missingVariablePattern, 40, 1), - error(diag.unusedLocalVariable, 51, 1), - ], - ); +'''); var node = findNode.singleGuardedPattern.pattern; assertResolvedNodeText(node, r''' LogicalOrPattern @@ -677,23 +657,22 @@ LogicalOrPattern } test_switchStatement_case2_both() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { case /*1*/ final a: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. case /*2*/ final a: +// ^^^^ +// [diag.deadCode] Dead code. +// [diag.unreachableSwitchCase] This case is covered by the previous cases. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. return; } } -''', - [ - error(diag.unusedLocalVariable, 52, 1), - error(diag.deadCode, 59, 4), - error(diag.unreachableSwitchCase, 59, 4), - error(diag.unusedLocalVariable, 76, 1), - ], - ); +'''); var node1 = findNode.switchPatternCase('case /*1*/').guardedPattern; assertResolvedNodeText(node1, r''' @@ -713,7 +692,7 @@ GuardedPattern pattern: DeclaredVariablePattern keyword: final name: a - declaredFragment: isFinal isPublic a@76 + declaredFragment: isFinal isPublic a@177 element: hasImplicitType isFinal isPublic type: int matchedValueType: int @@ -721,43 +700,42 @@ GuardedPattern } test_switchStatement_case2_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { switch (x) { case final double a: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. case 2: return; default: return; } } -''', - [error(diag.unusedLocalVariable, 53, 1)], - ); +'''); } test_switchStatement_case2_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { case 1: case final a: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. return; } } -''', - [error(diag.unusedLocalVariable, 58, 1)], - ); +'''); } test_switchStatement_differentCases_nested() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { case final a: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. switch (x) { case 2: return; @@ -765,17 +743,16 @@ void f(int x) { return; } } -''', - [error(diag.unusedLocalVariable, 46, 1)], - ); +'''); } test_switchStatement_differentCases_sibling() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { switch (x) { case final double a: +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. return; case 2: return; @@ -783,8 +760,6 @@ void f(num x) { return; } } -''', - [error(diag.unusedLocalVariable, 53, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_application_concrete_super_invoked_member_type_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_application_concrete_super_invoked_member_type_test.dart index 7ebb5c30610..84376500897 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_application_concrete_super_invoked_member_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_application_concrete_super_invoked_member_type_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinApplicationConcreteSuperInvokedMemberTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,8 +18,7 @@ main() { class MixinApplicationConcreteSuperInvokedMemberTypeTest extends PubPackageResolutionTest { test_class_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class I { void foo([int? p]) {} } @@ -38,13 +38,13 @@ mixin M on I { } abstract class X extends B with M {} -''', - [error(diag.mixinApplicationConcreteSuperInvokedMemberType, 227, 1)], - ); +// ^ +// [diag.mixinApplicationConcreteSuperInvokedMemberType] The super-invoked member 'foo' has the type 'void Function([int?])', and the concrete member in the class has the type 'void Function(int?)'. +'''); } test_class_method_OK_overriddenInMixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void remove(T x) {} } @@ -60,8 +60,7 @@ class X = A with M; } test_enum_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class I { void foo([int? p]); } @@ -79,11 +78,11 @@ mixin M3 on I { } enum E with M1, M2, M3 { +// ^^ +// [diag.mixinApplicationConcreteSuperInvokedMemberType] The super-invoked member 'foo' has the type 'void Function([int?])', and the concrete member in the class has the type 'void Function(int?)'. v; void foo([int? p]) {} } -''', - [error(diag.mixinApplicationConcreteSuperInvokedMemberType, 183, 2)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_application_no_concrete_super_invoked_member_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_application_no_concrete_super_invoked_member_test.dart index 2e1110587f0..036ece1d23f 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_application_no_concrete_super_invoked_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_application_no_concrete_super_invoked_member_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinApplicationNoConcreteSuperInvokedMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,8 +18,7 @@ main() { class MixinApplicationNoConcreteSuperInvokedMemberTest extends PubPackageResolutionTest { test_class_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { int get foo; } @@ -30,14 +30,13 @@ mixin M on A { } abstract class X extends A with M {} -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedMember, 121, 1)], - ); +// ^ +// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'. +'''); } test_class_inNextMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { void foo(); } @@ -53,14 +52,13 @@ mixin M2 on A { } class X extends A with M1, M2 {} -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedMember, 149, 2)], - ); +// ^^ +// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'. +'''); } test_class_inSameMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { void foo(); } @@ -72,14 +70,13 @@ mixin M on A { } class X extends A with M {} -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedMember, 113, 1)], - ); +// ^ +// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'. +'''); } test_class_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -91,13 +88,13 @@ mixin M on A { } abstract class X extends A with M {} -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedMember, 122, 1)], - ); +// ^ +// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'. +'''); } test_class_OK_hasNSM() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -117,7 +114,7 @@ class X extends C with M {} } test_class_OK_hasNSM2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -141,7 +138,7 @@ class X extends C with M {} } test_class_OK_inPreviousMixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -161,7 +158,7 @@ class X extends A with M1, M2 {} } test_class_OK_inSuper_fromMixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -183,7 +180,7 @@ class X extends B with M2 {} } test_class_OK_notInvoked() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -195,7 +192,7 @@ abstract class X extends A with M {} } test_class_OK_super_covariant() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { bar(num n) {} } @@ -215,8 +212,7 @@ class C extends B with M {} } test_class_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void set foo(_); } @@ -228,14 +224,13 @@ mixin M on A { } abstract class X extends A with M {} -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedSetter, 129, 1)], - ); +// ^ +// [diag.mixinApplicationNoConcreteSuperInvokedSetter] The class doesn't have a concrete implementation of the super-invoked setter 'foo'. +'''); } test_enum_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 { int get foo; } @@ -247,16 +242,16 @@ mixin M2 on M1 { } enum E with M1, M2 { +// ^^ +// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'. v; int get foo => 0; } -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedMember, 99, 2)], - ); +'''); } test_enum_getter_exists() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 { int get foo => 0; } @@ -274,7 +269,7 @@ enum E with M1, M2 { } test_enum_getter_index() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M on Enum { void foo() { super.index; @@ -288,8 +283,7 @@ enum E with M { } test_enum_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 { void foo(); } @@ -301,16 +295,16 @@ mixin M2 on M1 { } enum E with M1, M2 { +// ^^ +// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'. v; void foo() {} } -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedMember, 100, 2)], - ); +'''); } test_enum_method_exists() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 { void foo() {} } @@ -328,7 +322,7 @@ enum E with M1, M2 { } test_enum_OK_getter_inPreviousMixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 { int get foo => 0; } @@ -346,8 +340,7 @@ enum E with M1, M2 { } test_enum_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 { set foo(int _); } @@ -359,11 +352,11 @@ mixin M2 on M1 { } enum E with M1, M2 { +// ^^ +// [diag.mixinApplicationNoConcreteSuperInvokedSetter] The class doesn't have a concrete implementation of the super-invoked setter 'foo'. v; set foo(int _) {} } -''', - [error(diag.mixinApplicationNoConcreteSuperInvokedSetter, 106, 2)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_application_not_implemented_interface_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_application_not_implemented_interface_test.dart index 82ad6d13728..b5bb306733a 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_application_not_implemented_interface_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_application_not_implemented_interface_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinApplicationNotImplementedInterfaceTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -18,23 +19,22 @@ class MixinApplicationNotImplementedInterfaceTest extends PubPackageResolutionTest { test_class_hasRecursion() async { // https://github.com/dart-lang/sdk/issues/61829 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} abstract class X with Unresolved, M, CycleWithX {} +// ^ +// [diag.recursiveInterfaceInheritance] 'X' can't be a superinterface of itself: CycleWithX, X. +// ^^^^^^^^^^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. mixin M on A {} mixin CycleWithX on X {} -''', - [ - error(diag.recursiveInterfaceInheritance, 26, 1), - error(diag.mixinOfNonClass, 33, 10), - error(diag.recursiveInterfaceInheritance, 84, 10), - ], - ); +// ^^^^^^^^^^ +// [diag.recursiveInterfaceInheritance] 'CycleWithX' can't be a superinterface of itself: CycleWithX, X. +'''); } test_class_matchingInterface() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} class B {} mixin M on A {} @@ -43,7 +43,7 @@ class C extends A with M {} } test_class_matchingInterface_inPreviousMixin() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} class B {} mixin M1 implements A {} @@ -53,45 +53,39 @@ class C extends Object with M1, M2 {} } test_class_noMatchingInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} class B {} mixin M on A {} class C extends Object with M {} -''', - [error(diag.mixinApplicationNotImplementedInterface, 84, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_class_noMatchingInterface_fromAugmentation() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class B with M {} mixin M {} class A {} augment mixin M on A {} -''', - [error(diag.mixinApplicationNotImplementedInterface, 13, 1)], - ); +'''); } test_class_noMatchingInterface_withTypeArguments() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} class B {} mixin M on A {} class C extends Object with M {} -''', - [error(diag.mixinApplicationNotImplementedInterface, 84, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'. +'''); } test_class_noMemberErrors() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -107,13 +101,13 @@ class C { } class X = C with M; -''', - [error(diag.mixinApplicationNotImplementedInterface, 134, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'C' because 'C' doesn't implement 'A'. +'''); } test_class_noSuperclassConstraint() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} class B {} mixin M {} @@ -123,13 +117,15 @@ class C extends Object with M {} test_class_recursiveSubtypeCheck() async { // See dartbug.com/32353 for a detailed explanation. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class ioDirectory implements ioFileSystemEntity {} class ioFileSystemEntity {} abstract class _LocalDirectory +// ^^^^^^^^^^^^^^^ +// [diag.conflictingGenericInterfaces] The class '_LocalDirectory' can't implement both 'ForwardingFileSystemEntity<_LocalDirectory, ioDirectory>' and 'ForwardingFileSystemEntity' because the type arguments are different. +// [diag.unusedElement] The declaration '_LocalDirectory' isn't referenced. extends _LocalFileSystemEntity<_LocalDirectory, ioDirectory> with ForwardingDirectory, DirectoryAddOnsMixin {} @@ -149,57 +145,49 @@ mixin ForwardingDirectory abstract class Directory implements FileSystemEntity, ioDirectory {} mixin DirectoryAddOnsMixin implements Directory {} -''', - [ - error(diag.conflictingGenericInterfaces, 96, 15), - error(diag.unusedElement, 96, 15), - ], - ); +'''); var mixins = findElement2.class_('_LocalDirectory').mixins; assertType(mixins[0], 'ForwardingDirectory'); } test_classTypeAlias_generic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A {} class X = A with M; -''', - [error(diag.mixinApplicationNotImplementedInterface, 62, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'A' because 'A' doesn't implement 'A'. +'''); } test_classTypeAlias_noMatchingInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} class B {} mixin M on A {} class C = Object with M; -''', - [error(diag.mixinApplicationNotImplementedInterface, 78, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'. +'''); } test_classTypeAlias_notGeneric() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A {} class X = Object with M; -''', - [error(diag.mixinApplicationNotImplementedInterface, 51, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'. +'''); } test_classTypeAlias_OK_0() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M {} class X = Object with M; @@ -207,7 +195,7 @@ class X = Object with M; } test_classTypeAlias_OK_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A {} @@ -217,7 +205,7 @@ class X = A with M; } test_classTypeAlias_OK_generic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A {} @@ -229,7 +217,7 @@ class C = B with M; } test_classTypeAlias_OK_previousMixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M1 implements A {} @@ -241,8 +229,7 @@ class X = Object with M1, M2; } test_classTypeAlias_oneOfTwo() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B {} class C {} @@ -250,13 +237,13 @@ class C {} mixin M on A, B {} class X = C with M; -''', - [error(diag.mixinApplicationNotImplementedInterface, 71, 1)], - ); +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'C' because 'C' doesn't implement 'A'. +'''); } test_enum_matchingInterface_inPreviousMixin() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} mixin M1 implements A {} @@ -270,22 +257,21 @@ enum E with M1, M2 { } test_enum_noMatchingInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} mixin M on A {} enum E with M { +// ^ +// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Enum' because 'Enum' doesn't implement 'A'. v } -''', - [error(diag.mixinApplicationNotImplementedInterface, 50, 1)], - ); +'''); } test_enum_noSuperclassConstraint() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' mixin M {} enum E with M { diff --git a/pkg/analyzer/test/src/diagnostics/mixin_class_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_class_declaration_test.dart index 0e6375efc6a..06f110fd49a 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_class_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_class_declaration_test.dart @@ -2,66 +2,58 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinClassDeclarationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinClassDeclarationTest extends PubPackageResolutionTest { test_class_extends_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin class B extends A {} -''', - [error(diag.mixinClassDeclarationExtendsNotObject, 33, 1)], - ); +// ^ +// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'. +'''); } test_class_extends_Object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A extends Object {} '''); } test_class_extends_Object_with() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M {} mixin class A extends Object with M {} -''', - [error(diag.mixinClassDeclarationWithClause, 40, 6)], - ); +// ^^^^^^ +// [diag.mixinClassDeclarationWithClause] The class 'A' can't be declared a mixin because it has a 'with' clause. +'''); } test_classTypeAlias_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M {} mixin class A = Object with M; '''); } test_classTypeAlias_with2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M1 {} mixin M2 {} mixin class A = Object with M1, M2; -''', - [ - error( - diag.mixinModifierMixinApplicationClassWithMultipleMixins, - 47, - 11, - ), - ], - ); +// ^^^^^^^^^^^ +// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'A' can only have a single mixin. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_class_declares_non_trivial_generative_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_class_declares_non_trivial_generative_constructor_test.dart index dd16a67f738..7e77e7ce097 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_class_declares_non_trivial_generative_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_class_declares_non_trivial_generative_constructor_test.dart @@ -2,16 +2,17 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests( MixinClassDeclaresNonTrivialGenerativeConstructorTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,7 +20,7 @@ main() { class MixinClassDeclaresNonTrivialGenerativeConstructorTest extends PubPackageResolutionTest { test_mixinClass_constructor_factory_blockBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A.named(); factory A.x() { @@ -31,7 +32,7 @@ class B with A {} } test_mixinClass_constructor_factory_redirect() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A.named(); factory A.x() = A.named; @@ -41,68 +42,63 @@ class B with A {} } test_mixinClass_constructor_generative_redirect() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A() : this.named(); +//^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. A.named(); } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)], - ); +'''); } test_mixinClass_constructor_newHead_nonTrivial_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { new() {} +//^^^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 3)], - ); +'''); } test_mixinClass_constructor_newHead_nonTrivial_external() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { external new(); +// ^^^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 27, 3)], - ); +'''); } test_mixinClass_constructor_newHead_nonTrivial_hasFormalParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { new(int foo); +//^^^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 3)], - ); +'''); } test_mixinClass_constructor_newHead_nonTrivial_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { new(): super(); +//^^^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 3)], - ); +'''); } test_mixinClass_constructor_newHead_trivial() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { new(); } @@ -111,7 +107,7 @@ class B with A {} } test_mixinClass_constructor_newHead_trivial_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { const new(); } @@ -120,7 +116,7 @@ class B with A {} } test_mixinClass_constructor_trivial_named() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A.named(); } @@ -129,7 +125,7 @@ class B with A {} } test_mixinClass_constructor_trivial_named_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { const A.named(); } @@ -138,67 +134,62 @@ class B with A {} } test_mixinClass_constructor_typeName_nonTrivial_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A() {} +//^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)], - ); +'''); } test_mixinClass_constructor_typeName_nonTrivial_blockBody_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A.named() {} +//^^^^^^^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 7)], - ); +'''); } test_mixinClass_constructor_typeName_nonTrivial_external() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { external A(); +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 27, 1)], - ); +'''); } test_mixinClass_constructor_typeName_nonTrivial_hasFormalParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A(int foo); +//^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)], - ); +'''); } test_mixinClass_constructor_typeName_nonTrivial_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A(): super(); +//^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)], - ); +'''); } test_mixinClass_constructor_typeName_trivial() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { A(); } @@ -207,7 +198,7 @@ class B with A {} } test_mixinClass_constructor_typeName_trivial_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A { const A(); } @@ -216,48 +207,45 @@ class B with A {} } test_mixinClass_primaryConstructor_named_nonTrivial_hasBody_block() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A.named() { this {} +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 31, 1)], - ); +'''); } test_mixinClass_primaryConstructor_named_nonTrivial_hasFormalParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A.named(int x) {} +// ^^^^^^^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 12, 7)], - ); +'''); } test_mixinClass_primaryConstructor_named_nonTrivial_hasInitializer() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A.named() { this : assert(true); +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 31, 1)], - ); +'''); } test_mixinClass_primaryConstructor_named_trivial() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A.named() {} class B with A {} '''); } test_mixinClass_primaryConstructor_named_trivial_hasBody_empty() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A.named() { this; } @@ -266,60 +254,56 @@ class B with A {} } test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasBody_block() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A() { this {} +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 25, 1)], - ); +'''); } test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasBody_block_hasInitializer() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A() { this : assert(true) {} +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 25, 1)], - ); +'''); } test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasFormalParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A(int x) {} +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 12, 1)], - ); +'''); } test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasInitializer() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A() { this : assert(true); +// ^ +// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor. } class B with A {} -''', - [error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 25, 1)], - ); +'''); } test_mixinClass_primaryConstructor_unnamed_trivial() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A() {} class B with A {} '''); } test_mixinClass_primaryConstructor_unnamed_trivial_hasBody_empty() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A() { this; } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_declares_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_declares_constructor_test.dart index 981f5a5af66..708824d434d 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_declares_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_declares_constructor_test.dart @@ -2,28 +2,28 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinDeclaresConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinDeclaresConstructorTest extends PubPackageResolutionTest { test_factory_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { factory M.named() => throw 0; +//^^^^^^^ +// [diag.mixinDeclaresConstructor] Mixins can't declare constructors. } -''', - [error(diag.mixinDeclaresConstructor, 12, 7)], - ); +'''); var node = findNode.singleMixinDeclaration; assertResolvedNodeText(node, r''' @@ -40,14 +40,13 @@ invalidNodes } test_factory_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { factory M() => throw 0; +//^^^^^^^ +// [diag.mixinDeclaresConstructor] Mixins can't declare constructors. } -''', - [error(diag.mixinDeclaresConstructor, 12, 7)], - ); +'''); var node = findNode.singleMixinDeclaration; assertResolvedNodeText(node, r''' @@ -64,14 +63,13 @@ invalidNodes } test_generative_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { M.named(); +//^ +// [diag.mixinDeclaresConstructor] Mixins can't declare constructors. } -''', - [error(diag.mixinDeclaresConstructor, 12, 1)], - ); +'''); var node = findNode.singleMixinDeclaration; assertResolvedNodeText(node, r''' @@ -88,14 +86,13 @@ invalidNodes } test_generative_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { M(); +//^ +// [diag.mixinDeclaresConstructor] Mixins can't declare constructors. } -''', - [error(diag.mixinDeclaresConstructor, 12, 1)], - ); +'''); var node = findNode.singleMixinDeclaration; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/mixin_deferred_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_deferred_class_test.dart index 708ff92c89c..1d07bfe7c46 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_deferred_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_deferred_class_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinDeferredClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -20,36 +21,30 @@ class MixinDeferredClassTest extends PubPackageResolutionTest { library lib1; class A {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' library root; import 'lib1.dart' deferred as a; class B {} class C = B with a.A; -''', - [ - error(diag.mixinDeferredClass, 76, 3), - error(diag.classUsedAsMixin, 76, 3), - ], - ); +// ^^^ +// [diag.mixinDeferredClass] Classes can't mixin deferred classes. +// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin. +'''); } test_enum() async { newFile('$testPackageLibPath/a.dart', ''' class A {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart' deferred as a; enum E with a.A { +// ^^^ +// [diag.mixinDeferredClass] Classes can't mixin deferred classes. +// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin. v; } -''', - [ - error(diag.mixinDeferredClass, 43, 3), - error(diag.classUsedAsMixin, 43, 3), - ], - ); +'''); } test_mixin_deferred_class() async { @@ -57,16 +52,13 @@ enum E with a.A { library lib1; class A {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' library root; import 'lib1.dart' deferred as a; class B extends Object with a.A {} -''', - [ - error(diag.mixinDeferredClass, 76, 3), - error(diag.classUsedAsMixin, 76, 3), - ], - ); +// ^^^ +// [diag.mixinDeferredClass] Classes can't mixin deferred classes. +// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart index 6a535a71768..f8d282d2956 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart @@ -5,10 +5,12 @@ import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinInferenceNoPossibleSubstitutionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -16,7 +18,7 @@ main() { class MixinInferenceNoPossibleSubstitutionTest extends PubPackageResolutionTest { test_valid_single() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A {} diff --git a/pkg/analyzer/test/src/diagnostics/mixin_inherits_from_not_object_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_inherits_from_not_object_test.dart index c56d8199a22..54a4ce59323 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_inherits_from_not_object_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_inherits_from_not_object_test.dart @@ -2,47 +2,45 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinInheritsFromNotObjectTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinInheritsFromNotObjectTest extends PubPackageResolutionTest { test_class_class_extends() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin class B extends A {} +// ^ +// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'. class C extends Object with B {} -''', - [ - error(diag.mixinClassDeclarationExtendsNotObject, 33, 1), - error(diag.mixinInheritsFromNotObject, 66, 1), - ], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_class_class_extends_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends A {} class C extends Object with B {} -''', - [error(diag.mixinInheritsFromNotObject, 74, 1)], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_class_class_extends_Object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin class B extends Object {} class C extends Object with B {} @@ -50,7 +48,7 @@ class C extends Object with B {} } test_class_class_extends_Object_language219() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends Object {} @@ -59,33 +57,30 @@ class C extends Object with B {} } test_class_class_with() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B extends Object with A {} +// ^^^^^^ +// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause. class C extends Object with B {} -''', - [ - error(diag.mixinClassDeclarationWithClause, 46, 6), - error(diag.mixinInheritsFromNotObject, 84, 1), - ], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_class_class_with_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends Object with A {} class C extends Object with B {} -''', - [error(diag.mixinInheritsFromNotObject, 86, 1)], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_class_classTypeAlias_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B = Object with A; class C extends Object with B {} @@ -93,35 +88,32 @@ class C extends Object with B {} } test_class_classTypeAlias_with2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B {} mixin class C = Object with A, B; +// ^^^^^^^^^ +// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'C' can only have a single mixin. class D extends Object with C {} -''', - [ - error(diag.mixinModifierMixinApplicationClassWithMultipleMixins, 57, 9), - error(diag.mixinInheritsFromNotObject, 96, 1), - ], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_class_classTypeAlias_with2_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B {} class C = Object with A, B; class D extends Object with C {} -''', - [error(diag.mixinInheritsFromNotObject, 92, 1)], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_class_classTypeAlias_with_language219() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B = Object with A; @@ -130,7 +122,7 @@ class C extends Object with B {} } test_class_mixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin B on A {} class C extends A with B {} @@ -138,59 +130,53 @@ class C extends A with B {} } test_classTypeAlias_class_extends() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin class B extends A {} +// ^ +// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'. class C = Object with B; -''', - [ - error(diag.mixinClassDeclarationExtendsNotObject, 33, 1), - error(diag.mixinInheritsFromNotObject, 60, 1), - ], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_classTypeAlias_class_extends_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends A {} class C = Object with B; -''', - [error(diag.mixinInheritsFromNotObject, 68, 1)], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_classTypeAlias_class_with() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B extends Object with A {} +// ^^^^^^ +// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause. class C = Object with B; -''', - [ - error(diag.mixinClassDeclarationWithClause, 46, 6), - error(diag.mixinInheritsFromNotObject, 78, 1), - ], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_classTypeAlias_class_with_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends Object with A {} class C = Object with B; -''', - [error(diag.mixinInheritsFromNotObject, 80, 1)], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_classTypeAlias_classAlias_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B = Object with A; class C = Object with B; @@ -198,35 +184,32 @@ class C = Object with B; } test_classTypeAlias_classAlias_with2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B {} mixin class C = Object with A, B; +// ^^^^^^^^^ +// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'C' can only have a single mixin. class D = Object with C; -''', - [ - error(diag.mixinModifierMixinApplicationClassWithMultipleMixins, 57, 9), - error(diag.mixinInheritsFromNotObject, 90, 1), - ], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_classTypeAlias_classAlias_with2_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B {} class C = Object with A, B; class D = Object with C; -''', - [error(diag.mixinInheritsFromNotObject, 86, 1)], - ); +// ^ +// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'. +'''); } test_classTypeAlias_classAlias_with_language219() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B = Object with A; @@ -235,7 +218,7 @@ class C = Object with B; } test_classTypeAlias_mixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin B on A {} class C = A with B; @@ -243,37 +226,34 @@ class C = A with B; } test_enum_class_extends() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin class B extends A {} +// ^ +// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'. enum E with B { +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. v } -''', - [ - error(diag.mixinClassDeclarationExtendsNotObject, 33, 1), - error(diag.mixinInheritsFromNotObject, 50, 1), - ], - ); +'''); } test_enum_class_extends_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends A {} enum E with B { +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. v } -''', - [error(diag.mixinInheritsFromNotObject, 58, 1)], - ); +'''); } test_enum_class_extends_Object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin class B extends Object {} enum E with B { @@ -283,7 +263,7 @@ enum E with B { } test_enum_class_extends_Object_language219() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends Object {} @@ -294,37 +274,34 @@ enum E with B { } test_enum_class_with() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B extends Object with A {} +// ^^^^^^ +// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause. enum E with B { +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. v } -''', - [ - error(diag.mixinClassDeclarationWithClause, 46, 6), - error(diag.mixinInheritsFromNotObject, 68, 1), - ], - ); +'''); } test_enum_class_with_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B extends Object with A {} enum E with B { +// ^ +// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'. v } -''', - [error(diag.mixinInheritsFromNotObject, 70, 1)], - ); +'''); } test_enum_classTypeAlias_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B = Object with A; enum E with B { @@ -334,36 +311,34 @@ enum E with B { } test_enum_classTypeAlias_with2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B {} class C = Object with A, B; enum E with C { +// ^ +// [diag.classUsedAsMixin] The class 'C' can't be used as a mixin because it's neither a mixin class nor a mixin. v } -''', - [error(diag.classUsedAsMixin, 74, 1)], - ); +'''); } test_enum_classTypeAlias_with2_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B {} class C = Object with A, B; enum E with C { +// ^ +// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'. v } -''', - [error(diag.mixinInheritsFromNotObject, 76, 1)], - ); +'''); } test_enum_classTypeAlias_with_language219() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart=2.19 class A {} class B = Object with A; @@ -374,56 +349,52 @@ enum E with B { } test_mixinClass_class_extends() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B extends A {} -''', - [error(diag.mixinClassDeclarationExtendsNotObject, 39, 1)], - ); +// ^ +// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'. +'''); } test_mixinClass_class_extends_Object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A extends Object {} '''); } test_mixinClass_class_extends_Object_with() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B extends Object with A {} -''', - [error(diag.mixinClassDeclarationWithClause, 46, 6)], - ); +// ^^^^^^ +// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause. +'''); } test_mixinClass_class_with() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M {} mixin class A with M {} -''', - [error(diag.mixinClassDeclarationWithClause, 25, 6)], - ); +// ^^^^^^ +// [diag.mixinClassDeclarationWithClause] The class 'A' can't be declared a mixin because it has a 'with' clause. +'''); } test_mixinClass_classTypeAlias_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B = Object with A; '''); } test_mixinClass_classTypeAlias_with2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} mixin class B {} mixin class C = Object with A, B; -''', - [error(diag.mixinModifierMixinApplicationClassWithMultipleMixins, 57, 9)], - ); +// ^^^^^^^^^ +// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'C' can only have a single mixin. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_instantiate_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_instantiate_test.dart index 8ff2ce4f7a7..8634fd135d2 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_instantiate_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_instantiate_test.dart @@ -2,35 +2,34 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinInstantiateTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinInstantiateTest extends PubPackageResolutionTest { test_namedConstructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { M.named() {} +//^ +// [diag.mixinDeclaresConstructor] Mixins can't declare constructors. } void f() { new M.named(); +// ^ +// [diag.mixinInstantiate] Mixins can't be instantiated. } -''', - [ - error(diag.mixinDeclaresConstructor, 12, 1), - error(diag.mixinInstantiate, 45, 1), - ], - ); +'''); var node = findNode.singleInstanceCreationExpression; assertResolvedNodeText(node, r''' @@ -57,16 +56,15 @@ invalidNodes } test_unnamedConstructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M {} void f() { new M(); +// ^ +// [diag.mixinInstantiate] Mixins can't be instantiated. } -''', - [error(diag.mixinInstantiate, 29, 1)], - ); +'''); var node = findNode.singleInstanceCreationExpression; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/mixin_of_disallowed_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_of_disallowed_class_test.dart index 78eeb4d6ba8..eee425568a8 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_of_disallowed_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_of_disallowed_class_test.dart @@ -2,85 +2,79 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinOfDisallowedClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinOfDisallowedClassTest extends PubPackageResolutionTest { test_class_bool() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with bool {} -''', - [error(diag.mixinOfDisallowedClass, 28, 4)], - ); +// ^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'bool'. +'''); } test_class_bool_augment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A with bool {} -''', - [error(diag.mixinOfDisallowedClass, 33, 4)], - ); +// ^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'bool'. +'''); } test_class_double() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with double {} -''', - [error(diag.mixinOfDisallowedClass, 28, 6)], - ); +// ^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'double'. +'''); } test_class_FutureOr() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; class A extends Object with FutureOr {} -''', - [error(diag.mixinOfDisallowedClass, 49, 8)], - ); +// ^^^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr'. +'''); } test_class_FutureOr_typeArgument() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; class A extends Object with FutureOr {} -''', - [error(diag.mixinOfDisallowedClass, 49, 13)], - ); +// ^^^^^^^^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr'. +'''); } test_class_FutureOr_typeVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; class A extends Object with FutureOr {} -''', - [error(diag.mixinOfDisallowedClass, 52, 11)], - ); +// ^^^^^^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr'. +'''); } test_class_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with int {} -''', - [error(diag.mixinOfDisallowedClass, 28, 3)], - ); +// ^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'int'. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -96,138 +90,124 @@ augment class A with int {} '''); await assertErrorsInFile2(a, []); - await assertErrorsInFile2(b, [error(diag.mixinOfDisallowedClass, 39, 3)]); + await assertErrorsInFile2(b, []); } test_class_Null() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with Null {} -''', - [error(diag.mixinOfDisallowedClass, 28, 4)], - ); +// ^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'Null'. +'''); } test_class_num() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with num {} -''', - [error(diag.mixinOfDisallowedClass, 28, 3)], - ); +// ^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'num'. +'''); } test_class_Record() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with Record {} -''', - [error(diag.mixinOfDisallowedClass, 28, 6)], - ); +// ^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'Record'. +'''); } test_class_String() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A extends Object with String {} -''', - [error(diag.mixinOfDisallowedClass, 28, 6)], - ); +// ^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'String'. +'''); } test_classTypeAlias_bool() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with bool; -''', - [error(diag.mixinOfDisallowedClass, 28, 4)], - ); +// ^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'bool'. +'''); } test_classTypeAlias_double() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with double; -''', - [error(diag.mixinOfDisallowedClass, 28, 6)], - ); +// ^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'double'. +'''); } test_classTypeAlias_FutureOr() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; class A {} class C = A with FutureOr; -''', - [error(diag.mixinOfDisallowedClass, 49, 8)], - ); +// ^^^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr'. +'''); } test_classTypeAlias_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with int; -''', - [error(diag.mixinOfDisallowedClass, 28, 3)], - ); +// ^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'int'. +'''); } test_classTypeAlias_Null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with Null; -''', - [error(diag.mixinOfDisallowedClass, 28, 4)], - ); +// ^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'Null'. +'''); } test_classTypeAlias_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with num; -''', - [error(diag.mixinOfDisallowedClass, 28, 3)], - ); +// ^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'num'. +'''); } test_classTypeAlias_String() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with String; -''', - [error(diag.mixinOfDisallowedClass, 28, 6)], - ); +// ^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'String'. +'''); } test_classTypeAlias_String_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C = A with String, num; -''', - [ - error(diag.mixinOfDisallowedClass, 28, 6), - error(diag.mixinOfDisallowedClass, 36, 3), - ], - ); +// ^^^^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'String'. +// ^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'num'. +'''); } test_enum_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum E with int { +// ^^^ +// [diag.mixinOfDisallowedClass] Classes can't mixin 'int'. v } -''', - [error(diag.mixinOfDisallowedClass, 12, 3)], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -243,6 +223,6 @@ augment enum A with int {} '''); await assertErrorsInFile2(a, []); - await assertErrorsInFile2(b, [error(diag.mixinOfDisallowedClass, 38, 3)]); + await assertErrorsInFile2(b, []); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart index 2cbd1822851..5290fb4e3b0 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart @@ -2,152 +2,142 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinOfNonClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinOfNonClassTest extends PubPackageResolutionTest { test_class_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { ONE } class A extends Object with E {} -''', - [error(diag.mixinOfNonClass, 43, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_class_extensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} class B with A {} -''', - [error(diag.mixinOfNonClass, 41, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_class_topLevelVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int A = 7; class B extends Object with A {} -''', - [error(diag.mixinOfNonClass, 39, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_class_typeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} int B = 7; class C = A with B; -''', - [error(diag.mixinOfNonClass, 39, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_class_undefined() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C with M {} -''', - [error(diag.mixinOfNonClass, 13, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_enum_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E1 { v } enum E2 with E1 { v } -''', - [error(diag.mixinOfNonClass, 27, 2)], - ); +// ^^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_enum_extensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} enum E with A { v } -''', - [error(diag.mixinOfNonClass, 40, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_enum_topLevelVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int A = 7; enum E with A { +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. v } -''', - [error(diag.mixinOfNonClass, 23, 1)], - ); +'''); } test_enum_undefined() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E with M { +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. v } -''', - [error(diag.mixinOfNonClass, 12, 1)], - ); +'''); } test_Never() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A with Never {} -''', - [error(diag.mixinOfNonClass, 13, 5)], - ); +// ^^^^^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_undefined_ignore_import_prefix() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as p; +// ^^^^^^^^ +// [diag.uriDoesNotExist] Target of URI doesn't exist: 'a.dart'. class C with p.M {} -''', - [error(diag.uriDoesNotExist, 7, 8)], - ); +'''); } test_undefined_ignore_import_show_it() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' show M; +// ^^^^^^^^ +// [diag.uriDoesNotExist] Target of URI doesn't exist: 'a.dart'. class C with M {} -''', - [error(diag.uriDoesNotExist, 7, 8)], - ); +'''); } test_undefined_ignore_import_show_other() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' show N; +// ^^^^^^^^ +// [diag.uriDoesNotExist] Target of URI doesn't exist: 'a.dart'. class C with M {} -''', - [error(diag.uriDoesNotExist, 7, 8), error(diag.mixinOfNonClass, 38, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_undefined_ignore_part_exists_uriGenerated_nameIgnorable() async { @@ -155,71 +145,68 @@ class C with M {} part of 'test.dart'; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.g.dart'; class C with _$M {} -''', - [error(diag.mixinOfNonClass, 31, 3)], - ); +// ^^^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_undefined_ignore_part_notExist_uriGenerated_nameIgnorable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.g.dart'; +// ^^^^^^^^^^ +// [diag.uriHasNotBeenGenerated] Target of URI hasn't been generated: 'package:test/a.g.dart'. class C with _$M {} -''', - [error(diag.uriHasNotBeenGenerated, 5, 10)], - ); +'''); } test_undefined_ignore_part_notExist_uriGenerated_nameNotIgnorable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.g.dart'; +// ^^^^^^^^^^ +// [diag.uriHasNotBeenGenerated] Target of URI hasn't been generated: 'package:test/a.g.dart'. class C with M {} -''', - [ - error(diag.uriHasNotBeenGenerated, 5, 10), - error(diag.mixinOfNonClass, 31, 1), - ], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_undefined_ignore_part_notExist_uriNotGenerated_nameIgnorable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.dart'; +// ^^^^^^^^ +// [diag.uriDoesNotExist] Target of URI doesn't exist: 'package:test/a.dart'. class C with _$M {} -''', - [error(diag.uriDoesNotExist, 5, 8), error(diag.mixinOfNonClass, 29, 3)], - ); +// ^^^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_undefined_ignore_part_notExist_uriNotGenerated_nameNotIgnorable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.dart'; +// ^^^^^^^^ +// [diag.uriDoesNotExist] Target of URI doesn't exist: 'package:test/a.dart'. class C with M {} -''', - [error(diag.uriDoesNotExist, 5, 8), error(diag.mixinOfNonClass, 29, 1)], - ); +// ^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } test_undefined_import_exists_prefixed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as p; class C with p.M {} -''', - [error(diag.mixinOfNonClass, 39, 3)], - ); +// ^^^ +// [diag.mixinOfNonClass] Classes can only mix in mixins and classes. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_of_type_alias_expands_to_type_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_of_type_alias_expands_to_type_parameter_test.dart index 1b2ca5c9db6..4d3086ce8e7 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_of_type_alias_expands_to_type_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_of_type_alias_expands_to_type_parameter_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinOfTypeAliasExpandsToTypeParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +18,7 @@ main() { class MixinOfTypeAliasExpandsToTypeParameterTest extends PubPackageResolutionTest { test_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} typedef T = A; class B with A {} @@ -25,24 +26,22 @@ class B with A {} } test_class_noTypeArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} typedef T = X; class B with T {} -''', - [error(diag.mixinOfTypeAliasExpandsToTypeParameter, 52, 1)], - ); +// ^ +// [diag.mixinOfTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be mixed in. +'''); } test_class_withTypeArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} typedef T = X; class B with T {} -''', - [error(diag.mixinOfTypeAliasExpandsToTypeParameter, 52, 1)], - ); +// ^ +// [diag.mixinOfTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be mixed in. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart index 6f1c03d6be3..0f2fde67f6c 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart @@ -2,15 +2,16 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:analyzer_testing/package_config_file_builder.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; void main() { defineReflectiveSuite(() { defineReflectiveTests(MixinOnSealedClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -34,17 +35,15 @@ import 'package:meta/meta.dart'; @sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:foo/foo.dart'; mixin Bar on Foo {} -''', - [error(diag.mixinOnSealedClass, 31, 19)], - ); +// [diag.mixinOnSealedClass][column 1][length 19] The class 'Foo' shouldn't be used as a mixin constraint because it is sealed, and any class mixing in this mixin must have 'Foo' as a superclass. +'''); } test_withinLibrary_OK() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @sealed class Foo {} mixin Bar on Foo {} diff --git a/pkg/analyzer/test/src/diagnostics/mixin_on_type_alias_expands_to_type_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_on_type_alias_expands_to_type_parameter_test.dart index caa853aa87d..fcbf56aa64e 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_on_type_alias_expands_to_type_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_on_type_alias_expands_to_type_parameter_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinOnTypeAliasExpandsToTypeParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +18,7 @@ main() { class MixinOnTypeAliasExpandsToTypeParameterTest extends PubPackageResolutionTest { test_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} typedef T = A; mixin M on A {} @@ -25,24 +26,22 @@ mixin M on A {} } test_class_noTypeArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} typedef T = X; mixin M on T {} -''', - [error(diag.mixinOnTypeAliasExpandsToTypeParameter, 50, 1)], - ); +// ^ +// [diag.mixinOnTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be used as a superclass constraint. +'''); } test_class_withTypeArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} typedef T = X; mixin M on T {} -''', - [error(diag.mixinOnTypeAliasExpandsToTypeParameter, 50, 1)], - ); +// ^ +// [diag.mixinOnTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be used as a superclass constraint. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_base_is_not_base_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_base_is_not_base_test.dart index 26bae641977..511bbef38ba 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_base_is_not_base_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_base_is_not_base_test.dart @@ -2,100 +2,56 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; -import 'package:analyzer_testing/analysis_rule/analysis_rule.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinSubtypeOfBaseIsNotBaseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinSubtypeOfBaseIsNotBaseTest extends PubPackageResolutionTest { test_class_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' base class A {} mixin B implements A {} -''', - [ - this.error( - diag.mixinSubtypeOfBaseIsNotBase, - 22, - 1, - text: - "The mixin 'B' must be 'base' because the supertype 'A' is 'base'.", - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfBaseIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'base'. +'''); } test_class_implements_indirect() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' base class A {} +// ^ +// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here. sealed class B implements A {} mixin C implements B {} -''', - [ - this.error( - diag.mixinSubtypeOfBaseIsNotBase, - 53, - 1, - text: - "The mixin 'C' must be 'base' because the supertype 'A' is 'base'.", - contextMessages: [ - contextMessage( - testFile, - 11, - 1, - textContains: [ - "The type 'B' is a subtype of 'A', and 'A' is defined here.", - ], - ), - ], - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfBaseIsNotBase][context 1] The mixin 'C' must be 'base' because the supertype 'A' is 'base'. +'''); } test_class_on() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' base class A {} mixin B on A {} -''', - [ - this.error( - diag.mixinSubtypeOfBaseIsNotBase, - 22, - 1, - text: - "The mixin 'B' must be 'base' because the supertype 'A' is 'base'.", - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfBaseIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'base'. +'''); } test_mixin_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' base mixin A {} mixin B implements A {} -''', - [ - this.error( - diag.mixinSubtypeOfBaseIsNotBase, - 22, - 1, - text: - "The mixin 'B' must be 'base' because the supertype 'A' is 'base'.", - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfBaseIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'base'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_final_is_not_base_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_final_is_not_base_test.dart index d3702744a5e..b37b5669d26 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_final_is_not_base_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_subtype_of_final_is_not_base_test.dart @@ -2,82 +2,47 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; -import 'package:analyzer_testing/analysis_rule/analysis_rule.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinSubtypeOfFinalIsNotBaseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinSubtypeOfFinalIsNotBaseTest extends PubPackageResolutionTest { test_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final class A {} mixin B implements A {} -''', - [ - this.error( - diag.mixinSubtypeOfFinalIsNotBase, - 23, - 1, - text: - "The mixin 'B' must be 'base' because the supertype 'A' is 'final'.", - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfFinalIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'final'. +'''); } test_implements_indirect() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final class A {} +// ^ +// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here. sealed class B implements A {} mixin C implements B {} -''', - [ - this.error( - diag.mixinSubtypeOfFinalIsNotBase, - 54, - 1, - text: - "The mixin 'C' must be 'base' because the supertype 'A' is 'final'.", - contextMessages: [ - contextMessage( - testFile, - 12, - 1, - textContains: [ - "The type 'B' is a subtype of 'A', and 'A' is defined here.", - ], - ), - ], - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfFinalIsNotBase][context 1] The mixin 'C' must be 'base' because the supertype 'A' is 'final'. +'''); } test_on() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final class A {} mixin B on A {} -''', - [ - this.error( - diag.mixinSubtypeOfFinalIsNotBase, - 23, - 1, - text: - "The mixin 'B' must be 'base' because the supertype 'A' is 'final'.", - ), - ], - ); +// ^ +// [diag.mixinSubtypeOfFinalIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'final'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_deferred_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_deferred_class_test.dart index e0249f918f1..7c6b0113781 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_deferred_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_deferred_class_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinSuperClassConstraintDeferredClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,13 +18,12 @@ main() { class MixinSuperClassConstraintDeferredClassTest extends PubPackageResolutionTest { test_error_onClause_deferredClass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' deferred as math; mixin M on math.Random {} -''', - [error(diag.mixinSuperClassConstraintDeferredClass, 48, 11)], - ); +// ^^^^^^^^^^^ +// [diag.mixinSuperClassConstraintDeferredClass] Deferred classes can't be used as superclass constraints. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_disallowed_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_disallowed_class_test.dart index ecb97c47f5a..38f090e6395 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_disallowed_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_disallowed_class_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinSuperClassConstraintDisallowedClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,19 +18,18 @@ main() { class MixinSuperClassConstraintDisallowedClassTest extends PubPackageResolutionTest { test_dartCoreEnum() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M on Enum {} '''); } test_dartCoreEnum_language216() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.16 mixin M on Enum {} -''', - [error(diag.mixinSuperClassConstraintDisallowedClass, 27, 4)], - ); +// ^^^^ +// [diag.mixinSuperClassConstraintDisallowedClass] 'Enum' can't be used as a superclass constraint. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' @@ -56,18 +56,15 @@ augment mixin A on int {} '''); await assertErrorsInFile2(a, []); - await assertErrorsInFile2(b, [ - error(diag.mixinSuperClassConstraintDisallowedClass, 37, 3), - ]); + await assertErrorsInFile2(b, []); } test_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M on int {} -''', - [error(diag.mixinSuperClassConstraintDisallowedClass, 11, 3)], - ); +// ^^^ +// [diag.mixinSuperClassConstraintDisallowedClass] 'int' can't be used as a superclass constraint. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart index e55736c2a54..14dd59bf134 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinSuperClassConstraintNonInterfaceTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,12 +18,11 @@ main() { class MixinSuperClassConstraintNonInterfaceTest extends PubPackageResolutionTest { test_dynamic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M on dynamic {} -''', - [error(diag.mixinSuperClassConstraintNonInterface, 11, 7)], - ); +// ^^^^^^^ +// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' @@ -37,13 +37,12 @@ MixinOnClause } test_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v } mixin M on E {} -''', - [error(diag.mixinSuperClassConstraintNonInterface, 24, 1)], - ); +// ^ +// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' @@ -58,13 +57,12 @@ MixinOnClause } test_extensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} mixin M on A {} -''', - [error(diag.mixinSuperClassConstraintNonInterface, 39, 1)], - ); +// ^ +// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' @@ -79,12 +77,11 @@ MixinOnClause } test_Never() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin M on Never {} -''', - [error(diag.mixinSuperClassConstraintNonInterface, 11, 5)], - ); +// ^^^^^ +// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' @@ -99,15 +96,12 @@ MixinOnClause } test_void() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M on void {} -''', - [ - error(diag.expectedTypeName, 11, 4), - error(diag.mixinSuperClassConstraintNonInterface, 11, 4), - ], - ); +// ^^^^ +// [diag.expectedTypeName] Expected a type name. +// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints. +'''); var node = findNode.singleMixinOnClause; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/mixin_with_non_class_superclass_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_with_non_class_superclass_test.dart index 12b28e90610..089b150fc6f 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_with_non_class_superclass_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_with_non_class_superclass_test.dart @@ -2,38 +2,37 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinWithNonClassSuperclassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinWithNonClassSuperclassTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int A = 0; mixin B {} class C extends A with B {} -''', - [error(diag.mixinWithNonClassSuperclass, 38, 1)], - ); +// ^ +// [diag.mixinWithNonClassSuperclass] Mixin can only be applied to class. +'''); } test_mixinApplication() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int A = 0; mixin B {} class C = A with B; -''', - [error(diag.mixinWithNonClassSuperclass, 32, 1)], - ); +// ^ +// [diag.mixinWithNonClassSuperclass] Mixin can only be applied to class. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/mixins_super_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixins_super_class_test.dart index 1f95fd5527d..866efbb387f 100644 --- a/pkg/analyzer/test/src/diagnostics/mixins_super_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixins_super_class_test.dart @@ -2,58 +2,55 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinsSuperClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MixinsSuperClassTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} class B extends A with A {} -''', - [error(diag.mixinsSuperClass, 40, 1)], - ); +// ^ +// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses. +'''); } test_class_viaTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} typedef B = A; class C extends A with B {} -''', - [error(diag.mixinsSuperClass, 55, 1)], - ); +// ^ +// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses. +'''); } test_classAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} class B = A with A; -''', - [error(diag.mixinsSuperClass, 34, 1)], - ); +// ^ +// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses. +'''); } test_classAlias_viaTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class A {} typedef B = A; class C = A with B; -''', - [error(diag.mixinsSuperClass, 49, 1)], - ); +// ^ +// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/multiple_combinators_test.dart b/pkg/analyzer/test/src/diagnostics/multiple_combinators_test.dart index cea1c970203..9e245f5a386 100644 --- a/pkg/analyzer/test/src/diagnostics/multiple_combinators_test.dart +++ b/pkg/analyzer/test/src/diagnostics/multiple_combinators_test.dart @@ -2,145 +2,137 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MultipleCombinatorsExportTest); defineReflectiveTests(MultipleCombinatorsImportTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MultipleCombinatorsExportTest extends PubPackageResolutionTest { Future test_hide() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async' hide Future, Stream; '''); } Future test_hide_hide() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async' hide Future, Stream hide Stream; -''', - [error(diag.multipleCombinators, 20, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_hide_show() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async' hide Future, Stream show Stream; -''', - [error(diag.multipleCombinators, 20, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_no_combinators() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async'; '''); } Future test_show() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async' show Future, Stream; '''); } Future test_show_hide() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async' show Future, Stream hide Stream; -''', - [error(diag.multipleCombinators, 20, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_show_show() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' export 'dart:async' show Future, Stream show Stream; -''', - [error(diag.multipleCombinators, 20, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } } @reflectiveTest class MultipleCombinatorsImportTest extends PubPackageResolutionTest { Future test_hide() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' hide Future, Stream; '''); } Future test_hide_hide() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' hide Future, Stream hide Stream; -''', - [error(diag.multipleCombinators, 44, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_hide_show() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' hide Future, Stream show Stream; -''', - [error(diag.multipleCombinators, 44, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_no_combinators() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async'; '''); } Future test_prefixed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' as async hide Future, Stream show Stream; -''', - [error(diag.multipleCombinators, 53, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_show() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' show Future, Stream; '''); } Future test_show_hide() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' show Future, Stream hide Stream; -''', - [error(diag.multipleCombinators, 44, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } Future test_show_show() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' //ignore: unused_import import 'dart:async' show Future, Stream show Stream; -''', - [error(diag.multipleCombinators, 44, 31)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/multiple_redirecting_constructor_invocations_test.dart b/pkg/analyzer/test/src/diagnostics/multiple_redirecting_constructor_invocations_test.dart index db9857a0346..f6b7da89aed 100644 --- a/pkg/analyzer/test/src/diagnostics/multiple_redirecting_constructor_invocations_test.dart +++ b/pkg/analyzer/test/src/diagnostics/multiple_redirecting_constructor_invocations_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MultipleRedirectingConstructorInvocationsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,66 +18,62 @@ main() { class MultipleRedirectingConstructorInvocationsTest extends PubPackageResolutionTest { test_class_primary() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B() extends A { B.foo() : this(); B.bar() : this(); this : this.foo(), this.bar(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [ - error(diag.primaryConstructorCannotRedirect, 83, 4), - error(diag.primaryConstructorCannotRedirect, 95, 4), - ], - ); +'''); } test_class_typeName_twoNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() : this.foo(), this.bar(); +// ^^^^^^^^^^ +// [diag.multipleRedirectingConstructorInvocations] Constructors can have only one 'this' redirection, at most. A.foo() {} A.bar() {} } -''', - [error(diag.multipleRedirectingConstructorInvocations, 30, 10)], - ); +'''); } test_enum_primary() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E() { v; const E.foo() : this(); +// ^^^^^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. const E.bar() : this(); +// ^^^^^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. this : this.foo(), this.bar(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [ - error(diag.recursiveConstantConstructor, 24, 5), - error(diag.recursiveConstantConstructor, 50, 5), - error(diag.primaryConstructorCannotRedirect, 77, 4), - error(diag.primaryConstructorCannotRedirect, 89, 4), - ], - ); +'''); } test_enum_typeName_twoNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; const E() : this.foo(), this.bar(); +// ^^^^^^^^^^ +// [diag.multipleRedirectingConstructorInvocations] Constructors can have only one 'this' redirection, at most. const E.foo(); const E.bar(); } -''', - [error(diag.multipleRedirectingConstructorInvocations, 40, 10)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart b/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart index 51a36e593a4..0b52b663d8d 100644 --- a/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart +++ b/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart @@ -2,33 +2,33 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MultipleSuperInitializersTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MultipleSuperInitializersTest extends PubPackageResolutionTest { test_primary_twoSuperInitializers() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} class B() extends A { this : super(), super(); +// ^^^^^ +// [diag.multipleSuperInitializers] A constructor can have at most one 'super' initializer. } -''', - [error(diag.multipleSuperInitializers, 51, 5)], - ); +'''); } test_typeName_oneSuperInitializer() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B extends A { B() : super() {} @@ -37,14 +37,13 @@ class B extends A { } test_typeName_twoSuperInitializers() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} class B extends A { B() : super(), super() {} +// ^^^^^^^ +// [diag.multipleSuperInitializers] A constructor can have at most one 'super' initializer. } -''', - [error(diag.multipleSuperInitializers, 48, 7)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/must_be_a_native_function_type_test.dart b/pkg/analyzer/test/src/diagnostics/must_be_a_native_function_type_test.dart index 5b5213cd2ab..eae967376dd 100644 --- a/pkg/analyzer/test/src/diagnostics/must_be_a_native_function_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/must_be_a_native_function_type_test.dart @@ -2,64 +2,49 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MustBeANativeFunctionTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MustBeANativeFunctionTypeTest extends PubPackageResolutionTest { test_fromFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; int f(int i) => i * 2; class C { void g() { Pointer.fromFunction(f); +// ^ +// [diag.mustBeANativeFunctionType] The type 'T' given to 'fromFunction' must be a valid 'dart:ffi' native function type. } } -''', - [ - error( - diag.mustBeANativeFunctionType, - 110, - 1, - messageContains: ["The type 'T' given to 'fromFunction' must be"], - ), - ], - ); +'''); } test_lookupFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef S = int Function(int); typedef F = String Function(String); void f(DynamicLibrary lib) { lib.lookupFunction('g'); +// ^ +// [diag.mustBeANativeFunctionType] The type 'S' given to 'lookupFunction' must be a valid 'dart:ffi' native function type. } -''', - [ - error( - diag.mustBeANativeFunctionType, - 137, - 1, - messageContains: ["The type 'S' given to 'lookupFunction' must be"], - ), - ], - ); +'''); } test_lookupFunction_Pointer() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef S = Void Function(Pointer); typedef F = void Function(Pointer); @@ -72,21 +57,20 @@ void f(DynamicLibrary lib) { // TODO(dacoharkes): Should this be an error or not? // https://dartbug.com/44594 test_lookupFunction_PointerNativeFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef S = Void Function(Pointer); typedef F = void Function(Pointer); void f(DynamicLibrary lib) { lib.lookupFunction('g'); +// ^ +// [diag.mustBeANativeFunctionType] The type 'S' given to 'lookupFunction' must be a valid 'dart:ffi' native function type. } -''', - [error(diag.mustBeANativeFunctionType, 173, 1)], - ); +'''); } test_lookupFunction_PointerNativeFunction2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef S = Void Function(Pointer>); typedef F = void Function(Pointer>); @@ -97,7 +81,7 @@ void f(DynamicLibrary lib) { } test_lookupFunction_PointerVoid() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef S = Pointer Function(Pointer); typedef F = Pointer Function(Pointer); @@ -108,22 +92,21 @@ void f(DynamicLibrary lib) { } test_lookupFunction_T() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef F = int Function(int); class C { void f(DynamicLibrary lib, NativeFunction x) { lib.lookupFunction('g'); +// ^ +// [diag.mustBeANativeFunctionType] The type 'T' given to 'lookupFunction' must be a valid 'dart:ffi' native function type. } } -''', - [error(diag.mustBeANativeFunctionType, 152, 1)], - ); +'''); } test_lookupFunction_VarArgs1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final lib = DynamicLibrary.open('dontcare'); final variadicAt1Doublex2 = @@ -137,7 +120,7 @@ final variadicAt1Doublex2 = } test_lookupFunction_VarArgs2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final lib = DynamicLibrary.open('dontcare'); final variadicAt1Int64x5Leaf = @@ -152,56 +135,53 @@ final variadicAt1Int64x5Leaf = } test_lookupFunction_VarArgs3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final lib = DynamicLibrary.open('dontcare'); final variadicAt1Int64x5Leaf = lib.lookupFunction< Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, Int64)>), int Function(int, int, int, int, double) +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.mustBeASubtype] The type 'Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, Int64)>)' must be a subtype of 'int Function(int, int, int, int, double)' for 'lookupFunction'. >( "VariadicAt1Int64x5", isLeaf:true ); -''', - [error(diag.mustBeASubtype, 187, 40)], - ); +'''); } test_lookupFunction_VarArgs4() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final lib = DynamicLibrary.open('dontcare'); final variadicAt1Int64x5Leaf = lib.lookupFunction< Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, {Int64 named})>), +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.mustBeANativeFunctionType] The type 'Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, {Int64 named})>)' given to 'lookupFunction' must be a valid 'dart:ffi' native function type. int Function(int, int, int, int) >( "VariadicAt1Int64x5", isLeaf:true ); -''', - [error(diag.mustBeANativeFunctionType, 121, 68)], - ); +'''); } test_lookupFunction_VarArgs5() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final lib = DynamicLibrary.open('dontcare'); final variadicAt1Int64x5Leaf = lib.lookupFunction< Int64 Function(Int64, VarArgs<(Int64, Int64, Int64)>, Int64), +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.mustBeANativeFunctionType] The type 'Int64 Function(Int64, VarArgs<(Int64, Int64, Int64)>, Int64)' given to 'lookupFunction' must be a valid 'dart:ffi' native function type. int Function(int, int, int, int, int) >( "VariadicAt1Int64x5", isLeaf:true ); -''', - [error(diag.mustBeANativeFunctionType, 121, 60)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/must_be_a_subtype_test.dart b/pkg/analyzer/test/src/diagnostics/must_be_a_subtype_test.dart index 8083afb48db..c5e01de1ecd 100644 --- a/pkg/analyzer/test/src/diagnostics/must_be_a_subtype_test.dart +++ b/pkg/analyzer/test/src/diagnostics/must_be_a_subtype_test.dart @@ -2,49 +2,48 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MustBeASubtypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class MustBeASubtypeTest extends PubPackageResolutionTest { test_fromFunction_firstArgument() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Int8 Function(Int8); String f(int i) => i.toString(); void g() { Pointer.fromFunction(f, 5); +// ^ +// [diag.mustBeASubtype] The type 'String Function(int)' must be a subtype of 'T' for 'fromFunction'. } -''', - [error(diag.mustBeASubtype, 122, 1)], - ); +'''); } test_fromFunction_secondArgument() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Int8 Function(Int8); int f(int i) => i * 2; void g() { Pointer.fromFunction(f, ''); +// ^^ +// [diag.mustBeASubtype] The type 'String' must be a subtype of 'Int8' for 'fromFunction'. } -''', - [error(diag.mustBeASubtype, 115, 2)], - ); +'''); } test_fromFunction_valid_oneArgument() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Void Function(Int8); void f(int i) {} @@ -55,7 +54,7 @@ void g() { } test_fromFunction_valid_twoArguments() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Int8 Function(Int8); int f(int i) => i * 2; @@ -66,7 +65,7 @@ void g() { } test_fromFunction_valid_voidReturnPermissive() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Void Function(Int8); int f(int i) => i * 2; @@ -77,17 +76,16 @@ void g() { } test_lookupFunction_F() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = Int8 Function(Int8); class C { void f(DynamicLibrary lib, NativeFunction x) { lib.lookupFunction('g'); +// ^ +// [diag.mustBeASubtype] The type 'T' must be a subtype of 'F' for 'lookupFunction'. } } -''', - [error(diag.mustBeASubtype, 166, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/must_be_immutable_test.dart b/pkg/analyzer/test/src/diagnostics/must_be_immutable_test.dart index 6c53a08d3a3..99d633df54d 100644 --- a/pkg/analyzer/test/src/diagnostics/must_be_immutable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/must_be_immutable_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MustBeImmutableTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,58 +23,54 @@ class MustBeImmutableTest extends PubPackageResolutionTest { } test_directAnnotation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A { +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x int x = 0; } -''', - [error(diag.mustBeImmutable, 50, 1)], - ); +'''); } test_directAnnotation_declaredInPrimaryConstructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A(var int x); -''', - [error(diag.mustBeImmutable, 50, 1)], - ); +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x +'''); } test_directMixinAnnotation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable mixin A { +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x int x = 0; } -''', - [error(diag.mustBeImmutable, 50, 1)], - ); +'''); } test_extendsClassWithAnnotation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A {} class B extends A { +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: B.x int x = 0; } -''', - [error(diag.mustBeImmutable, 61, 1)], - ); +'''); } test_finalField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A { @@ -83,8 +80,7 @@ class A { } test_fromMixinWithAnnotation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A {} @@ -92,14 +88,13 @@ mixin B { int x = 0; } class C extends A with B {} -''', - [error(diag.mustBeImmutable, 86, 1)], - ); +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: B.x +'''); } test_mixinApplication() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A {} @@ -107,14 +102,13 @@ mixin B { int x = 0; } class C = A with B; -''', - [error(diag.mustBeImmutable, 86, 1)], - ); +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: B.x +'''); } test_mixinApplicationBase() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { int x = 0; @@ -122,13 +116,13 @@ class A { mixin B {} @immutable class C = A with B; -''', - [error(diag.mustBeImmutable, 86, 1)], - ); +// ^ +// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x +'''); } test_staticField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @immutable class A { diff --git a/pkg/analyzer/test/src/diagnostics/must_call_super_test.dart b/pkg/analyzer/test/src/diagnostics/must_call_super_test.dart index e99253f1fc6..505979a73db 100644 --- a/pkg/analyzer/test/src/diagnostics/must_call_super_test.dart +++ b/pkg/analyzer/test/src/diagnostics/must_call_super_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MustCallSuperTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,7 +23,7 @@ class MustCallSuperTest extends PubPackageResolutionTest { } test_containsSuperCall() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -38,8 +39,7 @@ class C extends A { } test_fromExtendingClass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -48,14 +48,14 @@ class A { class B extends A { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 115, 1)], - ); +'''); } test_fromExtendingClass_abstractInSubclass() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; abstract class A { @mustCallSuper @@ -69,7 +69,7 @@ class B extends A { } test_fromExtendingClass_abstractInSuperclass() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; abstract class A { @mustCallSuper @@ -83,8 +83,7 @@ class B extends A { } test_fromExtendingClass_genericClass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -93,15 +92,14 @@ class A { class B extends A { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 123, 1)], - ); +'''); } test_fromExtendingClass_genericMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -110,15 +108,14 @@ class A { class B extends A { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 118, 1)], - ); +'''); } test_fromExtendingClass_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -127,14 +124,14 @@ class A { class B extends A { @override int get a => 2; +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 122, 1)], - ); +'''); } test_fromExtendingClass_getter_containsSuperCall() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -151,8 +148,7 @@ class B extends A { } test_fromExtendingClass_getter_invokesSuper_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -164,18 +160,17 @@ class A { class B extends A { int get foo { +// ^^^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. super.foo = 0; return 0; } } -''', - [error(diag.mustCallSuper, 135, 3)], - ); +'''); } test_fromExtendingClass_operator() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -184,14 +179,14 @@ class A { class B extends A { @override operator ==(Object o) => o is B; +// ^^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 140, 2)], - ); +'''); } test_fromExtendingClass_operator_containsSuperCall() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -205,8 +200,7 @@ class B extends A { } test_fromExtendingClass_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -215,14 +209,14 @@ class A { class B extends A { @override set a(int value) {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 122, 1)], - ); +'''); } test_fromExtendingClass_setter_containsSuperCall() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -238,8 +232,7 @@ class B extends A { } test_fromExtendingClass_setter_invokesSuper_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -251,16 +244,16 @@ class A { class B extends A { set foo(int _) { +// ^^^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. super.foo; } } -''', - [error(diag.mustCallSuper, 131, 3)], - ); +'''); } test_fromInterface() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -274,8 +267,7 @@ class C implements A { } test_fromMixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; mixin Mixin { @mustCallSuper @@ -284,15 +276,14 @@ mixin Mixin { class C with Mixin { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'Mixin', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 120, 1)], - ); +'''); } test_fromMixin_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; mixin Mixin { @mustCallSuper @@ -301,15 +292,14 @@ mixin Mixin { class C with Mixin { @override void set a(int value) {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'Mixin', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 137, 1)], - ); +'''); } test_fromMixin_throughExtendingClass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; mixin M { @mustCallSuper @@ -319,15 +309,14 @@ class C with M {} class D extends C { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'M', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 133, 1)], - ); +'''); } test_indirectlyInherited() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -342,15 +331,14 @@ class C extends A { class D extends C { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 181, 1)], - ); +'''); } test_indirectlyInheritedFromMixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; mixin Mixin { @mustCallSuper @@ -360,15 +348,14 @@ class C extends Object with Mixin {} class D extends C { @override void b() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'Mixin', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 156, 1)], - ); +'''); } test_indirectlyInheritedFromMixinConstraint() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -377,15 +364,15 @@ class A { mixin C on A { @override void a() {} +// ^ +// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method. } -''', - [error(diag.mustCallSuper, 110, 1)], - ); +'''); } test_overriddenWithFuture() async { // https://github.com/flutter/flutter/issues/11646 - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper @@ -405,7 +392,7 @@ class C extends A { test_overriddenWithFuture2() async { // https://github.com/flutter/flutter/issues/11646 - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @mustCallSuper diff --git a/pkg/analyzer/test/src/diagnostics/native_clause_in_non_sdk_code_test.dart b/pkg/analyzer/test/src/diagnostics/native_clause_in_non_sdk_code_test.dart index 79258027d55..8fb5baf1306 100644 --- a/pkg/analyzer/test/src/diagnostics/native_clause_in_non_sdk_code_test.dart +++ b/pkg/analyzer/test/src/diagnostics/native_clause_in_non_sdk_code_test.dart @@ -2,25 +2,25 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NativeClauseInNonSdkCodeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NativeClauseInNonSdkCodeTest extends PubPackageResolutionTest { test_nativeClauseInNonSDKCode() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A native 'string' {} -''', - [error(diag.nativeClauseInNonSdkCode, 8, 15)], - ); +// ^^^^^^^^^^^^^^^ +// [diag.nativeClauseInNonSdkCode] Native clause can only be used in the SDK and code that is loaded through native extensions. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/native_function_body_in_non_sdk_code_test.dart b/pkg/analyzer/test/src/diagnostics/native_function_body_in_non_sdk_code_test.dart index d77e2fe2f6a..1dd5b81e8a4 100644 --- a/pkg/analyzer/test/src/diagnostics/native_function_body_in_non_sdk_code_test.dart +++ b/pkg/analyzer/test/src/diagnostics/native_function_body_in_non_sdk_code_test.dart @@ -2,47 +2,45 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NativeFunctionBodyInNonSdkCodeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NativeFunctionBodyInNonSdkCodeTest extends PubPackageResolutionTest { test_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int m(a) native 'string'; -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 9, 16)], - ); +// ^^^^^^^^^^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. +'''); } test_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int m(a) native 'string'; +// ^^^^^^^^^^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 28, 16)], - ); +'''); } test_mixinMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A { static int m(a) native 'string'; +// ^^^^^^^^^^^^^^^^ +// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions. } -''', - [error(diag.nativeFunctionBodyInNonSdkCode, 28, 16)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/new_with_non_type_test.dart b/pkg/analyzer/test/src/diagnostics/new_with_non_type_test.dart index f8044467fef..2dcb34ffd2d 100644 --- a/pkg/analyzer/test/src/diagnostics/new_with_non_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/new_with_non_type_test.dart @@ -2,30 +2,30 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NewWithNonTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NewWithNonTypeTest extends PubPackageResolutionTest { test_functionTypeAlias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' typedef F = void Function(); void foo() { new F(); +// ^ +// [diag.newWithNonType] The name 'F' isn't a class. } -''', - [error(diag.newWithNonType, 49, 1)], - ); +'''); var node = findNode.namedType('F()'); assertResolvedNodeText(node, r''' @@ -40,28 +40,26 @@ NamedType newFile('$testPackageLibPath/lib.dart', ''' class B {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'lib.dart' as lib; void f() { new lib.A(); +// ^ +// [diag.newWithNonType] The name 'A' isn't a class. } lib.B b = lib.B(); -''', - [error(diag.newWithNonType, 47, 1)], - ); +'''); } test_local() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var A = 0; void f() { new A(); +// ^ +// [diag.newWithNonType] The name 'A' isn't a class. } -''', - [error(diag.newWithNonType, 28, 1)], - ); +'''); var node = findNode.namedType('A()'); assertResolvedNodeText(node, r''' @@ -73,15 +71,14 @@ NamedType } test_local_withTypeArguments() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var A = 0; void f() { new A(); +// ^ +// [diag.newWithNonType] The name 'A' isn't a class. } -''', - [error(diag.newWithNonType, 28, 1)], - ); +'''); var node = findNode.namedType('A()'); assertResolvedNodeText(node, r''' @@ -101,27 +98,25 @@ NamedType } test_malformed_constructor_call() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { C.x(); } main() { new C.x.y(); +// ^^^ +// [diag.newWithNonType] The name 'x' isn't a class. } -''', - [error(diag.newWithNonType, 36, 3)], - ); +'''); } test_typeParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void foo() { new T(); +// ^ +// [diag.newWithNonType] The name 'T' isn't a class. } -''', - [error(diag.newWithNonType, 22, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/new_with_undefined_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/new_with_undefined_constructor_test.dart index 7a33b975b9c..514f9be2fb6 100644 --- a/pkg/analyzer/test/src/diagnostics/new_with_undefined_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/new_with_undefined_constructor_test.dart @@ -2,10 +2,10 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { @@ -13,6 +13,7 @@ main() { defineReflectiveTests( NewWithUndefinedConstructorWithoutConstructorTearoffsTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,38 +23,29 @@ class NewWithUndefinedConstructorTest extends PubPackageResolutionTest mixin NewWithUndefinedConstructorTestCases on PubPackageResolutionTest { test_default() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A.name() {} } f() { new A(); +// ^ +// [diag.newWithUndefinedConstructorDefault] The class 'A' doesn't have an unnamed constructor. } -''', - [ - error( - diag.newWithUndefinedConstructorDefault, - 38, - 1, - messageContains: ["'A'"], - ), - ], - ); +'''); } test_default_noKeyword() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A.name() {} } f() { A(); +//^ +// [diag.newWithUndefinedConstructorDefault] The class 'A' doesn't have an unnamed constructor. } -''', - [error(diag.newWithUndefinedConstructorDefault, 34, 1)], - ); +'''); } test_default_prefixed() async { @@ -62,41 +54,32 @@ class A { A.name() {} } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'lib1.dart' as lib1; f() { new lib1.A(); +// ^^^^^^ +// [diag.newWithUndefinedConstructorDefault] The class 'lib1.A' doesn't have an unnamed constructor. } -''', - [ - error( - diag.newWithUndefinedConstructorDefault, - 41, - 6, - messageContains: ["'lib1.A'"], - ), - ], - ); +'''); } test_default_unnamedViaNew() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A.name() {} } f() { A.new(); +// ^^^ +// [diag.newWithUndefinedConstructorDefault] The class 'A' doesn't have an unnamed constructor. } -''', - [error(diag.newWithUndefinedConstructorDefault, 36, 3)], - ); +'''); } test_defaultViaNew() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { A.new() {} } @@ -107,7 +90,7 @@ f() { } test_defined_named() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.name() {} } @@ -118,7 +101,7 @@ f() { } test_defined_unnamed() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() {} } @@ -129,24 +112,16 @@ f() { } test_named() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A() {} } f() { new A.name(); +// ^^^^ +// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named 'name'. } -''', - [ - error( - diag.newWithUndefinedConstructor, - 35, - 4, - messageContains: ["class 'A'", "named 'name'"], - ), - ], - ); +'''); } test_named_prefixed() async { @@ -155,22 +130,14 @@ class A { A() {} } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'lib1.dart' as lib1; f() { new lib1.A.name(); +// ^^^^ +// [diag.newWithUndefinedConstructor] The class 'lib1.A' doesn't have a constructor named 'name'. } -''', - [ - error( - diag.newWithUndefinedConstructor, - 47, - 4, - messageContains: ["class 'lib1.A'", "named 'name'"], - ), - ], - ); +'''); } test_private_named() async { @@ -179,15 +146,14 @@ class A { A._named() {} } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; void f() { new A._named(); +// ^^^^^^ +// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named '_named'. } -''', - [error(diag.newWithUndefinedConstructor, 36, 6)], - ); +'''); } test_private_named_genericClass_noTypeArguments() async { @@ -196,15 +162,14 @@ class A { A._named() {} } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; void f() { new A._named(); +// ^^^^^^ +// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named '_named'. } -''', - [error(diag.newWithUndefinedConstructor, 36, 6)], - ); +'''); } test_private_named_genericClass_withTypeArguments() async { @@ -213,15 +178,14 @@ class A { A._named() {} } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; void f() { new A._named(); +// ^^^^^^ +// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named '_named'. } -''', - [error(diag.newWithUndefinedConstructor, 41, 6)], - ); +'''); } } @@ -230,30 +194,28 @@ class NewWithUndefinedConstructorWithoutConstructorTearoffsTest extends PubPackageResolutionTest with WithoutConstructorTearoffsMixin { test_defaultViaNew() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A.new() {} +// ^^^ +// [diag.experimentNotEnabled] This requires the 'constructor-tearoffs' language feature to be enabled. } f() { A(); } -''', - [error(diag.experimentNotEnabled, 14, 3)], - ); +'''); } test_unnamedViaNew() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A.named() {} } f() { A.new(); +// ^^^ +// [diag.experimentNotEnabled] This requires the 'constructor-tearoffs' language feature to be enabled. } -''', - [error(diag.experimentNotEnabled, 37, 3)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/no_annotation_constructor_arguments_test.dart b/pkg/analyzer/test/src/diagnostics/no_annotation_constructor_arguments_test.dart index e0f7230d28f..07d2d332b79 100644 --- a/pkg/analyzer/test/src/diagnostics/no_annotation_constructor_arguments_test.dart +++ b/pkg/analyzer/test/src/diagnostics/no_annotation_constructor_arguments_test.dart @@ -2,30 +2,29 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NoAnnotationConstructorArgumentsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NoAnnotationConstructorArgumentsTest extends PubPackageResolutionTest { test_missingArgumentList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(); } @A +// [diag.noAnnotationConstructorArguments][column 1][length 2] Annotation creation must have arguments. main() { } -''', - [error(diag.noAnnotationConstructorArguments, 25, 2)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/no_combined_super_signature_test.dart b/pkg/analyzer/test/src/diagnostics/no_combined_super_signature_test.dart index 095892271a0..394a5587588 100644 --- a/pkg/analyzer/test/src/diagnostics/no_combined_super_signature_test.dart +++ b/pkg/analyzer/test/src/diagnostics/no_combined_super_signature_test.dart @@ -2,22 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NoCombinedSuperSignatureTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NoCombinedSuperSignatureTest extends PubPackageResolutionTest { test_conflictingParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { void foo(int x); } @@ -28,10 +28,10 @@ abstract class B { abstract class C implements A, B { foo(num x); +//^^^ +// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.foo (void Function(int)), B.foo (void Function(double)). } -''', - [error(diag.noCombinedSuperSignature, 122, 3)], - ); +'''); } /// If the method is subject to override inference, it is already an error @@ -40,8 +40,7 @@ abstract class C implements A, B { /// It does not matter that the conflicting component (the return type here) /// was resolved. test_conflictingReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { int foo(int x); } @@ -52,15 +51,14 @@ abstract class B { abstract class C implements A, B { Never foo(x); +// ^^^ +// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.foo (int Function(int)), B.foo (double Function(int)). } -''', - [error(diag.noCombinedSuperSignature, 126, 3)], - ); +'''); } test_noInvalidOverrideErrors() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { String foo(String a); } @@ -71,9 +69,9 @@ abstract class B { abstract class C implements A, B { foo(a); +//^^^ +// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.foo (String Function(String)), B.foo (int Function(int)). } -''', - [error(diag.noCombinedSuperSignature, 123, 3)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_explicit_test.dart b/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_explicit_test.dart index c235a355bff..7f20f5bbcf9 100644 --- a/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_explicit_test.dart +++ b/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_explicit_test.dart @@ -2,46 +2,45 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NoDefaultSuperConstructorExplicitTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NoDefaultSuperConstructorExplicitTest extends PubPackageResolutionTest { test_requiredNamed_constructor_typeName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.16 class A { A({required int a}); } class B extends A { B.foo(); +//^^^^^ +// [diag.noDefaultSuperConstructorExplicit] The superclass 'A' doesn't have a zero argument constructor. } -''', - [error(diag.noDefaultSuperConstructorExplicit, 73, 5)], - ); +'''); } test_requiredPositional_constructor_typeName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.16 class A { A(int a); } class B extends A { B.foo(); +//^^^^^ +// [diag.noDefaultSuperConstructorExplicit] The superclass 'A' doesn't have a zero argument constructor. } -''', - [error(diag.noDefaultSuperConstructorExplicit, 62, 5)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart index 905436ca335..93622cbd5f9 100644 --- a/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NoDefaultSuperConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NoDefaultSuperConstructorTest extends PubPackageResolutionTest { test_super_implicit_subclass_explicit_constructor_newHead() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A { new named(); @@ -25,7 +26,7 @@ class B extends A { } test_super_implicit_subclass_explicit_constructor_typeName() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A { B.named(); @@ -34,7 +35,7 @@ class B extends A { } test_super_implicit_subclass_explicit_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B() extends A { this; @@ -43,21 +44,21 @@ class B() extends A { } test_super_implicit_subclass_explicit_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B() extends A; '''); } test_super_implicit_subclass_implicit() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A {} '''); } test_super_noParameters() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(); } @@ -68,7 +69,7 @@ class B extends A { } test_super_optionalNamed_subclass_explicit_constructor_newHead() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -79,7 +80,7 @@ class B extends A { } test_super_optionalNamed_subclass_explicit_constructor_typeName() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -90,7 +91,7 @@ class B extends A { } test_super_optionalNamed_subclass_explicit_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -101,7 +102,7 @@ class B() extends A { } test_super_optionalNamed_subclass_explicit_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -110,7 +111,7 @@ class B() extends A; } test_super_optionalNamed_subclass_implicit() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -119,7 +120,7 @@ class B extends A {} } test_super_optionalNamed_subclass_superParameter_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -130,7 +131,7 @@ class B extends A { } test_super_optionalNamed_subclass_superParameter_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -141,7 +142,7 @@ class B({super.a}) extends A { } test_super_optionalNamed_subclass_superParameter_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({int? a}); } @@ -150,7 +151,7 @@ class B({super.a}) extends A; } test_super_optionalPositional_subclass_explicit_constructor_newHead() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -161,7 +162,7 @@ class B extends A { } test_super_optionalPositional_subclass_explicit_constructor_typeName() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -172,7 +173,7 @@ class B extends A { } test_super_optionalPositional_subclass_explicit_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -183,7 +184,7 @@ class B() extends A { } test_super_optionalPositional_subclass_explicit_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -192,7 +193,7 @@ class B() extends A; } test_super_optionalPositional_subclass_implicit() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -201,7 +202,7 @@ class B extends A {} } test_super_optionalPositional_subclass_superParameter_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -212,7 +213,7 @@ class B extends A { } test_super_optionalPositional_subclass_superParameter_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -223,7 +224,7 @@ class B([super.a]) extends A { } test_super_optionalPositional_subclass_superParameter_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A([int? a]); } @@ -232,73 +233,68 @@ class B([super.a]) extends A; } test_super_requiredNamed_subclass_explicit_constructor_newHead() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } class B extends A { new named(); +//^^^^^^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 58, 9)], - ); +'''); } test_super_requiredNamed_subclass_explicit_constructor_typeName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } class B extends A { B.named(); +//^^^^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 58, 7)], - ); +'''); } test_super_requiredNamed_subclass_explicit_primaryConstructor_hasBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } class B() extends A { this; +//^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 60, 4)], - ); +'''); } test_super_requiredNamed_subclass_explicit_primaryConstructor_noBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } class B() extends A; -''', - [error(diag.implicitSuperInitializerMissingArguments, 42, 1)], - ); +// ^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. +'''); } test_super_requiredNamed_subclass_implicit() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } class B extends A {} -''', - [error(diag.noDefaultSuperConstructorImplicit, 42, 1)], - ); +// ^ +// [diag.noDefaultSuperConstructorImplicit] The superclass 'A' doesn't have a zero argument constructor. +'''); } test_super_requiredNamed_subclass_superParameter_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -309,47 +305,44 @@ class B extends A { } test_super_requiredNamed_subclass_superParameter_oneLeft_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a, required int? b}); } class B extends A { B({required super.a}); +//^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 75, 1)], - ); +'''); } test_super_requiredNamed_subclass_superParameter_oneLeft_primaryConstructor_hasBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a, required int? b}); } class B({required super.a}) extends A { this; +//^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 95, 4)], - ); +'''); } test_super_requiredNamed_subclass_superParameter_oneLeft_primaryConstructor_noBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a, required int? b}); } class B({required super.a}) extends A; -''', - [error(diag.implicitSuperInitializerMissingArguments, 59, 1)], - ); +// ^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. +'''); } test_super_requiredNamed_subclass_superParameter_optionalNamed_hasDefault_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -360,7 +353,7 @@ class B extends A { } test_super_requiredNamed_subclass_superParameter_optionalNamed_hasDefault_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -371,7 +364,7 @@ class B({super.a = 0}) extends A { } test_super_requiredNamed_subclass_superParameter_optionalNamed_hasDefault_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -380,7 +373,7 @@ class B({super.a = 0}) extends A; } test_super_requiredNamed_subclass_superParameter_optionalNamed_noDefault_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -391,7 +384,7 @@ class B extends A { } test_super_requiredNamed_subclass_superParameter_optionalNamed_noDefault_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -402,7 +395,7 @@ class B({super.a}) extends A { } test_super_requiredNamed_subclass_superParameter_optionalNamed_noDefault_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -411,7 +404,7 @@ class B({super.a}) extends A; } test_super_requiredNamed_subclass_superParameter_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -422,7 +415,7 @@ class B({required super.a}) extends A { } test_super_requiredNamed_subclass_superParameter_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A({required int? a}); } @@ -431,61 +424,57 @@ class B({required super.a}) extends A; } test_super_requiredPositional_subclass_explicit_constructor_newHead() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int p); } class B extends A { new named(); +//^^^^^^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 46, 9)], - ); +'''); } test_super_requiredPositional_subclass_explicit_constructor_typeName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int p); } class B extends A { B.named(); +//^^^^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 46, 7)], - ); +'''); } test_super_requiredPositional_subclass_explicit_primaryConstructor_hasBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int p); } class B() extends A { this; +//^^^^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. } -''', - [error(diag.implicitSuperInitializerMissingArguments, 48, 4)], - ); +'''); } test_super_requiredPositional_subclass_explicit_primaryConstructor_noBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int p); } class B() extends A; -''', - [error(diag.implicitSuperInitializerMissingArguments, 30, 1)], - ); +// ^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. +'''); } test_super_requiredPositional_subclass_external() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int p); } @@ -496,19 +485,18 @@ class B extends A { } test_super_requiredPositional_subclass_implicit() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int p); } class B extends A {} -''', - [error(diag.noDefaultSuperConstructorImplicit, 30, 1)], - ); +// ^ +// [diag.noDefaultSuperConstructorImplicit] The superclass 'A' doesn't have a zero argument constructor. +'''); } test_super_requiredPositional_subclass_superParameter_optionalPositional_withDefault_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -519,7 +507,7 @@ class B extends A { } test_super_requiredPositional_subclass_superParameter_optionalPositional_withDefault_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -530,7 +518,7 @@ class B([super.a = 0]) extends A { } test_super_requiredPositional_subclass_superParameter_optionalPositional_withDefault_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -539,7 +527,7 @@ class B([super.a = 0]) extends A; } test_super_requiredPositional_subclass_superParameter_optionalPositional_withoutDefault_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -550,7 +538,7 @@ class B extends A { } test_super_requiredPositional_subclass_superParameter_optionalPositional_withoutDefault_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -561,7 +549,7 @@ class B([super.a]) extends A { } test_super_requiredPositional_subclass_superParameter_optionalPositional_withoutDefault_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -570,7 +558,7 @@ class B([super.a]) extends A; } test_super_requiredPositional_subclass_superParameter_requiredPositional_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -581,7 +569,7 @@ class B extends A { } test_super_requiredPositional_subclass_superParameter_requiredPositional_primaryConstructor_hasBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -592,7 +580,7 @@ class B(super.a) extends A { } test_super_requiredPositional_subclass_superParameter_requiredPositional_primaryConstructor_noBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } diff --git a/pkg/analyzer/test/src/diagnostics/no_generative_constructors_in_superclass_test.dart b/pkg/analyzer/test/src/diagnostics/no_generative_constructors_in_superclass_test.dart index d8aca4f7793..7f6e401c2cf 100644 --- a/pkg/analyzer/test/src/diagnostics/no_generative_constructors_in_superclass_test.dart +++ b/pkg/analyzer/test/src/diagnostics/no_generative_constructors_in_superclass_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NoGenerativeConstructorsInSuperclassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,36 +18,34 @@ main() { class NoGenerativeConstructorsInSuperclassTest extends PubPackageResolutionTest { test_explicit() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw ''; } class B extends A { +// ^ +// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor. B() : super(); } -''', - [error(diag.noGenerativeConstructorsInSuperclass, 55, 1)], - ); +'''); } test_explicit_oneFactory() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw ''; } class B extends A { +// ^ +// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor. B() : super(); factory B.second() => throw ''; } -''', - [error(diag.noGenerativeConstructorsInSuperclass, 55, 1)], - ); +'''); } test_hasFactories() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw ''; } @@ -58,7 +57,7 @@ class B extends A { } test_hasFactory() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw ''; } @@ -69,29 +68,27 @@ class B extends A { } test_implicit() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw ''; } class B extends A { +// ^ +// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor. B(); } -''', - [error(diag.noGenerativeConstructorsInSuperclass, 55, 1)], - ); +'''); } test_implicit2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw ''; } class B extends A { +// ^ +// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor. } -''', - [error(diag.noGenerativeConstructorsInSuperclass, 55, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart b/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart index 1d99c382164..186503160ae 100644 --- a/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart @@ -6,10 +6,12 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonAbstractClassInheritsAbstractMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +19,7 @@ main() { class NonAbstractClassInheritsAbstractMemberTest extends PubPackageResolutionTest { test_abstract_field_final_implement_getter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { abstract final int x; } @@ -28,40 +30,31 @@ class B implements A { } test_abstract_field_final_implement_none() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { abstract final int x; } class B implements A {} -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberOne, - 51, - 1, - messageContains: ["'getter A.x'"], - ), - ], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'. +'''); } test_abstract_field_implement_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { abstract int x; } class B implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.x'. int get x => 0; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 45, 1)], - ); +'''); } test_abstract_field_implement_getter_and_setter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { abstract int x; } @@ -73,47 +66,31 @@ class B implements A { } test_abstract_field_implement_none() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { abstract int x; } class B implements A {} -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberTwo, - 45, - 1, - messageContains: ["'getter A.x' and 'setter A.x'"], - ), - ], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'getter A.x' and 'setter A.x'. +'''); } test_abstract_field_implement_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { abstract int x; } class B implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'. void set x(int value) {} } -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberOne, - 45, - 1, - messageContains: ["'getter A.x'"], - ), - ], - ); +'''); } test_abstractsDontOverrideConcretes_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get g => 0; } @@ -125,7 +102,7 @@ class C extends B {} } test_abstractsDontOverrideConcretes_method() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { m(p) {} } @@ -137,7 +114,7 @@ class C extends B {} } test_abstractsDontOverrideConcretes_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set s(v) {} } @@ -174,43 +151,40 @@ augment class A with M {} } test_augment_withClause_sameFile_error_nonAbstractClassInheritsAbstractMember() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int foo(); } class A {} +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.foo'. augment class A with M {} -''', - [ - error(diag.nonAbstractClassInheritsAbstractMemberOne, 32, 1), - error(diag.nonAbstractClassInheritsAbstractMemberOne, 52, 1), - ], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.foo'. +'''); } test_class_notAbstract_hasConcreteSubtype_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { void foo(); } class B extends A {} +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.foo'. class C extends B {} class D extends C {} -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 42, 1)], - ); +'''); } test_classTypeAlias_interface() async { // issue 15979 - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 abstract class M {} abstract class A {} @@ -223,7 +197,7 @@ abstract class B = A with M implements I; test_classTypeAlias_mixin() async { // issue 15979 - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 abstract class M { m(); @@ -235,7 +209,7 @@ abstract class B = A with M; test_classTypeAlias_superclass() async { // issue 15979 - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 class M {} abstract class A { @@ -246,97 +220,91 @@ abstract class B = A with M; } test_enum_getter_fromInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { int get foo => 0; } enum E implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.foo'. v; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 38, 1)], - ); +'''); } test_enum_getter_fromMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin M { int get foo; } enum E with M { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter M.foo'. v; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 33, 1)], - ); +'''); } test_enum_method_fromInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void foo() {} } enum E implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.foo'. v; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 34, 1)], - ); +'''); } test_enum_method_fromMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin M { void foo(); } enum E with M { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.foo'. v; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 32, 1)], - ); +'''); } test_enum_setter_fromInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { set foo(int _) {} } enum E implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.foo'. v; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 38, 1)], - ); +'''); } test_enum_setter_fromMixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin M { set foo(int _); } enum E with M { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter M.foo'. v; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)], - ); +'''); } test_external_field_final_implement_getter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { external final int x; } @@ -347,33 +315,31 @@ class B implements A { } test_external_field_final_implement_none() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { external final int x; } class B implements A {} -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 42, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'. +'''); } test_external_field_implement_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { external int x; } class B implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.x'. int get x => 0; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)], - ); +'''); } test_external_field_implement_getter_and_setter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { external int x; } @@ -385,41 +351,31 @@ class B implements A { } test_external_field_implement_none() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { external int x; } class B implements A {} -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberTwo, - 36, - 1, - messageContains: ["'getter A.x' and 'setter A.x'"], - ), - ], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'getter A.x' and 'setter A.x'. +'''); } test_external_field_implement_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { external int x; } class B implements A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'. void set x(int value) {} } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)], - ); +'''); } test_fivePlus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { m(); n(); @@ -428,22 +384,14 @@ abstract class A { q(); } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberFivePlus] Missing concrete implementations of 'A.m', 'A.n', 'A.o', 'A.p', and 1 more. } -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberFivePlus, - 62, - 1, - messageContains: ["'A.m', 'A.n', 'A.o', 'A.p'"], - ), - ], - ); +'''); } test_four() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { m(); n(); @@ -451,22 +399,15 @@ abstract class A { p(); } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberFour] Missing concrete implementations of 'A.m', 'A.n', 'A.o', and 'A.p'. } -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberFour, - 55, - 1, - messageContains: ["'A.m', 'A.n', 'A.o', and 'A.p'"], - ), - ], - ); +'''); } test_mixin_concreteGetter() async { // issue 17034 - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 class A { var a; @@ -480,7 +421,7 @@ class C extends B {} } test_mixin_concreteMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 class A { m() {} @@ -494,7 +435,7 @@ class C extends B {} } test_mixin_concreteSetter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 class A { var a; @@ -508,7 +449,7 @@ class C extends B {} } test_noSuchMethod_concreteAccessor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { int get g; } @@ -519,7 +460,7 @@ class B extends A { } test_noSuchMethod_concreteMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { m(p); } @@ -530,7 +471,7 @@ class B extends A { } test_noSuchMethod_mixin() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 class A { noSuchMethod(v) => ''; @@ -542,7 +483,7 @@ class B extends Object with A { } test_noSuchMethod_superclass() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { noSuchMethod(v) => ''; } @@ -554,8 +495,7 @@ class B extends A { test_one_classTypeAlias_interface() async { // issue 15979 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' //@dart=2.19 abstract class M {} abstract class A {} @@ -563,96 +503,90 @@ abstract class I { m(); } class B = A with M implements I; -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 87, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'. +'''); } test_one_classTypeAlias_mixin() async { // issue 15979 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' //@dart=2.19 abstract class M { m(); } abstract class A {} class B = A with M; -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 67, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.m'. +'''); } test_one_classTypeAlias_superclass() async { // issue 15979 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' //@dart=2.19 class M {} abstract class A { m(); } class B = A with M; -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 58, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m'. +'''); } test_one_getter_fromInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { int get g {return 1;} } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter I.g'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 42, 1)], - ); +'''); } test_one_getter_fromSuperclass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { int get g; } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.g'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 40, 1)], - ); +'''); } test_one_method_fromInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { m(p) {} } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 28, 1)], - ); +'''); } test_one_method_fromInterface_abstractNSM() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { m(p) {} } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'. noSuchMethod(v); } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 28, 1)], - ); +'''); } test_one_method_fromInterface_abstractOverrideNSM() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class I { m(p) {} } @@ -666,36 +600,33 @@ class C extends B implements I { } test_one_method_fromInterface_ifcNSM() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { m(p) {} noSuchMethod(v) => null; } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 55, 1)], - ); +'''); } test_one_method_fromSuperclass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { m(p); } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 35, 1)], - ); +'''); } test_one_method_optionalParamCount() async { // issue 7640 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { int x(int a); } @@ -703,55 +634,51 @@ abstract class B { int x(int a, [int b]); } class C implements A, B { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'B.x'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 89, 1)], - ); +'''); } test_one_mixinInherits_getter() async { // issue 15001 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' //@dart=2.19 abstract class A { get g1; get g2; } abstract class B implements A { get g1 => 1; } class C extends Object with B {} -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 103, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.g2'. +'''); } test_one_mixinInherits_method() async { // issue 15001 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' //@dart=2.19 abstract class A { m1(); m2(); } abstract class B implements A { m1() => 1; } class C extends Object with B {} -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 97, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m2'. +'''); } test_one_mixinInherits_setter() async { // issue 15001 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' //@dart=2.19 abstract class A { set s1(v); set s2(v); } abstract class B implements A { set s1(v) {} } class C extends Object with B {} -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 109, 1)], - ); +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.s2'. +'''); } test_one_noSuchMethod_interface() async { // issue 15979 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { noSuchMethod(v) => ''; } @@ -759,16 +686,15 @@ abstract class A { m(); } class B extends A implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 71, 1)], - ); +'''); } test_one_setter_and_implicitSetter() async { // test from language/override_inheritance_abstract_test_14.dart - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { set field(_); } @@ -776,43 +702,40 @@ abstract class I { var field; } class B extends A implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.field'. get field => 0; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 77, 1)], - ); +'''); } test_one_setter_fromInterface() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { set s(int i) {} } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter I.s'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)], - ); +'''); } test_one_setter_fromSuperclass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { set s(int i); } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.s'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 43, 1)], - ); +'''); } test_one_superclasses_interface() async { // issue 11154 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { get a => 'a'; } @@ -820,44 +743,42 @@ abstract class B implements A { get b => 'b'; } class C extends B { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.a'. } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 84, 1)], - ); +'''); } test_one_variable_fromInterface_missingGetter() async { // issue 16133 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { var v; } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter I.v'. set v(_) {} } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 27, 1)], - ); +'''); } test_one_variable_fromInterface_missingSetter() async { // issue 16133 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { var v; } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter I.v'. get v => 1; } -''', - [error(diag.nonAbstractClassInheritsAbstractMemberOne, 27, 1)], - ); +'''); } test_overridesConcreteMethodInObject() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' //@dart=2.19 class A { String toString([String prefix = '']) => '${prefix}Hello'; @@ -868,66 +789,42 @@ class B extends A with C {} } test_three() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { m(); n(); o(); } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberThree] Missing concrete implementations of 'A.m', 'A.n', and 'A.o'. } -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberThree, - 48, - 1, - messageContains: ["'A.m', 'A.n', and 'A.o'"], - ), - ], - ); +'''); } test_two() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { m(); n(); } class C extends A { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'A.m' and 'A.n'. } -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberTwo, - 41, - 1, - messageContains: ["'A.m' and 'A.n'"], - ), - ], - ); +'''); } test_two_fromInterface_missingBoth() async { // issue 16133 - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class I { var v; } class C implements I { +// ^ +// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'getter I.v' and 'setter I.v'. } -''', - [ - error( - diag.nonAbstractClassInheritsAbstractMemberTwo, - 27, - 1, - messageContains: ["'getter I.v' and 'setter I.v'."], - ), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart index 5af4a54e882..76acd2b159a 100644 --- a/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart @@ -6,313 +6,285 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonBoolConditionTest); defineReflectiveTests(NonBoolConditionWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonBoolConditionTest extends PubPackageResolutionTest { test_conditional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { return 3 ? 2 : 1; } -''', - [error(diag.nonBoolCondition, 13, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_conditional_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { return [1, 2, 3] ? 2 : 1; } -''', - [error(diag.nonBoolCondition, 13, 9)], - ); +// ^^^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_conditional_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { return o ? 2 : 1; } -''', - [error(diag.nonBoolCondition, 21, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_const_list_ifElement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const dynamic c = 2; const x = [1, if (c) 2 else 3, 4]; -''', - [error(diag.nonBoolCondition, 39, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_const_list_ifElement_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const x = [1, if (1) 2 else 3, 4]; -''', - [error(diag.nonBoolCondition, 18, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_do() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { do {} while (3); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 21, 1)], - ); +'''); } test_do_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { do {} while ([1, 2, 3]); +// ^^^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 29, 9)], - ); +'''); } test_do_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { do {} while (o); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 29, 1)], - ); +'''); } test_for() async { // https://github.com/dart-lang/sdk/issues/24713 - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { for (;3;) {} +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 14, 1)], - ); +'''); } test_for_declaration() async { // https://github.com/dart-lang/sdk/issues/24713 - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { for (int i = 0; 3;) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used. +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [ - error(diag.unusedLocalVariable, 17, 1), - error(diag.nonBoolCondition, 24, 1), - ], - ); +'''); } test_for_expression() async { // https://github.com/dart-lang/sdk/issues/24713 - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { int i; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used. for (i = 0; 3;) {} -}''', - [ - error(diag.unusedLocalVariable, 12, 1), - error(diag.nonBoolCondition, 29, 1), - ], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +}'''); } test_for_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { for (;[1, 2, 3];) {} +// ^^^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 14, 9)], - ); +'''); } test_for_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { for (;o;) {} +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 22, 1)], - ); +'''); } test_forElement() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = [for (; 0;) 1]; -''', - [error(diag.nonBoolCondition, 16, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_guardedPattern_whenClause() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { if (0 case _ when 1) {} +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 31, 1)], - ); +'''); } test_if() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { if (3) return 2; else return 1; +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 12, 1)], - ); +'''); } test_if_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { if ([1, 2, 3]) return 2; else return 1; +// ^^^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 12, 9)], - ); +'''); } test_if_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { if (o) return 2; else return 1; +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 20, 1)], - ); +'''); } test_if_map() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const dynamic nonBool = null; const c = const {if (nonBool) 'a' : 1}; -''', - [error(diag.nonBoolCondition, 51, 7)], - ); +// ^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_if_null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Null a) { if (a) {} +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 23, 1)], - ); +'''); } test_if_set() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const dynamic nonBool = 'a'; const c = const {if (nonBool) 3}; -''', - [error(diag.nonBoolCondition, 50, 7)], - ); +// ^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_ifElement() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = [if (3) 1]; -''', - [error(diag.nonBoolCondition, 13, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_ifElement_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = [if ([1, 2, 3]) 'x']; -''', - [error(diag.nonBoolCondition, 13, 9)], - ); +// ^^^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_ifElement_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' final o = Object(); var v = [if (o) 'x']; -''', - [error(diag.nonBoolCondition, 33, 1)], - ); +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. +'''); } test_ternary_condition_null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Null a) { a ? 0 : 1; +//^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 19, 1)], - ); +'''); } test_while() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { while (3) {} +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 15, 1)], - ); +'''); } test_while_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { while ([1, 2, 3]) {} +// ^^^^^^^^^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 15, 9)], - ); +'''); } test_while_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { while (o) {} +// ^ +// [diag.nonBoolCondition] Conditions must have a static type of 'bool'. } -''', - [error(diag.nonBoolCondition, 23, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_expression_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_expression_test.dart index d80ad638e12..2e9929c1337 100644 --- a/pkg/analyzer/test/src/diagnostics/non_bool_expression_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_bool_expression_test.dart @@ -6,49 +6,48 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonBoolExpressionTest); defineReflectiveTests(NonBoolExpressionWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonBoolExpressionTest extends PubPackageResolutionTest { test_functionType_bool() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool makeAssertion() => true; f() { assert(makeAssertion); +// ^^^^^^^^^^^^^ +// [diag.nonBoolExpression] The expression in an assert must be of type 'bool'. } -''', - [error(diag.nonBoolExpression, 45, 13)], - ); +'''); } test_functionType_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int makeAssertion() => 1; f() { assert(makeAssertion); +// ^^^^^^^^^^^^^ +// [diag.nonBoolExpression] The expression in an assert must be of type 'bool'. } -''', - [error(diag.nonBoolExpression, 41, 13)], - ); +'''); } test_interfaceType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { assert(0); +// ^ +// [diag.nonBoolExpression] The expression in an assert must be of type 'bool'. } -''', - [error(diag.nonBoolExpression, 15, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart index c293e8ba9a4..339f6604471 100644 --- a/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart @@ -6,58 +6,56 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonBoolNegationExpressionTest); defineReflectiveTests(NonBoolNegationExpressionWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonBoolNegationExpressionTest extends PubPackageResolutionTest { test_nonBool() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { !42; +// ^^ +// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'. } -''', - [error(diag.nonBoolNegationExpression, 9, 2)], - ); +'''); } test_nonBool_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { ![1, 2, 3]; +// ^^^^^^^^^ +// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'. } -''', - [error(diag.nonBoolNegationExpression, 9, 9)], - ); +'''); } test_nonBool_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Object o) { !o; +// ^ +// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'. } -''', - [error(diag.nonBoolNegationExpression, 17, 1)], - ); +'''); } test_null() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void m(Null x) { !x; +// ^ +// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'. } -''', - [error(diag.nonBoolNegationExpression, 20, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart index 2414778a8a3..628d3cf855b 100644 --- a/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart @@ -6,115 +6,108 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonBoolOperandTest); defineReflectiveTests(NonBoolOperandWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonBoolOperandTest extends PubPackageResolutionTest { test_and_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool f(int left, bool right) { return left && right; +// ^^^^ +// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 40, 4)], - ); +'''); } test_and_left_fromInstanceCreationExpression() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' main() { new Object() && true; +//^^^^^^^^^^^^ +// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 11, 12)], - ); +'''); } test_and_left_fromLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' bool f(List left, bool right) { return left && right; +// ^^^^ +// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 46, 4)], - ); +'''); } test_and_left_fromSupertype() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' bool f(Object left, bool right) { return left && right; +// ^^^^ +// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 43, 4)], - ); +'''); } test_and_null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' m() { Null x; if(x && true) {} +// ^ +// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 21, 1)], - ); +'''); } test_and_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool f(bool left, String right) { return left && right; +// ^^^^^ +// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 51, 5)], - ); +'''); } test_or_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool f(List left, bool right) { return left || right; +// ^^^^ +// [diag.nonBoolOperand] The operands of the operator '||' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 46, 4)], - ); +'''); } test_or_null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' m() { Null x; if(x || false) {} +// ^ +// [diag.nonBoolOperand] The operands of the operator '||' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 21, 1)], - ); +'''); } test_or_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool f(bool left, double right) { return left || right; +// ^^^^^ +// [diag.nonBoolOperand] The operands of the operator '||' must be assignable to 'bool'. } -''', - [error(diag.nonBoolOperand, 51, 5)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_const_argument_for_const_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/non_const_argument_for_const_parameter_test.dart index a663de724a6..1e3a614891d 100644 --- a/pkg/analyzer/test/src/diagnostics/non_const_argument_for_const_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_const_argument_for_const_parameter_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ConstAnnotationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,71 +23,68 @@ class ConstAnnotationTest extends PubPackageResolutionTest { } test_adjacentLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final c = C('H' 'ello'); class C { C(@mustBeConst String s); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 92, 11), - ], - ); +'''); } test_binaryOperator_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(A a) { var b = A(); a < b; +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'other' must be a constant. } class A { bool operator <(@mustBeConst A other) => false; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 86, 1), - error(diag.experimentalMemberUse, 121, 11), - ], - ); +'''); } test_binaryOperator_fails_inAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(A a) { var b = A(); a += b; +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'other' must be a constant. } class A { A operator +(@mustBeConst A other) => this; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 87, 1), - error(diag.experimentalMemberUse, 119, 11), - ], - ); +'''); } test_binaryOperator_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(A a) { const b = A(); @@ -97,19 +95,17 @@ class A { const A(); bool operator <(@mustBeConst A other) => false; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 137, 11), - ], - ); +'''); } test_binaryOperator_succeeds_inAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(A a) { const b = A(); @@ -120,167 +116,153 @@ class A { const A(); A operator +(@mustBeConst A other) => this; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 135, 11), - ], - ); +'''); } test_constExpression_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() { g(const C()); } void g(@mustBeConst C c) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. class C { const C(); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 89, 11), - ], - ); +'''); } test_constructor_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final c = C(3); class C { C(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 83, 11), - ], - ); +'''); } test_constructor_extensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; final c = C(v); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'it' must be a constant. extension type C(@mustBeConst int it) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 77, 1), - error(diag.experimentalMemberUse, 100, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_constructor_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; final c = C(v); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. class C { C(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 77, 1), - error(diag.experimentalMemberUse, 97, 11), - ], - ); +'''); } test_functionExpression_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() { var g = (@mustBeConst int i) {}; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. g(3); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 74, 11), - ], - ); +'''); } test_functionExpression_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(int x) { var g = (@mustBeConst int i) {}; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. g(x); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 79, 11), - error(diag.nonConstArgumentForConstParameter, 106, 1), - ], - ); +'''); } test_functionType_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(void g(@mustBeConst int i)) { +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. g(3); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 66, 11), - ], - ); +'''); } test_functionType_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(void g(@mustBeConst int i), int x) { +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. g(x); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 66, 11), - error(diag.nonConstArgumentForConstParameter, 99, 1), - ], - ); +'''); } test_indexExpression_constExpression_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(A a) { const b = A(); @@ -291,291 +273,268 @@ class A { const A(); void operator []=(@mustBeConst int i, @mustBeConst A v) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 142, 11), - error(diag.experimentalMemberUse, 162, 11), - ], - ); +'''); } test_indexExpression_nonConstant_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(A a) { a[1] = A(); +// ^^^ +// [diag.nonConstArgumentForConstParameter] Argument 'v' must be a constant. } class A { const A(); void operator []=(@mustBeConst int i, @mustBeConst A v) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 74, 3), - error(diag.experimentalMemberUse, 127, 11), - error(diag.experimentalMemberUse, 147, 11), - ], - ); +'''); } test_interpolationLiteral_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const a = 'ello'; final c = C('H$a'); +// ^^^^^ +// [diag.nonConstArgumentForConstParameter] Argument 's' must be a constant. class C { C(@mustBeConst String s); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 82, 5), - error(diag.experimentalMemberUse, 106, 11), - ], - ); +'''); } test_localFunction_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() { void g(@mustBeConst int i) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. g(3); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 72, 11), - ], - ); +'''); } test_localFunction_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(int x) { void g(@mustBeConst int i) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. g(x); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 77, 11), - error(diag.nonConstArgumentForConstParameter, 103, 1), - ], - ); +'''); } test_method_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(C c) => c.g(3); class C { void g([@mustBeConst int? value]) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 96, 11), - ], - ); +'''); } test_method_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; void f(C c) => c.g(v); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'value' must be a constant. class C { void g([@mustBeConst int? value]) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 84, 1), - error(diag.experimentalMemberUse, 110, 11), - ], - ); +'''); } test_optionalNamed_constVariable_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const v = 3; void f() => g(value: v); void g({@mustBeConst int? value}) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 100, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_optionalNamed_noArgument_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() => g(); void g({@mustBeConst int? value}) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 78, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_optionalNamed_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; void f() => g(value: v); +// ^^^^^^^^ +// [diag.nonConstArgumentForConstParameter] Argument 'value' must be a constant. void g({@mustBeConst int? value}) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 79, 8), - error(diag.experimentalMemberUse, 100, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_optionalPositional_constVariable_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const v = 3; void f() => g(v); void g([@mustBeConst int? value]) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 93, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_optionalPositional_noArgument_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() => g(); void g([@mustBeConst int? value]) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 78, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_optionalPositional_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; void f() => g(v); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'value' must be a constant. void g([@mustBeConst int? value]) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 79, 1), - error(diag.experimentalMemberUse, 93, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_primaryConstructor_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final c = C(3); class C(@mustBeConst int i); -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 77, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_primaryConstructor_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final f = 3; final c = C(f); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. class C(@mustBeConst int i); -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 76, 1), - error(diag.experimentalMemberUse, 90, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_redirectingConstructor_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. class A { A(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. A.named(int i) : this(i); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 66, 11), - error(diag.nonConstArgumentForConstParameter, 110, 1), - ], - ); +'''); } test_redirectingFactoryConstructor_variable_succeeds() async { @@ -584,191 +543,175 @@ class A { // are separate. For example, they can have separate annotations. // TODO(srawlins): It still seems that to be consistent, we should report // `A.named(int i)`. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. class A { A(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. factory A.named(int i) = A; } final v = 3; var a = A.named(v); -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 66, 11), - ], - ); +'''); } test_requiredNamed_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() => g(value: 3); void g({@mustBeConst required int value}) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 86, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_requiredNamed_constVariable_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const v = 3; void f() => g(value: v); void g({@mustBeConst required int value}) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 100, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_requiredPositional_constVariable_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const v = 3; void f() => g(v); void g(@mustBeConst int value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 92, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_requiredPositional_list_constVariable_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const v = [3,4]; void f() => g(v); void g(@mustBeConst List value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 96, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_requiredPositional_localVariable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(int value) => g(value); +// ^^^^^ +// [diag.nonConstArgumentForConstParameter] Argument 'value' must be a constant. void g(@mustBeConst int value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 74, 5), - error(diag.experimentalMemberUse, 91, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_requiredPositional_map_constVariable_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. const v = {'k1': 3, 'k2': 4}; void f() => g(v); void g(@mustBeConst Map value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 109, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_requiredPositional_topLevelVariable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; void f() => g(v); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'value' must be a constant. void g(@mustBeConst int value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 79, 1), - error(diag.experimentalMemberUse, 92, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_setter_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() { final v = 3; i = v; +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'value' must be a constant. } set i(@mustBeConst int? value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 83, 1), - error(diag.experimentalMemberUse, 96, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_setter_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f() { i = 3; } set i(@mustBeConst int? value) {} -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 81, 11), - ], - ); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. +'''); } test_subclassesDontInherit() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; @@ -776,24 +719,22 @@ final r = B().f(v); abstract class A { void f(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } class B extends A { @override void f(int i) {} } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 115, 11), - ], - ); +'''); } test_superclassCanBeOverriden_cast_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; @@ -806,23 +747,23 @@ abstract class A { class B extends A { @override void f(@mustBeConst int i) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 174, 11), - ], - ); +'''); } test_superclassCanBeOverriden_noCast_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. final v = 3; final r = B().f(v); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. abstract class A { void f(int i); @@ -831,113 +772,101 @@ abstract class A { class B extends A { @override void f(@mustBeConst int i) {} +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.nonConstArgumentForConstParameter, 81, 1), - error(diag.experimentalMemberUse, 167, 11), - ], - ); +'''); } test_superConstructor_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. class A { A(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } class B extends A { B(int i) : super(i); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 66, 11), - error(diag.nonConstArgumentForConstParameter, 128, 1), - ], - ); +'''); } test_superParameter_variable_succeeds() async { // TODO(srawlins): It seems that to be consistent, we should `super.i`. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. class A { A(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } class B extends A { B(super.i); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 66, 11), - ], - ); +'''); } test_typedef_function_constantLiteral_succeeds() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. typedef Td = void Function(@mustBeConst int); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(Td td) { td(3); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 79, 11), - ], - ); +'''); } test_typedef_function_variable_succeeds() async { // An annotation on a parameter in a function type is not supported. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. typedef Td = void Function(@mustBeConst int); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. void f(int x, Td td) { td(x); } -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 79, 11), - ], - ); +'''); } test_typedef_nonFunction_variable_fails() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart' show mustBeConst; +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. typedef T = C; class C { C(@mustBeConst int i); +// ^^^^^^^^^^^ +// [diag.experimentalMemberUse] 'mustBeConst' is experimental and could be removed or changed at any time. } void g(int x) => T(x); -''', - [ - error(diag.experimentalMemberUse, 37, 11), - error(diag.experimentalMemberUse, 82, 11), - error(diag.nonConstArgumentForConstParameter, 124, 1), - ], - ); +// ^ +// [diag.nonConstArgumentForConstParameter] Argument 'i' must be a constant. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_const_call_to_literal_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/non_const_call_to_literal_constructor_test.dart index 800df6dc4c7..25d370c8e01 100644 --- a/pkg/analyzer/test/src/diagnostics/non_const_call_to_literal_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_const_call_to_literal_constructor_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstCallToLiteralConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,7 +23,7 @@ class NonConstCallToLiteralConstructorTest extends PubPackageResolutionTest { } test_class_primaryConstructor_constContext() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class const A() { @literal @@ -33,49 +34,46 @@ const a = A(); } test_class_primaryConstructor_dotShorthand_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class const A() { @literal this; } A a = .new(); -''', - [error(diag.nonConstCallToLiteralConstructor, 78, 6)], - ); +// ^^^^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'. +'''); } test_class_primaryConstructor_nonConstContext() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class const A() { @literal this; } var a = A(); -''', - [error(diag.nonConstCallToLiteralConstructor, 80, 3)], - ); +// ^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'. +'''); } test_class_secondaryConstructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal const A.named(); } var a = A.named(); -''', - [error(diag.nonConstCallToLiteralConstructor, 83, 9)], - ); +// ^^^^^^^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A.named constructor is marked as '@literal'. +'''); } test_class_secondaryConstructor_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal @@ -85,7 +83,7 @@ class A { } test_class_secondaryConstructor_constContextCreation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal @@ -96,7 +94,7 @@ const a = A(); } test_class_secondaryConstructor_constCreation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal @@ -107,49 +105,46 @@ const a = const A(); } test_class_secondaryConstructor_dotShorthand() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal const A.named(); } A a = .named(); -''', - [error(diag.nonConstCallToLiteralConstructor, 81, 8)], - ); +// ^^^^^^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A.named constructor is marked as '@literal'. +'''); } test_class_secondaryConstructor_dotShorthand_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal const A(); } A a = .new(); -''', - [error(diag.nonConstCallToLiteralConstructor, 75, 6)], - ); +// ^^^^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'. +'''); } test_class_secondaryConstructor_nonConstContext() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal const A(); } var a = A(); -''', - [error(diag.nonConstCallToLiteralConstructor, 77, 3)], - ); +// ^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'. +'''); } test_class_secondaryConstructor_unconstableCreation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal @@ -160,21 +155,20 @@ var a = A(new List.filled(1, '')); } test_class_secondaryConstructor_usingNew() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @literal const A(); } var a = new A(); -''', - [error(diag.nonConstCallToLiteralConstructorUsingNew, 77, 7)], - ); +// ^^^^^^^ +// [diag.nonConstCallToLiteralConstructorUsingNew] This instance creation must be 'const', because the A constructor is marked as '@literal'. +'''); } test_extensionType_constCreation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; extension type const E(int i) { @literal @@ -185,16 +179,15 @@ E e = const E.zero(); } test_extensionType_usingNew() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; extension type const E(int i) { @literal const E.zero(): this(0); } E e = E.zero(); -''', - [error(diag.nonConstCallToLiteralConstructor, 111, 8)], - ); +// ^^^^^^^^ +// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the E.zero constructor is marked as '@literal'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_const_generative_enum_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/non_const_generative_enum_constructor_test.dart index 3f6d3bb9c6a..d198139b9a6 100644 --- a/pkg/analyzer/test/src/diagnostics/non_const_generative_enum_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_const_generative_enum_constructor_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstGenerativeEnumConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstGenerativeEnumConstructorTest extends PubPackageResolutionTest { test_factoryHead_unnamed() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v.named(); const E.named(); @@ -26,7 +27,7 @@ enum E { } test_generative_const_newHead_named() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v.named(); const new named(); @@ -35,7 +36,7 @@ enum E { } test_generative_const_newHead_unnamed() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; const new (); @@ -44,7 +45,7 @@ enum E { } test_generative_const_typeName() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; const E(); @@ -53,7 +54,7 @@ enum E { } test_generative_nonConst_newHead_unnamed() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; new (); @@ -62,7 +63,7 @@ enum E { } test_generative_nonConst_typeName_named() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v.named(); E.named(); @@ -71,20 +72,19 @@ enum E { } test_generative_nonConst_typeName_named_language310() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 enum E { v.named(); E.named(); +//^^^^^^^ +// [diag.nonConstGenerativeEnumConstructor] Generative enum constructors must be 'const'. } -''', - [error(diag.nonConstGenerativeEnumConstructor, 40, 7)], - ); +'''); } test_generative_nonConst_typeName_unnamed() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; E(); @@ -93,20 +93,19 @@ enum E { } test_generative_nonConst_typeName_unnamed_language310() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 enum E { v; E(); +//^ +// [diag.nonConstGenerativeEnumConstructor] Generative enum constructors must be 'const'. } -''', - [error(diag.nonConstGenerativeEnumConstructor, 32, 1)], - ); +'''); } test_typeName_factory_named() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; factory E.foo() => v; diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_annotation_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_annotation_constructor_test.dart index ed8024f0205..cff8ee2c57c 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_annotation_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_annotation_constructor_test.dart @@ -2,44 +2,41 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantAnnotationConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantAnnotationConstructorTest extends PubPackageResolutionTest { test_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.fromInt() {} } @A.fromInt() +// [diag.nonConstantAnnotationConstructor][column 1][length 12] Annotation creation can only call a const constructor. main() { } -''', - [error(diag.nonConstantAnnotationConstructor, 29, 12)], - ); +'''); } test_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() {} } @A() +// [diag.nonConstantAnnotationConstructor][column 1][length 4] Annotation creation can only call a const constructor. main() { } -''', - [error(diag.nonConstantAnnotationConstructor, 21, 4)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart index 9f1008ba447..eb0194e3a82 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_from_deferred_library_test.dart @@ -2,11 +2,10 @@ // 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:analyzer/error/error.dart'; -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { @@ -14,98 +13,49 @@ main() { defineReflectiveTests( NonConstantCaseExpressionFromDeferredLibraryTest_Language219, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantCaseExpressionFromDeferredLibraryTest - extends PubPackageResolutionTest - with NonConstantCaseExpressionFromDeferredLibraryTestCases { - @override - _Variant get _variant => _Variant.patterns; - + extends PubPackageResolutionTest { test_nested() async { newFile('$testPackageLibPath/a.dart', ''' const int c = 0; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart' deferred as a; void f(int e) { switch (e) { case const (a.c + 1): +// ^ +// [diag.patternConstantFromDeferredLibrary] Constant values from a deferred library can't be used in patterns. break; } } -''', - [error(diag.patternConstantFromDeferredLibrary, 81, 1)], - ); - } -} - -@reflectiveTest -class NonConstantCaseExpressionFromDeferredLibraryTest_Language219 - extends PubPackageResolutionTest - with - WithLanguage219Mixin, - NonConstantCaseExpressionFromDeferredLibraryTestCases { - @override - _Variant get _variant => _Variant.nullSafe; - - test_nested() async { - newFile('$testPackageLibPath/a.dart', ''' -const int c = 0; '''); - - await assertErrorsInCode( - ''' -import 'a.dart' deferred as a; - -void f(int e) { - switch (e) { - case a.c + 1: - break; } -} -''', - [error(diag.nonConstantCaseExpressionFromDeferredLibrary, 74, 1)], - ); - } -} - -mixin NonConstantCaseExpressionFromDeferredLibraryTestCases - on PubPackageResolutionTest { - _Variant get _variant; test_simple() async { newFile('$testPackageLibPath/a.dart', ''' const int c = 0; '''); - DiagnosticCode expectedDiagnosticCode; - switch (_variant) { - case _Variant.nullSafe: - expectedDiagnosticCode = - diag.nonConstantCaseExpressionFromDeferredLibrary; - case _Variant.patterns: - expectedDiagnosticCode = diag.patternConstantFromDeferredLibrary; - } - - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart' deferred as a; void f(int e) { switch (e) { case a.c: +// ^ +// [diag.patternConstantFromDeferredLibrary] Constant values from a deferred library can't be used in patterns. break; } } -''', - [error(expectedDiagnosticCode, 74, 1)], - ); +'''); } test_simple_typeLiteral() async { @@ -113,29 +63,79 @@ void f(int e) { class A {} '''); - DiagnosticCode expectedDiagnosticCode; - switch (_variant) { - case _Variant.nullSafe: - expectedDiagnosticCode = - diag.nonConstantCaseExpressionFromDeferredLibrary; - case _Variant.patterns: - expectedDiagnosticCode = diag.patternConstantFromDeferredLibrary; - } - - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart' deferred as a; void f(Object? x) { switch (x) { case a.A: +// ^ +// [diag.patternConstantFromDeferredLibrary] Constant values from a deferred library can't be used in patterns. break; } } -''', - [error(expectedDiagnosticCode, 78, 1)], - ); +'''); } } -enum _Variant { nullSafe, patterns } +@reflectiveTest +class NonConstantCaseExpressionFromDeferredLibraryTest_Language219 + extends PubPackageResolutionTest + with WithLanguage219Mixin { + test_nested() async { + newFile('$testPackageLibPath/a.dart', ''' +const int c = 0; +'''); + + await resolveTestCodeWithDiagnostics(''' +import 'a.dart' deferred as a; + +void f(int e) { + switch (e) { + case a.c + 1: +// ^ +// [diag.nonConstantCaseExpressionFromDeferredLibrary] Constant values from a deferred library can't be used as a case expression. + break; + } +} +'''); + } + + test_simple() async { + newFile('$testPackageLibPath/a.dart', ''' +const int c = 0; +'''); + + await resolveTestCodeWithDiagnostics(''' +import 'a.dart' deferred as a; + +void f(int e) { + switch (e) { + case a.c: +// ^ +// [diag.nonConstantCaseExpressionFromDeferredLibrary] Constant values from a deferred library can't be used as a case expression. + break; + } +} +'''); + } + + test_simple_typeLiteral() async { + newFile('$testPackageLibPath/a.dart', ''' +class A {} +'''); + + await resolveTestCodeWithDiagnostics(''' +import 'a.dart' deferred as a; + +void f(Object? x) { + switch (x) { + case a.A: +// ^ +// [diag.nonConstantCaseExpressionFromDeferredLibrary] Constant values from a deferred library can't be used as a case expression. + break; + } +} +'''); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart index e295a8177d3..31665641828 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart @@ -2,43 +2,23 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantCaseExpressionTest); defineReflectiveTests(NonConstantCaseExpressionTest_Language219); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantCaseExpressionTest extends PubPackageResolutionTest - with NonConstantCaseExpressionTestCases {} - -@reflectiveTest -class NonConstantCaseExpressionTest_Language219 extends PubPackageResolutionTest - with WithLanguage219Mixin, NonConstantCaseExpressionTestCases { - test_parameter() async { - await assertErrorsInCode( - r''' -void f(var e, int a) { - switch (e) { - case 3 + a: - break; - } -} -''', - [error(diag.nonConstantCaseExpression, 51, 1)], - ); - } -} - -mixin NonConstantCaseExpressionTestCases on PubPackageResolutionTest { +class NonConstantCaseExpressionTest extends PubPackageResolutionTest { test_constField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(C e) { switch (e) { case C.zero: @@ -58,7 +38,58 @@ class C { } test_typeLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' +void f(e) { + switch (e) { + case bool: + case int: + break; + default: + break; + } +} +'''); + } +} + +@reflectiveTest +class NonConstantCaseExpressionTest_Language219 extends PubPackageResolutionTest + with WithLanguage219Mixin { + test_constField() async { + await resolveTestCodeWithDiagnostics(r''' +void f(C e) { + switch (e) { + case C.zero: + break; + default: + break; + } +} + +class C { + static const zero = C(0); + + final int a; + const C(this.a); +} +'''); + } + + test_parameter() async { + await resolveTestCodeWithDiagnostics(r''' +void f(var e, int a) { + switch (e) { + case 3 + a: +// ^ +// [diag.nonConstantCaseExpression] Case expressions must be constant. + break; + } +} +'''); + } + + test_typeLiteral() async { + await resolveTestCodeWithDiagnostics(r''' void f(e) { switch (e) { case bool: diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_default_value_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_default_value_from_deferred_library_test.dart index c9751222324..d5a5158bce6 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_default_value_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_default_value_from_deferred_library_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantDefaultValueFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -21,14 +22,13 @@ class NonConstantDefaultValueFromDeferredLibraryTest library lib1; const V = 1; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' library root; import 'lib1.dart' deferred as a; f({x = a.V}) {} -''', - [error(diag.nonConstantDefaultValueFromDeferredLibrary, 57, 1)], - ); +// ^ +// [diag.nonConstantDefaultValueFromDeferredLibrary] Constant values from a deferred library can't be used as a default parameter value. +'''); } test_nested() async { @@ -36,13 +36,12 @@ f({x = a.V}) {} library lib1; const V = 1; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' library root; import 'lib1.dart' deferred as a; f({x = a.V + 1}) {} -''', - [error(diag.nonConstantDefaultValueFromDeferredLibrary, 57, 1)], - ); +// ^ +// [diag.nonConstantDefaultValueFromDeferredLibrary] Constant values from a deferred library can't be used as a default parameter value. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_default_value_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_default_value_test.dart index e89887e8c0a..3f22af980ca 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_default_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_default_value_test.dart @@ -2,60 +2,54 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantDefaultValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantDefaultValueTest extends PubPackageResolutionTest { test_constructor_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int y = 0; A({x = y}) {} +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer. } -''', - [ - error(diag.nonConstantDefaultValue, 32, 1), - error(diag.implicitThisReferenceInInitializer, 32, 1), - ], - ); +'''); } test_constructor_positional() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int y = 0; A([x = y]) {} +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer. } -''', - [ - error(diag.nonConstantDefaultValue, 32, 1), - error(diag.implicitThisReferenceInInitializer, 32, 1), - ], - ); +'''); } test_dotShorthand_issue60962() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(); } void f([A a = .new()]) {} -''', - [error(diag.nonConstantDefaultValue, 40, 6)], - ); +// ^^^^^^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } test_enum_issue49097() async { @@ -66,7 +60,7 @@ class A { const A(); } '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; enum E { @@ -78,147 +72,135 @@ enum E { } test_function_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int y = 0; f({x = y}) {} -''', - [error(diag.nonConstantDefaultValue, 18, 1)], - ); +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } test_function_named_constList() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = const [0, 1]}) {} '''); } test_function_named_constList_elements_listLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = const [0, [1]]}) {} '''); } test_function_named_constRecord() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = const (0, 1)}) {} '''); } test_function_named_constRecord_namedFields_listLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = const (0, foo: [1])}) {} '''); } test_function_named_constRecord_positionalFields_listLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = const (0, [1])}) {} '''); } test_function_named_record_namedFields_integerLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = (a: 0, b: 1)}) {} '''); } test_function_named_record_namedFields_listLiteral() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = (a: 0, b: [1])}) {} -''', - [error(diag.nonConstantDefaultValue, 22, 3)], - ); +// ^^^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } test_function_named_record_namedFields_listLiteral_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = (a: 0, b: const [1])}) {} '''); } test_function_named_record_positionalFields_integerLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = (0, 1)}) {} '''); } test_function_named_record_positionalFields_listLiteral() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = (0, [1])}) {} -''', - [error(diag.nonConstantDefaultValue, 16, 3)], - ); +// ^^^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } test_function_named_record_positionalFields_listLiteral_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f({x = (0, const [1])}) {} '''); } test_function_named_undefinedIdentifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f({int x = X}) {} -''', - [error(diag.undefinedIdentifier, 16, 1)], - ); +// ^ +// [diag.undefinedIdentifier] Undefined name 'X'. +'''); } test_function_positional() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int y = 0; f([x = y]) {} -''', - [error(diag.nonConstantDefaultValue, 18, 1)], - ); +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } test_function_positional_undefinedIdentifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f([int x = X]) {} -''', - [error(diag.undefinedIdentifier, 16, 1)], - ); +// ^ +// [diag.undefinedIdentifier] Undefined name 'X'. +'''); } test_method_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int y = 0; m({x = y}) {} +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer. } -''', - [ - error(diag.nonConstantDefaultValue, 32, 1), - error(diag.implicitThisReferenceInInitializer, 32, 1), - ], - ); +'''); } test_method_positional() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int y = 0; m([x = y]) {} +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer. } -''', - [ - error(diag.nonConstantDefaultValue, 32, 1), - error(diag.implicitThisReferenceInInitializer, 32, 1), - ], - ); +'''); } test_noAppliedTypeParameters_defaultConstructorValue_dynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) => t; class C { @@ -229,7 +211,7 @@ class C { } test_noAppliedTypeParameters_defaultConstructorValue_genericFn() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) => t; class C { @@ -240,7 +222,7 @@ class C { } test_noAppliedTypeParameters_defaultFunctionValue_genericFn() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) => t; void bar([void Function(T) p = f]) {} @@ -248,7 +230,7 @@ void bar([void Function(T) p = f]) {} } test_noAppliedTypeParameters_defaultMethodValue_genericFn() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) => t; class C { @@ -258,22 +240,20 @@ class C { } test_primaryConstructor_optionalNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int y = 0; class A({int x = y}); -''', - [error(diag.nonConstantDefaultValue, 28, 1)], - ); +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } test_primaryConstructor_optionalPositional() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int y = 0; class A([int x = y]); -''', - [error(diag.nonConstantDefaultValue, 28, 1)], - ); +// ^ +// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart index 5965d58fa19..c802ed3e939 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart @@ -6,10 +6,12 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantListElementFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -36,47 +38,44 @@ var v = const [ if (cond) 'a' else a.c ]; newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; const cond = true; var v = const [ if (cond) a.c ]; -''', - [error(diag.nonConstantListElementFromDeferredLibrary, 81, 1)], - ); +// ^ +// [diag.nonConstantListElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' list literal. +'''); } test_const_topLevel_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const [a.c]; -''', - [error(diag.nonConstantListElementFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.nonConstantListElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' list literal. +'''); } test_const_topLevel_deferred_nested() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const [a.c + 1]; -''', - [error(diag.nonConstantListElementFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.nonConstantListElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' list literal. +'''); } test_const_topLevel_notDeferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1; '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' as a; var v = const [a.c]; '''); diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart index 200fcc8c19f..90505524753 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart @@ -2,118 +2,108 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantListElementTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantListElementTest extends PubPackageResolutionTest - with NonConstantListElementTestCases {} - -mixin NonConstantListElementTestCases on PubPackageResolutionTest { +class NonConstantListElementTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [if (1 < 0) 0 else a]; -''', - [error(diag.nonConstantListElement, 54, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_ifElement_thenElseFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [if (1 < 0) a else 0]; -''', - [error(diag.nonConstantListElement, 47, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_ifElement_thenElseTrue_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [if (1 > 0) 0 else a]; -''', - [error(diag.nonConstantListElement, 54, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_ifElement_thenElseTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [if (1 > 0) a else 0]; -''', - [error(diag.nonConstantListElement, 47, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_ifElement_thenFalse_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const [if (1 < 0) a]; '''); } test_const_ifElement_thenFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [if (1 < 0) a]; -''', - [error(diag.nonConstantListElement, 47, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_ifElement_thenTrue_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const [if (1 > 0) a]; '''); } test_const_ifElement_thenTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [if (1 > 0) a]; -''', - [error(diag.nonConstantListElement, 47, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_topVar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const [a]; -''', - [error(diag.nonConstantListElement, 36, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_const_topVar_nested() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; var v = const [a + 1]; -''', - [error(diag.nonConstantListElement, 36, 1)], - ); +// ^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +'''); } test_nonConst_topVar() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = [a]; '''); diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_element_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_element_test.dart index be004368ba9..e4869f27906 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_map_element_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_element_test.dart @@ -2,26 +2,24 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantMapElementTest); defineReflectiveTests(NonConstantMapKeyTest); defineReflectiveTests(NonConstantMapValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantMapElementTest extends PubPackageResolutionTest - with NonConstantMapElementTestCases {} - -mixin NonConstantMapElementTestCases on PubPackageResolutionTest { +class NonConstantMapElementTest extends PubPackageResolutionTest { test_forElement_notConst_noError() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main() { var x; print({x: x, for (final x2 in [x]) x2: x2}); @@ -30,7 +28,7 @@ void main() { } test_ifElement_mayBeConst() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main() { const {1: null, if (true) null: null}; } @@ -38,7 +36,7 @@ void main() { } test_ifElement_nested_mayBeConst() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main() { const {1: null, if (true) if (true) null: null}; } @@ -46,31 +44,29 @@ void main() { } test_ifElement_notConstCondition() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void main() { bool notConst = true; const {1: null, if (notConst) null: null}; +// ^^^^^^^^ +// [diag.nonConstantMapElement] The elements in a const map literal must be constant. } -''', - [error(diag.nonConstantMapElement, 60, 8)], - ); +'''); } test_ifElementWithElse_mayBeConst() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void main() { const isTrue = true; const {1: null, if (isTrue) null: null else null: null}; +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. } -''', - [error(diag.deadCode, 83, 10)], - ); +'''); } test_spreadElement_mayBeConst() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void main() { const {1: null, ...{null: null}}; } @@ -78,110 +74,98 @@ void main() { } test_spreadElement_notConst() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void main() { var notConst = {}; const {1: null, ...notConst}; +// ^^^^^^^^ +// [diag.nonConstantMapElement] The elements in a const map literal must be constant. } -''', - [error(diag.nonConstantMapElement, 56, 8)], - ); +'''); } } @reflectiveTest -class NonConstantMapKeyTest extends PubPackageResolutionTest - with NonConstantMapKeyTestCases {} - -@reflectiveTest -mixin NonConstantMapKeyTestCases on PubPackageResolutionTest { +class NonConstantMapKeyTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) 0: 0 else a: 0}; -''', - [error(diag.nonConstantMapKey, 67, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_ifElement_thenElseFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) a: 0 else 0: 0}; -''', - [error(diag.nonConstantMapKey, 57, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_ifElement_thenElseTrue_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) 0: 0 else a: 0}; -''', - [error(diag.nonConstantMapKey, 67, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_ifElement_thenElseTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) a: 0 else 0: 0}; -''', - [error(diag.nonConstantMapKey, 57, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_ifElement_thenFalse_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (1 < 0) a: 0}; '''); } test_const_ifElement_thenFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) a: 0}; -''', - [error(diag.nonConstantMapKey, 57, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_ifElement_thenTrue_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (1 > 0) a: 0}; '''); } test_const_ifElement_thenTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) a: 0}; -''', - [error(diag.nonConstantMapKey, 57, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_topVar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {a: 0}; -''', - [error(diag.nonConstantMapKey, 46, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_nonConst_topVar() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = {a: 0}; '''); @@ -189,96 +173,86 @@ var v = {a: 0}; } @reflectiveTest -class NonConstantMapValueTest extends PubPackageResolutionTest - with NonConstantMapValueTestCases {} - -mixin NonConstantMapValueTestCases on PubPackageResolutionTest { +class NonConstantMapValueTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) 0: 0 else 0: a}; -''', - [error(diag.nonConstantMapValue, 70, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_ifElement_thenElseFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) 0: a else 0: 0}; -''', - [error(diag.nonConstantMapValue, 60, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_ifElement_thenElseTrue_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) 0: 0 else 0: a}; -''', - [error(diag.nonConstantMapValue, 70, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_ifElement_thenElseTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) 0: a else 0: 0}; -''', - [error(diag.nonConstantMapValue, 60, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_ifElement_thenFalse_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (1 < 0) 0: a}; '''); } test_const_ifElement_thenFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) 0: a}; -''', - [error(diag.nonConstantMapValue, 60, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_ifElement_thenTrue_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (1 > 0) 0: a}; '''); } test_const_ifElement_thenTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) 0: a}; -''', - [error(diag.nonConstantMapValue, 60, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_topVar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {0: a}; -''', - [error(diag.nonConstantMapValue, 49, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_nonConst_topVar() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = {0: a}; '''); diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart index c328e991f03..8e329bbb227 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart @@ -6,19 +6,18 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantMapKeyFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantMapKeyFromDeferredLibraryTest extends PubPackageResolutionTest - with NonConstantMapKeyFromDeferredLibraryTestCases {} - -mixin NonConstantMapKeyFromDeferredLibraryTestCases - on PubPackageResolutionTest { +class NonConstantMapKeyFromDeferredLibraryTest + extends PubPackageResolutionTest { @failingTest test_const_ifElement_thenTrue_deferredElse() async { // reports wrong error code @@ -37,37 +36,34 @@ var v = const { if (cond) 0: 1 else a.c : 0}; test_const_ifElement_thenTrue_deferredThen() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; const cond = true; var v = const { if (cond) a.c : 0}; -''', - [error(diag.nonConstantMapKeyFromDeferredLibrary, 81, 1)], - ); +// ^ +// [diag.nonConstantMapKeyFromDeferredLibrary] Constant values from a deferred library can't be used as keys in a 'const' map literal. +'''); } test_const_topLevel_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const {a.c : 0}; -''', - [error(diag.nonConstantMapKeyFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.nonConstantMapKeyFromDeferredLibrary] Constant values from a deferred library can't be used as keys in a 'const' map literal. +'''); } test_const_topLevel_deferred_nested() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const {a.c + 1 : 0}; -''', - [error(diag.nonConstantMapKeyFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.nonConstantMapKeyFromDeferredLibrary] Constant values from a deferred library can't be used as keys in a 'const' map literal. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart index 37b2da45d81..f79eaf5d76a 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart @@ -2,51 +2,46 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantMapKeyTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantMapKeyTest extends PubPackageResolutionTest - with NonConstantMapKeyTestCases {} - -mixin NonConstantMapKeyTestCases on PubPackageResolutionTest { +class NonConstantMapKeyTest extends PubPackageResolutionTest { test_const_ifElement_thenTrue_elseFinal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; const cond = true; var v = const {if (cond) 0: 1 else a : 0}; -''', - [error(diag.nonConstantMapKey, 75, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_ifElement_thenTrue_thenFinal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; const cond = true; var v = const {if (cond) a : 0}; -''', - [error(diag.nonConstantMapKey, 65, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } test_const_topLevel() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; var v = const {a : 0}; -''', - [error(diag.nonConstantMapKey, 36, 1)], - ); +// ^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_pattern_key_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_pattern_key_test.dart index ffd8a0a3c68..b7e653cbdeb 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_map_pattern_key_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_pattern_key_test.dart @@ -2,47 +2,46 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantMapPatternKeyTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantMapPatternKeyTest extends PubPackageResolutionTest { test_formalParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(x, int a) { if (x case {a: 0}) {} +// ^ +// [diag.nonConstantMapPatternKey] Key expressions in map patterns must be constants. } -''', - [error(diag.nonConstantMapPatternKey, 33, 1)], - ); +'''); } test_instanceCreation_noConst() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { if (x case {A(): 0}) {} +// ^^^ +// [diag.nonConstantMapPatternKey] Key expressions in map patterns must be constants. } class A { const A(); } -''', - [error(diag.nonConstantMapPatternKey, 26, 3)], - ); +'''); } test_integerLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { if (x case {0: 1}) {} } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart index dc9292c886c..0f02ed2a989 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart @@ -6,20 +6,18 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantMapValueFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantMapValueFromDeferredLibraryTest - extends PubPackageResolutionTest - with NonConstantMapValueFromDeferredLibraryTestCases {} - -mixin NonConstantMapValueFromDeferredLibraryTestCases - on PubPackageResolutionTest { + extends PubPackageResolutionTest { @failingTest test_const_ifElement_thenTrue_elseDeferred() async { // reports wrong error code @@ -38,37 +36,34 @@ var v = const { if (cond) 'a': 'b' else 'c' : a.c}; test_const_ifElement_thenTrue_thenDeferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; const cond = true; var v = const { if (cond) 'a' : a.c}; -''', - [error(diag.nonConstantMapValueFromDeferredLibrary, 87, 1)], - ); +// ^ +// [diag.nonConstantMapValueFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' map literal. +'''); } test_const_topLevel_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const {'a' : a.c}; -''', - [error(diag.nonConstantMapValueFromDeferredLibrary, 57, 1)], - ); +// ^ +// [diag.nonConstantMapValueFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' map literal. +'''); } test_const_topLevel_deferred_nested() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const {'a' : a.c + 1}; -''', - [error(diag.nonConstantMapValueFromDeferredLibrary, 57, 1)], - ); +// ^ +// [diag.nonConstantMapValueFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' map literal. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart index fbd181c5e32..5a8e7cb8da3 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart @@ -2,51 +2,46 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantMapValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantMapValueTest extends PubPackageResolutionTest - with NonConstantMapValueTestCases {} - -mixin NonConstantMapValueTestCases on PubPackageResolutionTest { +class NonConstantMapValueTest extends PubPackageResolutionTest { test_const_ifTrue_elseFinal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; const cond = true; var v = const {if (cond) 'a': 'b', 'c' : a}; -''', - [error(diag.nonConstantMapValue, 81, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_ifTrue_thenFinal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; const cond = true; var v = const {if (cond) 'a' : a}; -''', - [error(diag.nonConstantMapValue, 71, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } test_const_topLevel() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final dynamic a = 0; var v = const {'a' : a}; -''', - [error(diag.nonConstantMapValue, 42, 1)], - ); +// ^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_record_field_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_record_field_from_deferred_library_test.dart index 7bbd835e91d..3312496267f 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_record_field_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_record_field_from_deferred_library_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantRecordFieldFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -20,13 +21,12 @@ class NonConstantRecordFieldFromDeferredLibraryTest newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const (a.c, ); -''', - [error(diag.nonConstantRecordFieldFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.nonConstantRecordFieldFromDeferredLibrary] Constant values from a deferred library can't be used as fields in a 'const' record literal. +'''); } test_const_notDeferred() async { @@ -34,7 +34,7 @@ var v = const (a.c, ); const int c = 1; const int d = 2; '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' as a; var v = const (a.c, d: a.d); '''); @@ -44,7 +44,7 @@ var v = const (a.c, d: a.d); newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1; '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = (a.c, ); '''); diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_record_field_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_record_field_test.dart index 12fedf81b7d..941bcc06bbd 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_record_field_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_record_field_test.dart @@ -2,41 +2,40 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantRecordFieldTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantRecordFieldTest extends PubPackageResolutionTest { test_const_namedField() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final a = 0; var v = const (a: a); -''', - [error(diag.nonConstantRecordField, 31, 1)], - ); +// ^ +// [diag.nonConstantRecordField] The fields in a const record literal must be constants. +'''); } test_const_positionalField() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final a = 0; var v = const (a, ); -''', - [error(diag.nonConstantRecordField, 28, 1)], - ); +// ^ +// [diag.nonConstantRecordField] The fields in a const record literal must be constants. +'''); } test_nonConst() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' final a = 0; var v = (a, ); '''); diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_relational_pattern_expression_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_relational_pattern_expression_test.dart index 782a4ac657b..74daa820367 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_relational_pattern_expression_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_relational_pattern_expression_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantRelationalPatternExpressionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -23,7 +24,7 @@ class NonConstantRelationalPatternExpressionTest const int a = 0; '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; void f(int x) { @@ -33,7 +34,7 @@ void f(int x) { } test_const_integerLiteral() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { if (x case > 0) {} } @@ -41,7 +42,7 @@ void f(x) { } test_const_localVariable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { const a = 0; if (x case > a) {} @@ -50,7 +51,7 @@ void f(x) { } test_const_topLevelVariable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' const a = 0; void f(x) { @@ -60,26 +61,24 @@ void f(x) { } test_notConst_formalParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(x, int a) { if (x case > a) {} +// ^ +// [diag.nonConstantRelationalPatternExpression] The relational pattern expression must be a constant. } -''', - [error(diag.nonConstantRelationalPatternExpression, 34, 1)], - ); +'''); } test_notConst_topLevelVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final a = 0; void f(x) { if (x case > a) {} +// ^ +// [diag.nonConstantRelationalPatternExpression] The relational pattern expression must be a constant. } -''', - [error(diag.nonConstantRelationalPatternExpression, 41, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart index dfc9bf3cac7..2f72b6485dc 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart @@ -2,128 +2,117 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantSetElementTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest -class NonConstantSetElementTest extends PubPackageResolutionTest - with NonConstantSetElementTestCases {} - -mixin NonConstantSetElementTestCases on PubPackageResolutionTest { +class NonConstantSetElementTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) 0 else a}; -''', - [error(diag.nonConstantSetElement, 59, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_ifElement_thenElseFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) a else 0}; -''', - [error(diag.nonConstantSetElement, 52, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_ifElement_thenElseTrue_finalElse() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) 0 else a}; -''', - [error(diag.nonConstantSetElement, 59, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_ifElement_thenElseTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) a else 0}; -''', - [error(diag.nonConstantSetElement, 52, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_ifElement_thenFalse_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (1 < 0) a}; '''); } test_const_ifElement_thenFalse_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 < 0) a}; -''', - [error(diag.nonConstantSetElement, 52, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_ifElement_thenTrue_constThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' const dynamic a = 0; var v = const {if (1 > 0) a}; '''); } test_const_ifElement_thenTrue_finalThen() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {if (1 > 0) a}; -''', - [error(diag.nonConstantSetElement, 52, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_parameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(a) { return const {a}; -}''', - [error(diag.nonConstantSetElement, 23, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +}'''); } test_const_spread_final() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final Set x = {}; var v = const {...x}; -''', - [error(diag.nonConstantSetElement, 36, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_const_topVar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = const {a}; -''', - [error(diag.nonConstantSetElement, 41, 1)], - ); +// ^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +'''); } test_nonConst_topVar() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' final dynamic a = 0; var v = {a}; '''); diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_type_argument_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_type_argument_test.dart index 6fbf4273c0c..8deaa5c1eae 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_type_argument_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_type_argument_test.dart @@ -2,40 +2,40 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantTypeArgumentTest); defineReflectiveTests(NonConstantTypeArgumentWarningTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonConstantTypeArgumentTest extends PubPackageResolutionTest { test_asFunction_R() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef T = int Function(int); class C { void f(Pointer> p) { p.asFunction(); +// ^ +// [diag.nonConstantTypeArgument] The type arguments to 'asFunction' must be known at compile time, so they can't be type parameters. } } -''', - [error(diag.nonConstantTypeArgument, 147, 1)], - ); +'''); } } @reflectiveTest class NonConstantTypeArgumentWarningTest extends PubPackageResolutionTest { test_ref_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class MyStruct extends Struct { @@ -51,7 +51,7 @@ void main() { } test_ref_class_cascade() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class MyStruct extends Struct { @@ -68,19 +68,18 @@ void main() { } test_ref_typeParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; T genericRef(Pointer p) => p.ref; -''', - [error(diag.nonConstantTypeArgument, 72, 5)], - ); +// ^^^^^ +// [diag.nonConstantTypeArgument] The type arguments to 'ref' must be known at compile time, so they can't be type parameters. +'''); } test_refWithFinalizer_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class MyStruct extends Struct { @@ -96,7 +95,7 @@ void main() { } test_refWithFinalizer_class_cascade() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class MyStruct extends Struct { @@ -113,14 +112,13 @@ void main() { } test_refWithFinalizer_typeParameter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; T genericRefWithFinalizer(Pointer p) => p.refWithFinalizer(nullptr); -''', - [error(diag.nonConstantTypeArgument, 85, 27)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.nonConstantTypeArgument] The type arguments to 'refWithFinalizer' must be known at compile time, so they can't be type parameters. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_covariant_type_parameter_position_in_representation_type_test.dart b/pkg/analyzer/test/src/diagnostics/non_covariant_type_parameter_position_in_representation_type_test.dart index c54aa84eedc..b1f19212fac 100644 --- a/pkg/analyzer/test/src/diagnostics/non_covariant_type_parameter_position_in_representation_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_covariant_type_parameter_position_in_representation_type_test.dart @@ -2,16 +2,17 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests( NonCovariantTypeParameterPositionInRepresentationTypeTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,38 +20,24 @@ main() { class NonCovariantTypeParameterPositionInRepresentationTypeTest extends PubPackageResolutionTest { test_contravariant() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(void Function(T) it) {} -''', - [ - error( - diag.nonCovariantTypeParameterPositionInRepresentationType, - 17, - 1, - ), - ], - ); +// ^ +// [diag.nonCovariantTypeParameterPositionInRepresentationType] An extension type parameter can't be used in a non-covariant position of its representation type. +'''); } test_covariant() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(T Function() it) {} '''); } test_invariant() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(T Function(T) it) {} -''', - [ - error( - diag.nonCovariantTypeParameterPositionInRepresentationType, - 17, - 1, - ), - ], - ); +// ^ +// [diag.nonCovariantTypeParameterPositionInRepresentationType] An extension type parameter can't be used in a non-covariant position of its representation type. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_exhaustive_switch_test.dart b/pkg/analyzer/test/src/diagnostics/non_exhaustive_switch_test.dart index f99d597e4d4..e86e2b6dca7 100644 --- a/pkg/analyzer/test/src/diagnostics/non_exhaustive_switch_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_exhaustive_switch_test.dart @@ -2,35 +2,35 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonExhaustiveSwitchExpressionTest); defineReflectiveTests(NonExhaustiveSwitchStatementTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonExhaustiveSwitchExpressionTest extends PubPackageResolutionTest { test_bool_true() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' Object f(bool x) { return switch (x) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpression] The type 'bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'. true => 0, }; } -''', - [error(diag.nonExhaustiveSwitchExpression, 28, 6)], - ); +'''); } test_bool_true_false() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Object f(bool x) { return switch (x) { true => 1, @@ -41,7 +41,7 @@ Object f(bool x) { } test_class_int_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Object f(int x) { return switch (x) { 0 => 0, @@ -52,7 +52,7 @@ Object f(int x) { } test_class_withField_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Object f(int x) { return switch (x) { int(isEven: true) => 0, @@ -63,37 +63,28 @@ Object f(int x) { } test_enum_2at2_hasWhen() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a, b } Object f(E x) { return switch (x) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpression] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.a'. E.a when 1 == 0 => 0, E.b => 1, }; } -''', - [ - error( - diag.nonExhaustiveSwitchExpression, - 44, - 6, - correctionContains: 'E.a', - ), - ], - ); +'''); } test_invalidType_empty() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Unresolved x) => switch (x) {}; -''', - [error(diag.undefinedClass, 7, 10)], - ); +// ^^^^^^^^^^ +// [diag.undefinedClass] Undefined class 'Unresolved'. +'''); } test_private_enum() async { @@ -101,90 +92,84 @@ void f(Unresolved x) => switch (x) {}; enum _E { a, b } _E e() => _E.a; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_enum.dart'; Object f() { return switch (e()) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpressionPrivate] The enum '_E' isn't exhaustively matched by the switch cases because some of the enum constants are private. }; } -''', - [error(diag.nonExhaustiveSwitchExpressionPrivate, 51, 6)], - ); +'''); } test_private_enum_sameLibrary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum _E { a, b } +// ^ +// [diag.unusedField] The value of the field 'a' isn't used. +// ^ +// [diag.unusedField] The value of the field 'b' isn't used. Object f(_E e) { return switch (e) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpression] The type '_E' isn't exhaustively matched by the switch cases since it doesn't match the pattern '_E.a'. }; } -''', - [ - error(diag.unusedField, 10, 1), - error(diag.unusedField, 13, 1), - error(diag.nonExhaustiveSwitchExpression, 44, 6), - ], - ); +'''); } test_private_enumConstant() async { newFile(join(testPackageLibPath, 'private_enum.dart'), r''' enum E { a, b, _c } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_enum.dart'; Object f(E e) { return switch (e) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpression] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'. E.a => 0, }; } -''', - [error(diag.nonExhaustiveSwitchExpression, 54, 6)], - ); +'''); } test_private_enumConstant_only() async { newFile(join(testPackageLibPath, 'private_enum.dart'), r''' enum E { a, b, _c } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_enum.dart'; Object f(E e) { return switch (e) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpressionPrivate] The enum 'E' isn't exhaustively matched by the switch cases because some of the enum constants are private. E.a => 0, E.b => 1, }; } -''', - [error(diag.nonExhaustiveSwitchExpressionPrivate, 54, 6)], - ); +'''); } test_private_enumConstant_sameLibrary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' enum E { a, b, _c } +// ^^ +// [diag.unusedField] The value of the field '_c' isn't used. Object f(E e) { return switch (e) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpression] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E._c'. E.a => 0, E.b => 1, }; } -''', - [ - error(diag.unusedField, 15, 2), - error(diag.nonExhaustiveSwitchExpression, 45, 6), - ], - ); +'''); } test_private_sealed() async { @@ -193,38 +178,36 @@ sealed class _A {} class B extends _A {} _A a() => B(); '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_sealed.dart'; Object f() { return switch (a()) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchExpression] The type '_A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'B()'. }; } -''', - [error(diag.nonExhaustiveSwitchExpression, 53, 6)], - ); +'''); } } @reflectiveTest class NonExhaustiveSwitchStatementTest extends PubPackageResolutionTest { test_alwaysExhaustive_bool_true() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'. case true: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 19, 6)], - ); +'''); } test_alwaysExhaustive_bool_true_false() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool x) { switch (x) { case true: @@ -236,7 +219,7 @@ void f(bool x) { } test_alwaysExhaustive_bool_wildcard_typed_bool() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool x) { switch (x) { case bool _: @@ -247,24 +230,22 @@ void f(bool x) { } test_alwaysExhaustive_bool_wildcard_typed_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'true'. case int _: +// ^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'bool' can never match the required type 'int'. break; } } -''', - [ - error(diag.nonExhaustiveSwitchStatement, 19, 6), - error(diag.patternNeverMatchesValueType, 41, 3), - ], - ); +'''); } test_alwaysExhaustive_bool_wildcard_untyped() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool x) { switch (x) { case _: @@ -275,22 +256,21 @@ void f(bool x) { } test_alwaysExhaustive_boolNullable_true_false() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool? x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'bool?' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'null'. case true: case false: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 20, 6)], - ); +'''); } test_alwaysExhaustive_boolNullable_true_false_null() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool? x) { switch (x) { case true: @@ -303,25 +283,24 @@ void f(bool? x) { } test_alwaysExhaustive_enum_2at1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a, b } void f(E x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'. case E.a: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 35, 6)], - ); +'''); } test_alwaysExhaustive_enum_2at2_cases() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a, b } @@ -337,33 +316,25 @@ void f(E x) { } test_alwaysExhaustive_enum_2at2_hasWhen() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a, b } void f(E x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.a'. case E.a when 1 == 0: case E.b: break; } } -''', - [ - error( - diag.nonExhaustiveSwitchStatement, - 35, - 6, - correctionContains: 'E.a', - ), - ], - ); +'''); } test_alwaysExhaustive_enum_2at2_logicalOr() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a, b } @@ -378,10 +349,13 @@ void f(E x) { } test_alwaysExhaustive_enum_cannotCompute() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v1(v2), v2(v1); +//^^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. +// ^^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. const E(Object f); } @@ -392,27 +366,21 @@ void f(E x) { break; } } -''', - [ - error(diag.recursiveCompileTimeConstant, 11, 2), - error(diag.recursiveCompileTimeConstant, 19, 2), - ], - ); +'''); } test_alwaysExhaustive_Null_hasError() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Null x) { switch (x) {} +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'Null' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'null'. } -''', - [error(diag.nonExhaustiveSwitchStatement, 19, 6)], - ); +'''); } test_alwaysExhaustive_Null_noError() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Null x) { switch (x) { case null: @@ -423,7 +391,7 @@ void f(Null x) { } test_alwaysExhaustive_recordType_bool_bool_4at4() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f((bool, bool) x) { switch (x) { case (false, false): @@ -437,25 +405,24 @@ void f((bool, bool) x) { } test_alwaysExhaustive_sealedClass_2at1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} class C extends A {} void f(A x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'C()'. case B(): break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 77, 6)], - ); +'''); } test_alwaysExhaustive_sealedClass_2at2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} class C extends A {} @@ -472,7 +439,7 @@ void f(A x) { } test_alwaysExhaustive_sealedClass_2at2_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} class C extends A {} @@ -489,8 +456,7 @@ void f(A x) { } test_alwaysExhaustive_sealedClass_constraintsMixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} @@ -499,17 +465,17 @@ mixin M on A {} void f(A x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'M()'. case B _: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 74, 6)], - ); +'''); } test_alwaysExhaustive_sealedClass_hasExtensionType_1of1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} extension type EA(A it) implements A {} @@ -524,8 +490,7 @@ void f(A x) { } test_alwaysExhaustive_sealedClass_hasExtensionType_1of2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} class C extends A {} @@ -533,18 +498,17 @@ extension type EA(A it) implements A {} void f(A x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'C()'. case B(): break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 117, 6)], - ); +'''); } test_alwaysExhaustive_sealedClass_implementedByEnum_3at2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B implements A {} @@ -555,18 +519,18 @@ enum E implements A { void f(A x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'. case B _: case E.a: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 92, 6)], - ); +'''); } test_alwaysExhaustive_sealedClass_implementedByEnum_3at3() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B implements A {} @@ -587,8 +551,7 @@ void f(A x) { } test_alwaysExhaustive_sealedClass_implementedByMixin_2at1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B implements A {} @@ -597,17 +560,17 @@ mixin M implements A {} void f(A x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'M()'. case B _: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 85, 6)], - ); +'''); } test_alwaysExhaustive_sealedClass_implementedByMixin_2at2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B implements A {} @@ -625,55 +588,52 @@ void f(A x) { } test_alwaysExhaustive_sealedClass_unresolvedIdentifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} void f(A x) { switch (x) { case unresolved: +// ^^^^^^^^^^ +// [diag.undefinedIdentifier] Undefined name 'unresolved'. break; } } -''', - [error(diag.undefinedIdentifier, 78, 10)], - ); +'''); } test_alwaysExhaustive_sealedClass_unresolvedObject() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} class B extends A {} void f(A x) { switch (x) { case Unresolved(): +// ^^^^^^^^^^ +// [diag.undefinedClass] Undefined class 'Unresolved'. break; } } -''', - [error(diag.undefinedClass, 78, 10)], - ); +'''); } test_alwaysExhaustive_typeVariable_bound_bool_true() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { switch (x) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'T' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'. case true: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 32, 6)], - ); +'''); } test_alwaysExhaustive_typeVariable_bound_bool_true_false() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { switch (x) { case true: @@ -685,23 +645,22 @@ void f(T x) { } test_alwaysExhaustive_typeVariable_promoted_bool_true() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { if (x is bool) { switch (x) { +// ^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'T & bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'. case true: break; } } } -''', - [error(diag.nonExhaustiveSwitchStatement, 40, 6)], - ); +'''); } test_alwaysExhaustive_typeVariable_promoted_bool_true_false() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { if (x is bool) { switch (x) { @@ -715,18 +674,17 @@ void f(T x) { } test_invalidType_empty() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Unresolved x) { +// ^^^^^^^^^^ +// [diag.undefinedClass] Undefined class 'Unresolved'. switch (x) {} } -''', - [error(diag.undefinedClass, 7, 10)], - ); +'''); } test_notAlwaysExhaustive_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { case 0: @@ -741,56 +699,53 @@ void f(int x) { enum _E { a, b } _E e() => _E.a; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_enum.dart'; void f() { switch (e()) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatementPrivate] The enum '_E' isn't exhaustively matched by the switch cases because some of the enum constants are private. } } -''', - [error(diag.nonExhaustiveSwitchStatementPrivate, 42, 6)], - ); +'''); } test_private_enumConstant() async { newFile(join(testPackageLibPath, 'private_enum.dart'), r''' enum E { a, b, _c } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_enum.dart'; void f(E e) { switch (e) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'. case E.a: break; } } -''', - [error(diag.nonExhaustiveSwitchStatement, 45, 6)], - ); +'''); } test_private_enumConstant_only() async { newFile(join(testPackageLibPath, 'private_enum.dart'), r''' enum E { a, b, _c } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_enum.dart'; void f(E e) { switch (e) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatementPrivate] The enum 'E' isn't exhaustively matched by the switch cases because some of the enum constants are private. case E.a: case E.b: break; } } -''', - [error(diag.nonExhaustiveSwitchStatementPrivate, 45, 6)], - ); +'''); } test_private_sealed() async { @@ -799,16 +754,15 @@ sealed class _A {} class B extends _A {} _A a() => B(); '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'private_sealed.dart'; Object f() { switch (a()) { +//^^^^^^ +// [diag.nonExhaustiveSwitchStatement] The type '_A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'B()'. } } -''', - [error(diag.nonExhaustiveSwitchStatement, 46, 6)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_final_field_in_enum_test.dart b/pkg/analyzer/test/src/diagnostics/non_final_field_in_enum_test.dart index 91d8bb60f4a..18fb570e3aa 100644 --- a/pkg/analyzer/test/src/diagnostics/non_final_field_in_enum_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_final_field_in_enum_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonFinalFieldInEnumTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonFinalFieldInEnumTest extends PubPackageResolutionTest { test_declaringFormalParameter_optionalNamed_typeInt_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E({final int foo = 0}) { v(foo: 0); } @@ -24,18 +25,17 @@ enum E({final int foo = 0}) { } test_declaringFormalParameter_optionalNamed_typeInt_var() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E({var int foo = 0}) { +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. v(foo: 0); } -''', - [error(diag.nonFinalFieldInEnum, 16, 3)], - ); +'''); } test_declaringFormalParameter_optionalPositional_typeInt_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E([final int foo = 0]) { v(0); } @@ -43,18 +43,17 @@ enum E([final int foo = 0]) { } test_declaringFormalParameter_optionalPositional_typeInt_var() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E([var int foo = 0]) { +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. v(0); } -''', - [error(diag.nonFinalFieldInEnum, 16, 3)], - ); +'''); } test_declaringFormalParameter_requiredNamed_typeInt_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E({required final int foo}) { v(foo: 0); } @@ -62,18 +61,17 @@ enum E({required final int foo}) { } test_declaringFormalParameter_requiredNamed_typeInt_var() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E({required var int foo}) { +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. v(foo: 0); } -''', - [error(diag.nonFinalFieldInEnum, 25, 3)], - ); +'''); } test_declaringFormalParameter_requiredPositional_functionTyped_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E(final void foo()?) { v(null); } @@ -81,18 +79,17 @@ enum E(final void foo()?) { } test_declaringFormalParameter_requiredPositional_functionTyped_var() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(var void foo()?) { +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. v(null); } -''', - [error(diag.nonFinalFieldInEnum, 16, 3)], - ); +'''); } test_declaringFormalParameter_requiredPositional_typeInt_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E(final int foo) { v(0); } @@ -100,42 +97,39 @@ enum E(final int foo) { } test_declaringFormalParameter_requiredPositional_typeInt_var() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(var int foo) { +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. v(0); } -''', - [error(diag.nonFinalFieldInEnum, 15, 3)], - ); +'''); } test_fieldDeclaration_instance() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int foo = 0; +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. } -''', - [error(diag.nonFinalFieldInEnum, 20, 3)], - ); +'''); } test_fieldDeclaration_instance_covariant() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; covariant int foo = 0; +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. } -''', - [error(diag.nonFinalFieldInEnum, 30, 3)], - ); +'''); } test_fieldDeclaration_instance_external() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; external int foo; @@ -144,7 +138,7 @@ enum E { } test_fieldDeclaration_instance_external_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; external final int foo; @@ -153,7 +147,7 @@ enum E { } test_fieldDeclaration_instance_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int foo = 0; @@ -162,19 +156,18 @@ enum E { } test_fieldDeclaration_instance_late() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; late int foo = 0; +// ^^^ +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. } -''', - [error(diag.nonFinalFieldInEnum, 25, 3)], - ); +'''); } test_fieldDeclaration_static() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int foo = 0; @@ -183,7 +176,7 @@ enum E { } test_fieldDeclaration_static_final() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static final int foo = 0; diff --git a/pkg/analyzer/test/src/diagnostics/non_generative_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/non_generative_constructor_test.dart index 42a5905cb20..0b1c7822c94 100644 --- a/pkg/analyzer/test/src/diagnostics/non_generative_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_generative_constructor_test.dart @@ -2,81 +2,78 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonGenerativeConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonGenerativeConstructorTest extends PubPackageResolutionTest { test_factory_explicit_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A.named() => throw 0; A.generative(); } class B extends A { B() : super.named(); +// ^^^^^^^^^^^^^ +// [diag.nonGenerativeConstructor] The generative constructor 'A.named()' is expected, but a factory was found. } -''', - [error(diag.nonGenerativeConstructor, 90, 13)], - ); +'''); } test_factory_explicit_primaryConstructor_hasBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A.named() => throw 0; A.generative(); } class B() extends A { this : super.named(); +// ^^^^^^^^^^^^^ +// [diag.nonGenerativeConstructor] The generative constructor 'A.named()' is expected, but a factory was found. } -''', - [error(diag.nonGenerativeConstructor, 93, 13)], - ); +'''); } test_factory_implicit_constructor_newHead() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw 0; A.named(); } class B extends A { new foo(); +//^^^^^^^ +// [diag.nonGenerativeConstructor] The generative constructor 'A()' is expected, but a factory was found. } -''', - [error(diag.nonGenerativeConstructor, 73, 7)], - ); +'''); } test_factory_implicit_constructor_typeName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw 0; A.named(); } class B extends A { B.foo(); +//^^^^^ +// [diag.nonGenerativeConstructor] The generative constructor 'A()' is expected, but a factory was found. } -''', - [error(diag.nonGenerativeConstructor, 73, 5)], - ); +'''); } test_factory_implicit_constructor_typeName_external() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named() {} factory A() => throw 0; @@ -88,22 +85,21 @@ class B extends A { } test_factory_implicit_primaryConstructor_hasBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw 0; A.named(); } class B() extends A { this; +//^^^^ +// [diag.nonGenerativeConstructor] The generative constructor 'A()' is expected, but a factory was found. } -''', - [error(diag.nonGenerativeConstructor, 75, 4)], - ); +'''); } test_generative_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named() {} factory A() => throw 0; @@ -115,7 +111,7 @@ class B extends A { } test_generative_primaryConstructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named() {} factory A() => throw 0; @@ -127,7 +123,7 @@ class B() extends A { } test_generative_primaryContructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named() {} factory A() => throw 0; diff --git a/pkg/analyzer/test/src/diagnostics/non_generative_implicit_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/non_generative_implicit_constructor_test.dart index 4c74a2051f4..4b144113544 100644 --- a/pkg/analyzer/test/src/diagnostics/non_generative_implicit_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_generative_implicit_constructor_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonGenerativeImplicitConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -25,7 +26,7 @@ augment class B { } '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.dart'; class A {} @@ -34,16 +35,15 @@ class B extends A {} } test_implicit() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => throw 0; A.named(); } class B extends A { +// ^ +// [diag.nonGenerativeImplicitConstructor] The unnamed constructor of superclass 'A' (called by the default constructor of 'B') must be a generative constructor, but factory found. } -''', - [error(diag.nonGenerativeImplicitConstructor, 57, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_native_function_type_argument_to_pointer_test.dart b/pkg/analyzer/test/src/diagnostics/non_native_function_type_argument_to_pointer_test.dart index 55a6d97adca..573c6a30f38 100644 --- a/pkg/analyzer/test/src/diagnostics/non_native_function_type_argument_to_pointer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_native_function_type_argument_to_pointer_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonNativeFunctionTypeArgumentToPointerTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,57 +18,50 @@ main() { class NonNativeFunctionTypeArgumentToPointerTest extends PubPackageResolutionTest { test_asFunction_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef R = Int8 Function(Int8); class C { void f(Pointer p) { p.asFunction(); +// ^^^^^^^^^^ +// [diag.undefinedMethod] The method 'asFunction' isn't defined for the type 'Pointer'. } } -''', - [ - // This changed from a method to a extension method, uses Dart semantics - // instead of manual check now. - error(diag.undefinedMethod, 98, 10), - ], - ); +'''); } test_asFunction_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef TPrime = int Function(int); typedef F = String Function(String); class C { void f(Pointer> p) { p.asFunction(); +// ^ +// [diag.nonNativeFunctionTypeArgumentToPointer] Can't invoke 'asFunction' because the function signature 'NativeFunction' for the pointer isn't a valid C function signature. } } -''', - [error(diag.nonNativeFunctionTypeArgumentToPointer, 165, 1)], - ); +'''); } test_asFunction_F() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef R = int Function(int); class C { void f(Pointer> p) { p.asFunction(); +// ^ +// [diag.nonConstantTypeArgument] The type arguments to 'asFunction' must be known at compile time, so they can't be type parameters. } } -''', - [error(diag.nonConstantTypeArgument, 125, 1)], - ); +'''); } test_asFunction_Pointer_Opaque() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; main() { DynamicLibrary.open('dontcare') diff --git a/pkg/analyzer/test/src/diagnostics/non_nullable_equals_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/non_nullable_equals_parameter_test.dart index fddea8deeaa..537c98097ed 100644 --- a/pkg/analyzer/test/src/diagnostics/non_nullable_equals_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_nullable_equals_parameter_test.dart @@ -2,52 +2,50 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonNullableEqualsParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonNullableEqualsParameterTest extends PubPackageResolutionTest { test_dynamic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { @override bool operator ==(dynamic other) => false; +// ^^ +// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable. } -''', - [error(diag.nonNullableEqualsParameter, 38, 2)], - ); +'''); } test_inheritedDynamic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { @override bool operator ==(dynamic other) => false; +// ^^ +// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable. } class D extends C { @override bool operator ==(other) => false; +// ^^ +// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable. } -''', - [ - error(diag.nonNullableEqualsParameter, 38, 2), - error(diag.nonNullableEqualsParameter, 116, 2), - ], - ); +'''); } test_inheritedFromObject() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { @override bool operator ==(other) => false; @@ -56,7 +54,7 @@ class C { } test_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { @override bool operator ==(covariant int other) => false; @@ -65,19 +63,18 @@ class C { } test_nullableObject() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { @override bool operator ==(Object? other) => false; +// ^^ +// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable. } -''', - [error(diag.nonNullableEqualsParameter, 38, 2)], - ); +'''); } test_object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { @override bool operator ==(Object other) => false; diff --git a/pkg/analyzer/test/src/diagnostics/non_positive_array_dimension_test.dart b/pkg/analyzer/test/src/diagnostics/non_positive_array_dimension_test.dart index 54c01cb5498..32aed29c6ef 100644 --- a/pkg/analyzer/test/src/diagnostics/non_positive_array_dimension_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_positive_array_dimension_test.dart @@ -2,49 +2,48 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonPositiveArrayDimensionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonPositiveArrayDimensionTest extends PubPackageResolutionTest { test_multi_negative() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @Array.multi([-1]) +// ^^ +// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers. external Array a0; } -''', - [error(diag.nonPositiveArrayDimension, 74, 2)], - ); +'''); } test_multi_oneOfMany() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @Array.multi([1, 2, 3, -4, 5, 6]) +// ^^ +// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers. external Array>>>>> a0; } -''', - [error(diag.nonPositiveArrayDimension, 83, 2)], - ); +'''); } test_multi_positive() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @@ -55,35 +54,33 @@ final class MyStruct extends Struct { } test_multi_zero() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @Array.multi([0]) +// ^ +// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers. external Array a0; } -''', - [error(diag.nonPositiveArrayDimension, 74, 1)], - ); +'''); } test_single_negative() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @Array(-12) +// ^^^ +// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers. external Array a0; } -''', - [error(diag.nonPositiveArrayDimension, 67, 3)], - ); +'''); } test_single_positive() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @@ -94,16 +91,15 @@ final class MyStruct extends Struct { } test_single_zero() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import "dart:ffi"; final class MyStruct extends Struct { @Array(0) +// ^ +// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers. external Array a0; } -''', - [error(diag.nonPositiveArrayDimension, 67, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_redirecting_generative_constructor_with_primary_test.dart b/pkg/analyzer/test/src/diagnostics/non_redirecting_generative_constructor_with_primary_test.dart index a58429d13dc..856eae25e7a 100644 --- a/pkg/analyzer/test/src/diagnostics/non_redirecting_generative_constructor_with_primary_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_redirecting_generative_constructor_with_primary_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonRedirectingGenerativeConstructorWithPrimaryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +18,7 @@ main() { class NonRedirectingGenerativeConstructorWithPrimaryTest extends PubPackageResolutionTest { test_class_factory() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C(int x) { factory C.named() => C(0); } @@ -25,30 +26,28 @@ class C(int x) { } test_class_generative_nonRedirecting() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C(int x) { C.named(); +//^^^^^^^ +// [diag.nonRedirectingGenerativeConstructorWithPrimary] Classes with primary constructors can't have non-redirecting generative constructors. } -''', - [error(diag.nonRedirectingGenerativeConstructorWithPrimary, 19, 7)], - ); +'''); } test_class_generative_redirectingToNonPrimary() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C(int x) { C.named1() : this.named2(); C.named2(); +//^^^^^^^^ +// [diag.nonRedirectingGenerativeConstructorWithPrimary] Classes with primary constructors can't have non-redirecting generative constructors. } -''', - [error(diag.nonRedirectingGenerativeConstructorWithPrimary, 49, 8)], - ); +'''); } test_class_generative_redirectingToPrimary() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C(int x) { C.named() : this(0); } @@ -56,7 +55,7 @@ class C(int x) { } test_class_noPrimaryConstructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { C.named(); } @@ -64,7 +63,7 @@ class C { } test_enum_factory() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E(int x) { v(0); factory E.named() => E.v; @@ -73,34 +72,31 @@ enum E(int x) { } test_enum_generative_nonRedirecting() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(int x) { v(0); const E.named(); +// ^^^^^^^ +// [diag.nonRedirectingGenerativeConstructorWithPrimary] Classes with primary constructors can't have non-redirecting generative constructors. +// ^^^^^ +// [diag.unusedElement] The declaration 'E.named' isn't referenced. } -''', - [ - error(diag.nonRedirectingGenerativeConstructorWithPrimary, 32, 7), - error(diag.unusedElement, 34, 5), - ], - ); +'''); } test_enum_generative_redirectingToPrimary() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(int x) { v(0); const E.named(int x) : this(x); +// ^^^^^ +// [diag.unusedElement] The declaration 'E.named' isn't referenced. } -''', - [error(diag.unusedElement, 34, 5)], - ); +'''); } test_enum_noPrimaryConstructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; const E(); @@ -110,7 +106,7 @@ enum E { test_extensionType_generative_nonRedirecting() async { // Extension types can have non-redirecting generative constructors. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int x) { E.named(this.x); } diff --git a/pkg/analyzer/test/src/diagnostics/non_sized_type_argument_test.dart b/pkg/analyzer/test/src/diagnostics/non_sized_type_argument_test.dart index e2c9a3b927d..9b765d1a9c8 100644 --- a/pkg/analyzer/test/src/diagnostics/non_sized_type_argument_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_sized_type_argument_test.dart @@ -2,49 +2,48 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonSizedTypeArgument); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonSizedTypeArgument extends PubPackageResolutionTest { test_invalid_struct() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Array(8) external Array a0; +// ^^^^ +// [diag.nonSizedTypeArgument] The type 'Void' isn't a valid type argument for 'Array'. The type argument must be a native integer, 'Float', 'Double', 'Pointer', or subtype of 'Struct', 'Union', or 'AbiSpecificInteger'. } -''', - [error(diag.nonSizedTypeArgument, 80, 4)], - ); +'''); } test_invalid_union() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Union { @Array(8) external Array a0; +// ^^^^ +// [diag.nonSizedTypeArgument] The type 'Void' isn't a valid type argument for 'Array'. The type argument must be a native integer, 'Float', 'Double', 'Pointer', or subtype of 'Struct', 'Union', or 'AbiSpecificInteger'. } -''', - [error(diag.nonSizedTypeArgument, 79, 4)], - ); +'''); } test_valid() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { diff --git a/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart b/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart index 33fb59792cd..decb4bbbd06 100644 --- a/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_type_as_type_argument_test.dart @@ -2,25 +2,27 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonTypeAsTypeArgumentTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonTypeAsTypeArgumentTest extends PubPackageResolutionTest { test_issue54388() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' sealed class Option {} final class None implements Option { +// ^ +// [diag.nonTypeAsTypeArgument] The name 'A' isn't a type, so it can't be used as a type argument. const None(); } @@ -33,29 +35,25 @@ A doOption( }, ); } -''', - [error(diag.nonTypeAsTypeArgument, 62, 1)], - ); +'''); } test_notAType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int A = 0; class B {} f(B b) {} -''', - [error(diag.nonTypeAsTypeArgument, 29, 1)], - ); +// ^ +// [diag.nonTypeAsTypeArgument] The name 'A' isn't a type, so it can't be used as a type argument. +'''); } test_undefinedIdentifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class B {} f(B b) {} -''', - [error(diag.nonTypeAsTypeArgument, 18, 1)], - ); +// ^ +// [diag.nonTypeAsTypeArgument] The name 'A' isn't a type, so it can't be used as a type argument. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/non_type_in_catch_clause_test.dart b/pkg/analyzer/test/src/diagnostics/non_type_in_catch_clause_test.dart index b153d75142d..795a2199d0f 100644 --- a/pkg/analyzer/test/src/diagnostics/non_type_in_catch_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_type_in_catch_clause_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonTypeInCatchClauseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonTypeInCatchClauseTest extends PubPackageResolutionTest { test_isClass() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() { try { } on String catch (e) { @@ -27,7 +28,7 @@ f() { } test_isFunctionTypeAlias() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F(); f() { try { @@ -39,7 +40,7 @@ f() { } test_isGenericFunctionTypeAlias() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function(T); f() { try { @@ -51,7 +52,7 @@ f() { } test_isInterfaceTypeTypeAlias() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = String; f() { try { @@ -63,7 +64,7 @@ f() { } test_isTypeParameter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { f() { try { @@ -76,36 +77,34 @@ class A { } test_notDefined() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { try { } on T catch (e) { +// ^ +// [diag.nonTypeInCatchClause] The name 'T' isn't a type and can't be used in an on-catch clause. e; } } -''', - [error(diag.nonTypeInCatchClause, 21, 1)], - ); +'''); } test_notType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var T = 0; f() { try { } on T catch (e) { +// ^ +// [diag.nonTypeInCatchClause] The name 'T' isn't a type and can't be used in an on-catch clause. e; } } -''', - [error(diag.nonTypeInCatchClause, 32, 1)], - ); +'''); } test_noType() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() { try { } catch (e) { diff --git a/pkg/analyzer/test/src/diagnostics/non_void_return_for_operator_test.dart b/pkg/analyzer/test/src/diagnostics/non_void_return_for_operator_test.dart index e8a2bb659c7..d23162b0247 100644 --- a/pkg/analyzer/test/src/diagnostics/non_void_return_for_operator_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_void_return_for_operator_test.dart @@ -2,31 +2,31 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonVoidReturnForOperatorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonVoidReturnForOperatorTest extends PubPackageResolutionTest { test_indexSetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { int operator []=(a, b) { return a; } -}''', - [error(diag.nonVoidReturnForOperator, 12, 3)], - ); +//^^^ +// [diag.nonVoidReturnForOperator] The return type of the operator []= must be 'void'. +}'''); } test_no_return() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { operator []=(a, b) {} } @@ -34,7 +34,7 @@ class A { } test_void() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void operator []=(a, b) {} } diff --git a/pkg/analyzer/test/src/diagnostics/non_void_return_for_setter_test.dart b/pkg/analyzer/test/src/diagnostics/non_void_return_for_setter_test.dart index 60874d5176f..146ea1f6031 100644 --- a/pkg/analyzer/test/src/diagnostics/non_void_return_for_setter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_void_return_for_setter_test.dart @@ -2,55 +2,53 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonVoidReturnForSetterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonVoidReturnForSetterTest extends PubPackageResolutionTest { test_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' int set x(int v) { +// [diag.nonVoidReturnForSetter][column 1][length 3] The return type of the setter must be 'void' or absent. return 42; -}''', - [error(diag.nonVoidReturnForSetter, 0, 3)], - ); +}'''); } test_function_no_return() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' set x(v) {} '''); } test_function_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void set x(v) {} '''); } test_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { int set x(int v) { +//^^^ +// [diag.nonVoidReturnForSetter] The return type of the setter must be 'void' or absent. return 42; } -}''', - [error(diag.nonVoidReturnForSetter, 12, 3)], - ); +}'''); } test_method_no_return() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set x(v) {} } @@ -58,7 +56,7 @@ class A { } test_method_void() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void set x(v) {} } diff --git a/pkg/analyzer/test/src/diagnostics/not_a_type_test.dart b/pkg/analyzer/test/src/diagnostics/not_a_type_test.dart index 015e9f3bf43..c7a47f562d1 100644 --- a/pkg/analyzer/test/src/diagnostics/not_a_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_a_type_test.dart @@ -2,74 +2,54 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotATypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NotATypeTest extends PubPackageResolutionTest { test_class_constructor() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { A.foo(); +// ^^^ +// [context 1] The declaration of 'foo' is here. } A.foo bar() {} -''', - [ - error( - diag.notAType, - 24, - 5, - contextMessages: [message(testFile, 14, 3)], - ), - ], - ); +// [diag.notAType][column 1][length 5][context 1] A.foo isn't a type. +'''); } test_class_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { static void foo() {} +// ^^^ +// [context 1] The declaration of 'foo' is here. } A.foo bar() {} -''', - [ - error( - diag.notAType, - 36, - 5, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +// [diag.notAType][column 1][length 5][context 1] A.foo isn't a type. +'''); } test_extension() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension E on int {} +// ^ +// [context 1] The declaration of 'E' is here. E a; -''', - [ - error( - diag.notAType, - 22, - 1, - contextMessages: [message(testFile, 10, 1)], - ), - ], - ); +// [diag.notAType][column 1][length 1][context 1] E isn't a type. +'''); var node = findNode.namedType('E a;'); assertResolvedNodeText(node, r''' @@ -81,16 +61,15 @@ NamedType } test_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() {} +// [context 1][column 1][length 1] The declaration of 'f' is here. main() { f v = null; -}''', - [ - error(diag.notAType, 18, 1, contextMessages: [message(testFile, 0, 1)]), - error(diag.unusedLocalVariable, 20, 1), - ], - ); +//^ +// [diag.notAType][context 1] f isn't a type. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/not_assigned_potentially_non_nullable_local_variable_test.dart b/pkg/analyzer/test/src/diagnostics/not_assigned_potentially_non_nullable_local_variable_test.dart index 7d864687241..9c7fc514033 100644 --- a/pkg/analyzer/test/src/diagnostics/not_assigned_potentially_non_nullable_local_variable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_assigned_potentially_non_nullable_local_variable_test.dart @@ -2,16 +2,17 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests( NotInitializedPotentiallyNonNullableLocalVariableTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,45 +20,44 @@ main() { class NotInitializedPotentiallyNonNullableLocalVariableTest extends PubPackageResolutionTest { test_assignment_leftExpression() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { List v; v[0] = (v = [1, 2])[1]; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. v; } -''', - [_notAssignedError(28, 1)], - ); +'''); } test_assignment_leftLocal_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v += 1; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. v; } -''', - [_notAssignedError(22, 1)], - ); +'''); } test_assignment_leftLocal_compound_assignInRight() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v += (v = v); +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(22, 1), _notAssignedError(32, 1)], - ); +'''); } test_assignment_leftLocal_pure_eq() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v = 0; @@ -67,52 +67,50 @@ void f() { } test_assignment_leftLocal_pure_eq_self() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v = v; +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(26, 1)], - ); +'''); } test_assignment_leftLocal_pure_questionEq() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v ??= 0; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. +// ^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.deadNullAwareExpression] The left operand can't be null, so the right operand is never executed. } -''', - [ - _notAssignedError(22, 1), - error(diag.deadCode, 28, 2), - error(diag.deadNullAwareExpression, 28, 1), - ], - ); +'''); } test_assignment_leftLocal_pure_questionEq_self() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v ??= v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. +// ^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.deadNullAwareExpression] The left operand can't be null, so the right operand is never executed. } -''', - [ - _notAssignedError(22, 1), - error(diag.deadCode, 28, 2), - error(diag.deadNullAwareExpression, 28, 1), - _notAssignedError(28, 1), - ], - ); +'''); } test_basic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; v = 0; @@ -122,37 +120,37 @@ void f() { } test_binaryExpression_ifNull_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; (v = 0) ?? 0; +// ^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.deadNullAwareExpression] The left operand can't be null, so the right operand is never executed. v; } -''', - [error(diag.deadCode, 30, 4), error(diag.deadNullAwareExpression, 33, 1)], - ); +'''); } test_binaryExpression_ifNull_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a) { int v; a ?? (v = 0); +// ^^^^^^^^^^ +// [diag.deadCode] Dead code. +// ^^^^^^^ +// [diag.deadNullAwareExpression] The left operand can't be null, so the right operand is never executed. v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [ - error(diag.deadCode, 29, 10), - error(diag.deadNullAwareExpression, 32, 7), - _notAssignedError(43, 1), - ], - ); +'''); } test_binaryExpression_logicalAnd_left() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; ((v = 0) >= 0) && c; @@ -162,20 +160,19 @@ void f(bool c) { } test_binaryExpression_logicalAnd_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; c && ((v = 0) >= 0); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(51, 1)], - ); +'''); } test_binaryExpression_logicalOr_left() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; ((v = 0) >= 0) || c; @@ -185,20 +182,19 @@ void f(bool c) { } test_binaryExpression_logicalOr_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; c || ((v = 0) >= 0); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(51, 1)], - ); +'''); } test_binaryExpression_plus_left() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' main() { int v; (v = 0) + 1; @@ -208,7 +204,7 @@ main() { } test_binaryExpression_plus_right() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' main() { int v; 1 + (v = 0); @@ -218,7 +214,7 @@ main() { } test_conditional_both() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(bool b) { int v; b ? (v = 1) : (v = 2); @@ -228,33 +224,31 @@ f(bool b) { } test_conditional_else() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(bool b) { int v; b ? 1 : (v = 2); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(42, 1)], - ); +'''); } test_conditional_then() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(bool b) { int v; b ? (v = 1) : 2; v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(42, 1)], - ); +'''); } test_conditionalExpression_condition() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' main() { int v; (v = 0) >= 0 ? 1 : 2; @@ -264,7 +258,7 @@ main() { } test_doWhile_break_afterAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; do { @@ -278,8 +272,7 @@ void f(bool b) { } test_doWhile_break_beforeAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; do { @@ -287,15 +280,14 @@ void f(bool b) { v = 0; } while (b); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(79, 1)], - ); +'''); } test_doWhile_breakOuterFromInner() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2, v3; L1: do { @@ -309,45 +301,42 @@ void f(bool b) { } while (b); v1; v3; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v3' must be assigned before it can be used. } -''', - [_notAssignedError(168, 2)], - ); +'''); } test_doWhile_condition() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v1, v2; do { v1; // assigned in the condition, but not yet +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v1' must be assigned before it can be used. } while ((v1 = 0) + (v2 = 0) >= 0); v2; } -''', - [_notAssignedError(36, 2)], - ); +'''); } test_doWhile_condition_break() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; do { if (b) break; } while ((v = 0) >= 0); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(79, 1)], - ); +'''); } test_doWhile_condition_break_continue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b1, b2) { int v1, v2, v3, v4, v5, v6; do { @@ -359,24 +348,24 @@ void f(bool b1, b2) { v4 = 0; // not visible v5 = 0; // not visible } while ((v6 = v1 + v2 + v4) == 0); // has break => v6 is not visible outside +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v4' must be assigned before it can be used. v1; v3; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v3' must be assigned before it can be used. v5; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v5' must be assigned before it can be used. v6; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v6' must be assigned before it can be used. } -''', - [ - _notAssignedError(360, 2), - _notAssignedError(421, 2), - _notAssignedError(427, 2), - _notAssignedError(433, 2), - ], - ); +'''); } test_doWhile_condition_continue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2, v3, v4; do { @@ -385,18 +374,19 @@ void f(bool b) { v2 = 0; // not visible v3 = 0; // not visible } while ((v4 = v1 + v2) == 0); // no break => v4 visible outside +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. v1; v3; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v3' must be assigned before it can be used. v4; } -''', - [_notAssignedError(200, 2), _notAssignedError(253, 2)], - ); +'''); } test_doWhile_continue_beforeAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; do { @@ -404,14 +394,14 @@ void f(bool b) { v = 0; } while (b); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(82, 1)], - ); +'''); } test_doWhile_true_assignInBreak() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; do { @@ -427,52 +417,48 @@ void f(bool b) { test_extensionType_hasImplements() async { // Extension types are always potentially non-nullable. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) implements int {} void f() { E v; v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(64, 1)], - ); +'''); } test_extensionType_noImplements() async { // Extension types are always potentially non-nullable. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) {} void f() { E v; v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(49, 1)], - ); +'''); } test_for_body() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; for (; b;) { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(58, 1)], - ); +'''); } test_for_break() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; for (; b;) { @@ -481,15 +467,17 @@ void f(bool b) { v2 = 0; } v1; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v1' must be assigned before it can be used. v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(94, 2), _notAssignedError(100, 2)], - ); +'''); } test_for_break_updaters() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; for (; b; v1 + v2) { @@ -502,7 +490,7 @@ void f(bool b) { } test_for_condition() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; for (; (v = 0) >= 0;) { @@ -514,8 +502,7 @@ void f() { } test_for_continue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; for (; b;) { @@ -524,81 +511,82 @@ void f(bool b) { v2 = 0; } v1; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v1' must be assigned before it can be used. v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(97, 2), _notAssignedError(103, 2)], - ); +'''); } test_for_continue_updaters() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; for (; b; v1 + v2) { +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. v1 = 0; if (b) continue; v2 = 0; } } -''', - [_notAssignedError(48, 2)], - ); +'''); } test_for_initializer_expression() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; for (v = 0;;) { v; } v; +//^^ +// [diag.deadCode] Dead code. } -''', - [error(diag.deadCode, 51, 2)], - ); +'''); } test_for_initializer_variable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; for (var t = (v = 0);;) { +// ^ +// [diag.unusedLocalVariable] The value of the local variable 't' isn't used. v; } v; +//^^ +// [diag.deadCode] Dead code. } -''', - [error(diag.unusedLocalVariable, 31, 1), error(diag.deadCode, 61, 2)], - ); +'''); } test_for_updaters() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2, v3, v4; +// ^^ +// [diag.unusedLocalVariable] The value of the local variable 'v3' isn't used. for (; b; v1 = 0, v2 = 0, v3 = 0, v4) { +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v4' must be assigned before it can be used. v1; +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v1' must be assigned before it can be used. } v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [ - error(diag.unusedLocalVariable, 31, 2), - _notAssignedError(75, 2), - _notAssignedError(85, 2), - _notAssignedError(95, 2), - ], - ); +'''); } test_for_updaters_afterBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; for (; b; v) { @@ -609,8 +597,7 @@ void f(bool b) { } test_forEach() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { List v1; int v2; @@ -619,15 +606,14 @@ void f() { } v1; v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(97, 2)], - ); +'''); } test_forEach_break() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; for (var _ in [0, 1, 2]) { @@ -636,16 +622,17 @@ void f(bool b) { v2 = 0; } v1; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v1' must be assigned before it can be used. v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(108, 2), _notAssignedError(114, 2)], - ); +'''); } test_forEach_continue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; for (var _ in [0, 1, 2]) { @@ -654,16 +641,17 @@ void f(bool b) { v2 = 0; } v1; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v1' must be assigned before it can be used. v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(111, 2), _notAssignedError(117, 2)], - ); +'''); } test_functionExpression_closure_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v1, v2; @@ -672,16 +660,15 @@ void f() { [0, 1, 2].forEach((t) { v1; v2; +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. }); } -''', - [_notAssignedError(75, 2)], - ); +'''); } test_functionExpression_closure_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; @@ -690,107 +677,108 @@ void f() { }); v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(67, 1)], - ); +'''); } test_functionExpression_localFunction_local() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. v = 0; void f() { +// ^ +// [diag.unusedElement] The declaration 'f' isn't referenced. int v; // 1 v; +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } } -''', - [ - error(diag.unusedLocalVariable, 17, 1), - error(diag.unusedElement, 38, 1), - _notAssignedError(64, 1), - ], - ); +'''); } test_functionExpression_localFunction_local2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v1; v1 = 0; void f() { +// ^ +// [diag.unusedElement] The declaration 'f' isn't referenced. int v2, v3; v2 = 0; v1; v2; v3; +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v3' must be assigned before it can be used. } } -''', - [error(diag.unusedElement, 40, 1), _notAssignedError(94, 2)], - ); +'''); } test_functionExpression_localFunction_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v1, v2; v1 = 0; void f() { +// ^ +// [diag.unusedElement] The declaration 'f' isn't referenced. v1; v2; +// ^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } v2 = 0; } -''', - [error(diag.unusedElement, 44, 1), _notAssignedError(62, 2)], - ); +'''); } test_functionExpression_localFunction_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; void f() { +// ^ +// [diag.unusedElement] The declaration 'f' isn't referenced. v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [error(diag.unusedElement, 28, 1), _notAssignedError(52, 1)], - ); +'''); } test_futureOr_questionArgument_none() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; f() { FutureOr v; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } -''', - [error(diag.unusedLocalVariable, 45, 1)], - ); +'''); } test_hasInitializer() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f() { int v = 0; v; @@ -799,7 +787,7 @@ f() { } test_if_condition() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' main() { int v; if ((v = 0) >= 0) { @@ -813,58 +801,58 @@ main() { } test_if_condition_false() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; if (false) { +// [diag.deadCode][column 14][length 77] Dead code. // not assigned } else { v = 0; } v; } -''', - [error(diag.deadCode, 33, 25)], - ); +'''); } test_if_condition_logicalAnd() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, int i) { int v; if (b && (v = i) > 0) { v; } else { v; +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(81, 1), _notAssignedError(90, 1)], - ); +'''); } test_if_condition_logicalOr() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, int i) { int v; if (b || (v = i) > 0) { v; +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } else { v; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(63, 1), _notAssignedError(90, 1)], - ); +'''); } test_if_condition_notFalse() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; if (!false) { @@ -876,24 +864,22 @@ void f() { } test_if_condition_notTrue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; if (!true) { +// [diag.deadCode][column 14][length 77] Dead code. // not assigned } else { v = 0; } v; } -''', - [error(diag.deadCode, 33, 25)], - ); +'''); } test_if_condition_true() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; if (true) { @@ -905,22 +891,21 @@ void f() { } test_if_then() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; if (c) { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(54, 1)], - ); +'''); } test_if_thenElse_all() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; if (c) { @@ -936,8 +921,7 @@ void f(bool c) { } test_if_thenElse_else() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; if (c) { @@ -946,15 +930,14 @@ void f(bool c) { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(85, 1)], - ); +'''); } test_if_thenElse_then() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool c) { int v; if (c) { @@ -963,14 +946,14 @@ void f(bool c) { // not assigned } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(85, 1)], - ); +'''); } test_late() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f() { late int v; @@ -985,42 +968,39 @@ f() { } test_noInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { int v; v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(17, 1)], - ); +'''); } test_noInitializer_typeParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { T v; v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(18, 1)], - ); +'''); } test_notUsed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f() { int v; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } -''', - [error(diag.unusedLocalVariable, 17, 1)], - ); +'''); } test_nullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f() { int? v; v; @@ -1029,8 +1009,7 @@ f() { } test_switch_case1_default() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int e) { int v; switch (e) { @@ -1044,15 +1023,14 @@ void f(int e) { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(157, 1)], - ); +'''); } test_switch_case1_default_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(int e) { int v; @@ -1067,15 +1045,14 @@ void f(int e) { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(173, 1)], - ); +'''); } test_switch_case2_default() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int e) { int v1, v2; switch (e) { @@ -1090,15 +1067,14 @@ void f(int e) { } v1; v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(157, 2)], - ); +'''); } test_switch_case2_default_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(int e) { int v1, v2; @@ -1114,15 +1090,14 @@ void f(int e) { } v1; v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(173, 2)], - ); +'''); } test_switch_case_default_break() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, int e) { int v1, v2; switch (e) { @@ -1138,15 +1113,14 @@ void f(bool b, int e) { } v1; v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(199, 2)], - ); +'''); } test_switch_case_default_break_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(bool b, int e) { int v1, v2; @@ -1163,10 +1137,10 @@ void f(bool b, int e) { } v1; v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(215, 2)], - ); +'''); } test_switch_case_default_continue() async { @@ -1175,7 +1149,7 @@ void f(bool b, int e) { // removed from the unassigned set in the `breakState`. And if there is a // case when it is not assigned, then the variable will be left unassigned // in the `breakState`. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int e) { int v; switch (e) { @@ -1198,7 +1172,7 @@ void f(int e) { // removed from the unassigned set in the `breakState`. And if there is a // case when it is not assigned, then the variable will be left unassigned // in the `breakState`. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(int e) { int v; @@ -1217,8 +1191,7 @@ void f(int e) { } test_switch_case_noDefault() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int e) { int v; switch (e) { @@ -1227,15 +1200,14 @@ void f(int e) { break; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(84, 1)], - ); +'''); } test_switch_case_noDefault_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(int e) { int v; @@ -1245,14 +1217,14 @@ void f(int e) { break; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(100, 1)], - ); +'''); } test_switch_expression() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; switch (v = 0) {} @@ -1262,7 +1234,7 @@ void f() { } test_switch_expression_language219() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f() { int v; @@ -1273,48 +1245,45 @@ void f() { } test_syntheticPatternVariable_orPattern_inIfCase() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { if (x case [var a || var a] when a > 0) { +// ^^^^^^^^ +// [diag.deadCode] Dead code. a; } } -''', - [error(diag.deadCode, 45, 8)], - ); +'''); } test_syntheticPatternVariable_orPattern_inSwitchExpression() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { (switch (x) { [var a || var a] when a > 0 => a, +// ^^^^^^^^ +// [diag.deadCode] Dead code. _ => 0, }); } -''', - [error(diag.deadCode, 52, 8)], - ); +'''); } test_syntheticPatternVariable_orPattern_inSwitchStatement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { switch (x) { case [var a || var a] when a > 0: +// ^^^^^^^^ +// [diag.deadCode] Dead code. a; } } -''', - [error(diag.deadCode, 56, 8)], - ); +'''); } test_syntheticPatternVariable_switchCasesSharingABody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { switch (x) { case [var a] when a > 0: @@ -1326,8 +1295,7 @@ void f(Object? x) { } test_tryCatch_body() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1336,14 +1304,14 @@ void f() { // not assigned } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(81, 1)], - ); +'''); } test_tryCatch_body_catch() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1360,7 +1328,7 @@ void g() {} } test_tryCatch_body_catchRethrow() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1374,8 +1342,7 @@ void f() { } test_tryCatch_catch() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1384,15 +1351,14 @@ void f() { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(81, 1)], - ); +'''); } test_tryCatchFinally_body() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1403,15 +1369,14 @@ void f() { // not assigned } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(115, 1)], - ); +'''); } test_tryCatchFinally_catch() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1422,14 +1387,14 @@ void f() { // not assigned } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(115, 1)], - ); +'''); } test_tryCatchFinally_finally() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1445,8 +1410,7 @@ void f() { } test_tryCatchFinally_useInFinally() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { int x; try { @@ -1456,17 +1420,17 @@ f() { x = 1; } finally { x; // BAD +// ^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'x' must be assigned before it can be used. } } void g() {} -''', - [_notAssignedError(114, 1)], - ); +'''); } test_tryFinally_body() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1480,7 +1444,7 @@ void f() { } test_tryFinally_finally() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; try { @@ -1494,40 +1458,37 @@ void f() { } test_type_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { dynamic v; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } -''', - [error(diag.unusedLocalVariable, 16, 1)], - ); +'''); } test_type_dynamicImplicit() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { var v; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } -''', - [error(diag.unusedLocalVariable, 12, 1)], - ); +'''); } test_type_void() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { void v; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } -''', - [error(diag.unusedLocalVariable, 13, 1)], - ); +'''); } test_while_condition() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; while ((v = 0) >= 0) { @@ -1539,8 +1500,7 @@ void f() { } test_while_condition_notTrue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; while (b) { @@ -1548,14 +1508,14 @@ void f(bool b) { v; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(64, 1)], - ); +'''); } test_while_true_break_afterAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; while (true) { @@ -1572,8 +1532,7 @@ void f(bool b) { } test_while_true_break_beforeAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; while (true) { @@ -1582,15 +1541,14 @@ void f(bool b) { v; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. } -''', - [_notAssignedError(85, 1)], - ); +'''); } test_while_true_break_if() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; while (true) { @@ -1602,16 +1560,16 @@ void f(bool b) { break; } v; +// ^^ +// [diag.deadCode] Dead code. } v; } -''', - [error(diag.deadCode, 131, 2)], - ); +'''); } test_while_true_break_if2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { var v; while (true) { @@ -1627,8 +1585,7 @@ void f(bool b) { } test_while_true_break_if3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2; while (true) { @@ -1644,15 +1601,14 @@ void f(bool b) { v1; } v2; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v2' must be assigned before it can be used. } -''', - [_notAssignedError(190, 2)], - ); +'''); } test_while_true_breakOuterFromInner() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v1, v2, v3; L1: while (true) { @@ -1667,15 +1623,14 @@ void f(bool b) { } v1; v3; +//^^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v3' must be assigned before it can be used. } -''', - [_notAssignedError(193, 2)], - ); +'''); } test_while_true_continue() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int v; while (true) { @@ -1683,18 +1638,16 @@ void f(bool b) { v = 0; } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. +//^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.deadCode, 81, 2), - error(diag.notAssignedPotentiallyNonNullableLocalVariable, 81, 1), - ], - ); +'''); } test_while_true_noBreak() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int v; while (true) { @@ -1702,20 +1655,11 @@ void f() { // So, we don't exit the loop. } v; +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'v' must be assigned before it can be used. +//^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.deadCode, 114, 2), - error(diag.notAssignedPotentiallyNonNullableLocalVariable, 114, 1), - ], - ); - } - - ExpectedDiagnostic _notAssignedError(int offset, int length) { - return error( - diag.notAssignedPotentiallyNonNullableLocalVariable, - offset, - length, - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/not_binary_operator_test.dart b/pkg/analyzer/test/src/diagnostics/not_binary_operator_test.dart index 2cdfa08c4c2..323247a2794 100644 --- a/pkg/analyzer/test/src/diagnostics/not_binary_operator_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_binary_operator_test.dart @@ -2,22 +2,25 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonBinaryOperatorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NonBinaryOperatorTest extends PubPackageResolutionTest { test_unaryTilde() async { - await assertErrorsInCode('var a = 5 ~ 3;', [ - error(diag.notBinaryOperator, 10, 1), - ]); + await resolveTestCodeWithDiagnostics(''' +var a = 5 ~ 3; +// ^ +// [diag.notBinaryOperator] '~' isn't a binary operator. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart b/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart index 831db276d90..55973e60cd9 100644 --- a/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart @@ -2,344 +2,226 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotEnoughPositionalArgumentsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NotEnoughPositionalArgumentsTest extends PubPackageResolutionTest { test_annotation_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.named(int p); } @A.named() +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'named', but 0 found. void f() { } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 45, - 1, - messageContains: ["expected by 'named'"], - ), - ], - ); +'''); } test_annotation_withArgumentList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); } @A() +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'A.new', but 0 found. void f() { } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 33, - 1, - messageContains: ["expected by 'A.new'"], - ), - ], - ); +'''); } test_annotation_withoutArgumentList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); } const a = A(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'A.new', but 0 found. @a void f() { } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 42, - 1, - messageContains: ["expected by 'A.new'"], - ), - ], - ); +'''); } test_enumConstant_withArgumentList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'E', but 0 found. const E(int a); } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 13, - 1, - messageContains: ["expected by 'E'"], - ), - ], - ); +'''); } test_enumConstant_withoutArgumentList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; +//^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'E', but 0 found. const E(int a); } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 11, - 1, - messageContains: ["expected by 'E'"], - ), - ], - ); +'''); } test_functionExpressionInvocation_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' typedef Getter(self); Getter getter = (x) => x; main() { getter(); -}''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 66, - 1, - messageContains: ["expected by 'getter'"], - ), - ], - ); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'getter', but 0 found. +}'''); } test_functionExpressionInvocation_plural() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { (int x, int y) {} (); -}''', - [error(diag.notEnoughPositionalArgumentsPlural, 30, 1)], - ); +// ^ +// [diag.notEnoughPositionalArgumentsPlural] 2 positional arguments expected, but 0 found. +}'''); } test_functionExpressionInvocation_singular() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' main() { (int x) {} (); -}''', - [error(diag.notEnoughPositionalArgumentsSingular, 23, 1)], - ); +// ^ +// [diag.notEnoughPositionalArgumentsSingular] 1 positional argument expected, but 0 found. +}'''); } test_instanceCreationExpression_const() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); } main() { const A(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'A.new', but 0 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 49, - 1, - messageContains: ["expected by 'A.new'"], - ), - ], - ); +'''); } test_instanceCreationExpression_const_namedArgument_insteadOfRequiredPositional() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); } main() { const A(p: 0); +// ^ +// [diag.undefinedNamedParameter] The named parameter 'p' isn't defined. +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'A.new', but 0 found. } -''', - [ - error(diag.notEnoughPositionalArgumentsNameSingular, 49, 1), - error(diag.undefinedNamedParameter, 49, 1), - ], - ); +'''); } test_instanceCreationExpression_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named(int x, int y, {int? n}); } void f() { A.named(5, n: 1); +// ^ +// [diag.notEnoughPositionalArgumentsNamePlural] 2 positional arguments expected by 'named', but 1 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNamePlural, - 70, - 1, - messageContains: ["expected by 'named'"], - ), - ], - ); +'''); } test_instanceCreationExpression_positionalAndNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int x, int y, {int? n}); } void f() { A(5, n: 1); +// ^ +// [diag.notEnoughPositionalArgumentsNamePlural] 2 positional arguments expected by 'A.new', but 1 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNamePlural, - 58, - 1, - messageContains: [ - "2 positional arguments expected by 'A.new', but 1 found.", - ], - ), - ], - ); +'''); } test_methodInvocation_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f(int a, String b) {} main() { f(); -}''', - [ - error( - diag.notEnoughPositionalArgumentsNamePlural, - 35, - 1, - messageContains: ["expected by 'f'"], - ), - ], - ); +// ^ +// [diag.notEnoughPositionalArgumentsNamePlural] 2 positional arguments expected by 'f', but 0 found. +}'''); } test_redirectingConstructorInvocation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); const A.named(int p) : this(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'A.new', but 0 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 58, - 1, - messageContains: ["expected by 'A.new'"], - ), - ], - ); +'''); } test_redirectingConstructorInvocation_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.named(int p); const A(int p) : this.named(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'named', but 0 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 64, - 1, - messageContains: ["expected by 'named'"], - ), - ], - ); +'''); } test_superConstructorInvocation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); } class B extends A { const B() : super(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'A.new', but 0 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 70, - 1, - messageContains: ["expected by 'A.new'"], - ), - ], - ); +'''); } test_superConstructorInvocation_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.named(int p); } class B extends A { const B() : super.named(); +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'named', but 0 found. } -''', - [ - error( - diag.notEnoughPositionalArgumentsNameSingular, - 82, - 1, - messageContains: ["expected by 'named'"], - ), - ], - ); +'''); } test_superConstructorInvocation_superParameter_optional() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int? a); } @@ -351,7 +233,7 @@ class B extends A { } test_superConstructorInvocation_superParameter_required() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a); } diff --git a/pkg/analyzer/test/src/diagnostics/not_instantiated_bound_test.dart b/pkg/analyzer/test/src/diagnostics/not_instantiated_bound_test.dart index 55b1607b4dd..a9e17cb4975 100644 --- a/pkg/analyzer/test/src/diagnostics/not_instantiated_bound_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_instantiated_bound_test.dart @@ -2,41 +2,40 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotInstantiatedBoundTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NotInstantiatedBoundTest extends PubPackageResolutionTest { test_argument_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A> {} class C {} -''', - [error(diag.notInstantiatedBound, 51, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_argumentDeep_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A>> {} class C {} -''', - [error(diag.notInstantiatedBound, 57, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_class_bound_argument_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B {} class C> {} @@ -44,7 +43,7 @@ class C> {} } test_class_bound_argument_recursive_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B {} class C> {} @@ -52,7 +51,7 @@ class C> {} } test_class_bound_bound_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C> {} class D {} @@ -60,14 +59,14 @@ class D {} } test_class_function_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B {} '''); } test_class_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C1 {} class C2> {} @@ -75,142 +74,129 @@ class C2> {} } test_class_recursion_boundArgument_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A> {} +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. class B> {} -''', - [ - error(diag.notInstantiatedBound, 20, 1), - error(diag.notInstantiatedBound, 47, 1), - ], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_class_recursion_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} // points to a +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. class B {} // points to b +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. class C {} // points to a cyclical type -''', - [ - error(diag.notInstantiatedBound, 18, 1), - error(diag.notInstantiatedBound, 57, 1), - error(diag.notInstantiatedBound, 96, 1), - ], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_class_recursion_notInstantiated_genericFunctionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} -''', - [error(diag.notInstantiatedBound, 32, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_class_recursion_notInstantiated_genericFunctionType2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A()> {} -''', - [error(diag.notInstantiatedBound, 42, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_class_recursion_typedef_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F(C value); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. class C {} +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. class D {} -''', - [ - error(diag.typeAliasCannotReferenceItself, 8, 1), - error(diag.notInstantiatedBound, 38, 1), - error(diag.notInstantiatedBound, 62, 1), - ], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_class_typedef_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef void F(); class C {} '''); } test_direct_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C {} -''', - [error(diag.notInstantiatedBound, 45, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_functionType_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B {} class C {} +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. class D {} -''', - [ - error(diag.notInstantiatedBound, 87, 1), - error(diag.notInstantiatedBound, 111, 1), - ], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_indirect_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class C> {} -''', - [error(diag.notInstantiatedBound, 50, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_typedef_argument_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A> {} typedef void F(); -''', - [error(diag.notInstantiatedBound, 58, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_typedef_argumentDeep_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A>> {} typedef void F(); -''', - [error(diag.notInstantiatedBound, 64, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } test_typedef_class_instantiated() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C {} typedef void F(); '''); } test_typedef_direct_notInstantiated() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} typedef void F(); -''', - [error(diag.notInstantiatedBound, 52, 1)], - ); +// ^ +// [diag.notInstantiatedBound] Type parameter bound types must be instantiated. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/not_iterable_spread_test.dart b/pkg/analyzer/test/src/diagnostics/not_iterable_spread_test.dart index 5b97f9db4f1..515ee72105d 100644 --- a/pkg/analyzer/test/src/diagnostics/not_iterable_spread_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_iterable_spread_test.dart @@ -6,18 +6,20 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotIterableSpreadTest); defineReflectiveTests(NotIterableSpreadWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NotIterableSpreadTest extends PubPackageResolutionTest { test_iterable_interfaceTypeTypedef() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' typedef A = List; f(A a) { var v = [...a]; @@ -27,20 +29,20 @@ f(A a) { } test_iterable_list() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var a = [0]; var v = [...a]; '''); } test_iterable_null() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = [...?null]; '''); } test_iterable_typeParameter_bound_list() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f>(T a) { var v = [...a]; v; @@ -49,7 +51,7 @@ void f>(T a) { } test_iterable_typeParameter_bound_listQuestion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f?>(T a) { var v = [...?a]; v; @@ -58,67 +60,60 @@ void f?>(T a) { } test_notIterable_direct() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = [...a]; -''', - [error(diag.notIterableSpread, 23, 1)], - ); +// ^ +// [diag.notIterableSpread] Spread elements in list or set literals must implement 'Iterable'. +'''); } test_notIterable_forElement() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = [for (var i in []) ...a]; -''', - [ - error(diag.unusedLocalVariable, 29, 1), - error(diag.notIterableSpread, 41, 1), - ], - ); +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used. +// ^ +// [diag.notIterableSpread] Spread elements in list or set literals must implement 'Iterable'. +'''); } test_notIterable_ifElement_else() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = [if (1 > 0) ...[] else ...a]; -''', - [error(diag.notIterableSpread, 45, 1)], - ); +// ^ +// [diag.notIterableSpread] Spread elements in list or set literals must implement 'Iterable'. +'''); } test_notIterable_ifElement_then() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = [if (1 > 0) ...a]; -''', - [error(diag.notIterableSpread, 34, 1)], - ); +// ^ +// [diag.notIterableSpread] Spread elements in list or set literals must implement 'Iterable'. +'''); } test_notIterable_typeParameter_bound() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(T a) { var v = [...a]; +// ^ +// [diag.notIterableSpread] Spread elements in list or set literals must implement 'Iterable'. v; } -''', - [error(diag.notIterableSpread, 43, 1)], - ); +'''); } test_spread_map_in_iterable_context() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' List f() => [...{1: 2, 3: 4}]; -''', - [error(diag.notIterableSpread, 21, 12)], - ); +// ^^^^^^^^^^^^ +// [diag.notIterableSpread] Spread elements in list or set literals must implement 'Iterable'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart b/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart index 8b012ad9a7b..d74c068430a 100644 --- a/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart @@ -6,31 +6,33 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotMapSpreadTest); defineReflectiveTests(NotMapSpreadWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NotMapSpreadTest extends PubPackageResolutionTest { test_map() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var a = {0: 0}; var v = {...a}; '''); } test_map_null() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = {...?null}; '''); } test_map_typeParameter_bound_map() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f>(T a) { var v = {...a}; v; @@ -39,7 +41,7 @@ void f>(T a) { } test_map_typeParameter_bound_mapQuestion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f?>(T a) { var v = {...?a}; v; @@ -48,55 +50,52 @@ void f?>(T a) { } test_notMap_direct() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = {...a}; -''', - [error(diag.notMapSpread, 33, 1)], - ); +// ^ +// [diag.notMapSpread] Spread elements in map literals must implement 'Map'. +'''); } test_notMap_forElement() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = {for (var i in []) ...a}; -''', - [error(diag.unusedLocalVariable, 39, 1), error(diag.notMapSpread, 51, 1)], - ); +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used. +// ^ +// [diag.notMapSpread] Spread elements in map literals must implement 'Map'. +'''); } test_notMap_ifElement_else() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = {if (1 > 0) ...{} else ...a}; -''', - [error(diag.notMapSpread, 65, 1)], - ); +// ^ +// [diag.notMapSpread] Spread elements in map literals must implement 'Map'. +'''); } test_notMap_ifElement_then() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var a = 0; var v = {if (1 > 0) ...a}; -''', - [error(diag.notMapSpread, 44, 1)], - ); +// ^ +// [diag.notMapSpread] Spread elements in map literals must implement 'Map'. +'''); } test_notMap_typeParameter_bound() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(T a) { var v = {...a}; +// ^ +// [diag.notMapSpread] Spread elements in map literals must implement 'Map'. v; } -''', - [error(diag.notMapSpread, 53, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/not_null_aware_null_spread_test.dart b/pkg/analyzer/test/src/diagnostics/not_null_aware_null_spread_test.dart index e14b85de13b..bad15d63d75 100644 --- a/pkg/analyzer/test/src/diagnostics/not_null_aware_null_spread_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_null_aware_null_spread_test.dart @@ -2,128 +2,111 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotNullAwareNullSpreadTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NotNullAwareNullSpreadTest extends PubPackageResolutionTest { test_listLiteral_notNullAware_nullLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = [...null]; -''', - [ - error(diag.invalidUseOfNullValue, 12, 4), - error(diag.notNullAwareNullSpread, 12, 4), - ], - ); +// ^^^^ +// [diag.invalidUseOfNullValue] An expression whose value is always 'null' can't be dereferenced. +// [diag.notNullAwareNullSpread] The Null-typed expression can't be used with a non-null-aware spread. +'''); } test_listLiteral_notNullAware_nullTyped() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' Null a = null; var v = [...a]; -''', - [ - error(diag.invalidUseOfNullValue, 27, 1), - error(diag.notNullAwareNullSpread, 27, 1), - ], - ); +// ^ +// [diag.invalidUseOfNullValue] An expression whose value is always 'null' can't be dereferenced. +// [diag.notNullAwareNullSpread] The Null-typed expression can't be used with a non-null-aware spread. +'''); } test_listLiteral_nullAware_nullLiteral() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = [...?null]; '''); } test_listLiteral_nullAware_nullTyped() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' Null a = null; var v = [...?a]; '''); } test_mapLiteral_notNullAware_nullLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {...null}; -''', - [ - error(diag.invalidUseOfNullValue, 22, 4), - error(diag.notNullAwareNullSpread, 22, 4), - ], - ); +// ^^^^ +// [diag.invalidUseOfNullValue] An expression whose value is always 'null' can't be dereferenced. +// [diag.notNullAwareNullSpread] The Null-typed expression can't be used with a non-null-aware spread. +'''); } test_mapLiteral_notNullAware_nullType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' Null a = null; var v = {...a}; -''', - [ - error(diag.invalidUseOfNullValue, 37, 1), - error(diag.notNullAwareNullSpread, 37, 1), - ], - ); +// ^ +// [diag.invalidUseOfNullValue] An expression whose value is always 'null' can't be dereferenced. +// [diag.notNullAwareNullSpread] The Null-typed expression can't be used with a non-null-aware spread. +'''); } test_mapLiteral_nullAware_nullLiteral() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = {...?null}; '''); } test_mapLiteral_nullAware_nullType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' Null a = null; var v = {...?a}; '''); } test_setLiteral_notNullAware_nullLiteral() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var v = {...null}; -''', - [ - error(diag.invalidUseOfNullValue, 17, 4), - error(diag.notNullAwareNullSpread, 17, 4), - ], - ); +// ^^^^ +// [diag.invalidUseOfNullValue] An expression whose value is always 'null' can't be dereferenced. +// [diag.notNullAwareNullSpread] The Null-typed expression can't be used with a non-null-aware spread. +'''); } test_setLiteral_notNullAware_nullTyped() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' Null a = null; var v = {...a}; -''', - [ - error(diag.invalidUseOfNullValue, 32, 1), - error(diag.notNullAwareNullSpread, 32, 1), - ], - ); +// ^ +// [diag.invalidUseOfNullValue] An expression whose value is always 'null' can't be dereferenced. +// [diag.notNullAwareNullSpread] The Null-typed expression can't be used with a non-null-aware spread. +'''); } test_setLiteral_nullAware_nullLiteral() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' var v = {...?null}; '''); } test_setLiteral_nullAware_nullTyped() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' Null a = null; var v = {...?a}; '''); diff --git a/pkg/analyzer/test/src/diagnostics/null_argument_to_non_null_type_test.dart b/pkg/analyzer/test/src/diagnostics/null_argument_to_non_null_type_test.dart index 850f3016823..f374caa81e7 100644 --- a/pkg/analyzer/test/src/diagnostics/null_argument_to_non_null_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/null_argument_to_non_null_type_test.dart @@ -2,15 +2,16 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; void main() { defineReflectiveSuite(() { defineReflectiveTests(NullArgumentToNonNullCompleterCompleteTest); defineReflectiveTests(NullArgumentToNonNullFutureValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -18,17 +19,16 @@ void main() { class NullArgumentToNonNullCompleterCompleteTest extends PubPackageResolutionTest { test_absent() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; void f() => Completer().complete(); -''', - [error(diag.nullArgumentToNonNullType, 33, 27)], - ); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.nullArgumentToNonNullType] 'Completer.complete' shouldn't be called with a 'null' argument for the non-nullable type argument 'int'. +'''); } test_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; void f() { Completer().complete(null as dynamic); @@ -37,17 +37,16 @@ void f() { } test_null() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; void f() => Completer().complete(null); -''', - [error(diag.nullArgumentToNonNullType, 59, 4)], - ); +// ^^^^ +// [diag.nullArgumentToNonNullType] 'Completer.complete' shouldn't be called with a 'null' argument for the non-nullable type argument 'int'. +'''); } test_nullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; void f() { final c = Completer(); @@ -58,29 +57,27 @@ void f() { } test_nullType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; void f(Null a) => Completer().complete(a); -''', - [error(diag.nullArgumentToNonNullType, 65, 1)], - ); +// ^ +// [diag.nullArgumentToNonNullType] 'Completer.complete' shouldn't be called with a 'null' argument for the non-nullable type argument 'int'. +'''); } } @reflectiveTest class NullArgumentToNonNullFutureValueTest extends PubPackageResolutionTest { test_absent() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void foo() => Future.value(); -''', - [error(diag.nullArgumentToNonNullType, 14, 19)], - ); +// ^^^^^^^^^^^^^^^^^^^ +// [diag.nullArgumentToNonNullType] 'Future.value' shouldn't be called with a 'null' argument for the non-nullable type argument 'int'. +'''); } test_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'dart:async'; void f() { Future.value(null as dynamic); @@ -89,16 +86,15 @@ void f() { } test_null() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void foo() => Future.value(null); -''', - [error(diag.nullArgumentToNonNullType, 32, 4)], - ); +// ^^^^ +// [diag.nullArgumentToNonNullType] 'Future.value' shouldn't be called with a 'null' argument for the non-nullable type argument 'int'. +'''); } test_nullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f() { Future.value(); Future.value(null); @@ -107,11 +103,10 @@ void f() { } test_nullType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void foo(Null a) => Future.value(a); -''', - [error(diag.nullArgumentToNonNullType, 38, 1)], - ); +// ^ +// [diag.nullArgumentToNonNullType] 'Future.value' shouldn't be called with a 'null' argument for the non-nullable type argument 'int'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/null_aware_elements_const_literals_error_test.dart b/pkg/analyzer/test/src/diagnostics/null_aware_elements_const_literals_error_test.dart index d33a1ad52c2..3ef94160095 100644 --- a/pkg/analyzer/test/src/diagnostics/null_aware_elements_const_literals_error_test.dart +++ b/pkg/analyzer/test/src/diagnostics/null_aware_elements_const_literals_error_test.dart @@ -2,304 +2,230 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullAwareElementsConstLiteralsErrorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullAwareElementsConstLiteralsErrorTest extends PubPackageResolutionTest { test_duplicated_in_key_named_null_aware_key_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const int? intConst = 0; const String? stringConst = ""; const map = {intConst: null, 0: ?intConst, null: 1, stringConst: 1}; -''', - [ - error( - diag.equalKeysInConstMap, - 86, - 1, - contextMessages: [message(testFile, 70, 8)], - ), - ], - ); +// ^^^^^^^^ +// [context 1] The first key with this value. +// ^ +// [diag.equalKeysInConstMap][context 1] Two keys in a constant map literal can't be equal. +'''); } test_duplicated_int_in_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const int? intConst = 0; const String? stringConst = ""; const set = {0, ?intConst, stringConst}; -''', - [ - error( - diag.equalElementsInConstSet, - 74, - 8, - contextMessages: [message(testFile, 70, 1)], - ), - ], - ); +// ^ +// [context 1] The first element with this value. +// ^^^^^^^^ +// [diag.equalElementsInConstSet][context 1] Two elements in a constant set literal can't be equal. +'''); } test_duplicated_int_key_null_aware_key_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const int? intConst = 0; const String? stringConst = ""; const map = {intConst: null, ?(0 as int?): intConst, null: 1, stringConst: 1}; -''', - [ - error( - diag.equalKeysInConstMap, - 87, - 11, - contextMessages: [message(testFile, 70, 8)], - ), - ], - ); +// ^^^^^^^^ +// [context 1] The first key with this value. +// ^^^^^^^^^^^ +// [diag.equalKeysInConstMap][context 1] Two keys in a constant map literal can't be equal. +'''); } test_duplicated_null_in_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const int? nullConst = null; const int? intConst = 0; const String? stringConst = ""; const set = {nullConst, null, intConst, stringConst}; -''', - [ - error( - diag.equalElementsInConstSet, - 110, - 4, - contextMessages: [message(testFile, 99, 9)], - ), - ], - ); +// ^^^^^^^^^ +// [context 1] The first element with this value. +// ^^^^ +// [diag.equalElementsInConstSet][context 1] Two elements in a constant set literal can't be equal. +'''); } test_duplicated_null_key_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const nullConst = null; const int? intConst = 0; const String? stringConst = ""; const map = {null: 1, nullConst: 1, intConst: 1, stringConst: 1}; -''', - [ - error( - diag.equalKeysInConstMap, - 103, - 9, - contextMessages: [message(testFile, 94, 4)], - ), - ], - ); +// ^^^^ +// [context 1] The first key with this value. +// ^^^^^^^^^ +// [diag.equalKeysInConstMap][context 1] Two keys in a constant map literal can't be equal. +'''); } test_duplicated_null_key_null_aware_value_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const nullConst = null; const int? intConst = 0; const String? stringConst = ""; const map = {null: 1, nullConst: ?intConst, stringConst: 1}; -''', - [ - error( - diag.equalKeysInConstMap, - 103, - 9, - contextMessages: [message(testFile, 94, 4)], - ), - ], - ); +// ^^^^ +// [context 1] The first key with this value. +// ^^^^^^^^^ +// [diag.equalKeysInConstMap][context 1] Two keys in a constant map literal can't be equal. +'''); } test_duplicated_string_in_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const int? intConst = 0; const String? stringConst = ""; const set = {null, intConst, "", ?stringConst}; -''', - [ - error( - diag.equalElementsInConstSet, - 91, - 11, - contextMessages: [message(testFile, 86, 2)], - ), - ], - ); +// ^^ +// [context 1] The first element with this value. +// ^^^^^^^^^^^ +// [diag.equalElementsInConstSet][context 1] Two elements in a constant set literal can't be equal. +'''); } test_non_const_and_null_under_question_in_list() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var nullVar = null; const int? intConst = 0; const String? stringConst = ""; const list = [?null, ?nullVar, intConst, stringConst]; -''', - [ - error(diag.nonConstantListElement, 99, 7), - error(diag.constInitializedWithNonConstantValue, 99, 7), - ], - ); +// ^^^^^^^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_in_key_under_question_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const String? stringConst = ""; int? intVar = 0; const map = {null: 1, ?intVar: 1, stringConst: 1}; -''', - [ - error(diag.nonConstantMapKey, 72, 6), - error(diag.constInitializedWithNonConstantValue, 72, 6), - ], - ); +// ^^^^^^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_int_under_question_in_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const nullConst = null; const String? stringConst = ""; int? intVar = 0; const set = {nullConst, ?intVar, stringConst}; -''', - [ - error(diag.nonConstantSetElement, 98, 6), - error(diag.constInitializedWithNonConstantValue, 98, 6), - ], - ); +// ^^^^^^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_int_value_under_question_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const String? stringConst = ""; int? intVar = 0; const map = {null: 1, 0: ?intVar, stringConst: 1}; -''', - [ - error(diag.nonConstantMapValue, 75, 6), - error(diag.constInitializedWithNonConstantValue, 75, 6), - ], - ); +// ^^^^^^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_null_key_under_question_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var nullVar = null; const int? intConst = 0; const String? stringConst = ""; const map = {?nullVar: 1, intConst: 1, stringConst: 1}; -''', - [ - error(diag.nonConstantMapKey, 91, 7), - error(diag.constInitializedWithNonConstantValue, 91, 7), - ], - ); +// ^^^^^^^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_null_under_question_in_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var nullVar = null; const int? intConst = 0; const String? stringConst = ""; const set = {?nullVar, intConst, stringConst}; -''', - [ - error(diag.nonConstantSetElement, 91, 7), - error(diag.constInitializedWithNonConstantValue, 91, 7), - ], - ); +// ^^^^^^^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_null_value_under_question_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var nullVar = null; const int? intConst = 0; const String? stringConst = ""; const map = {null: ?nullVar, intConst: 1, stringConst: 1}; -''', - [ - error(diag.nonConstantMapValue, 97, 7), - error(diag.constInitializedWithNonConstantValue, 97, 7), - ], - ); +// ^^^^^^^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_string_key_under_question_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' String? stringVar = ""; const map = {null: 1, 0: 1, ?stringVar: 1}; -''', - [ - error(diag.nonConstantMapKey, 53, 9), - error(diag.constInitializedWithNonConstantValue, 53, 9), - ], - ); +// ^^^^^^^^^ +// [diag.nonConstantMapKey] The keys in a const map literal must be constant. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_string_under_question_in_set() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const nullConst = null; const int? intConst = 0; String? stringVar = ""; const set = {nullConst, intConst, ?stringVar}; -''', - [ - error(diag.nonConstantSetElement, 108, 9), - error(diag.constInitializedWithNonConstantValue, 108, 9), - ], - ); +// ^^^^^^^^^ +// [diag.nonConstantSetElement] The values in a const set literal must be constants. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_string_value_under_question_in_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' String? stringVar = ""; const map = {null: 1, 0: 1, "": ?stringVar}; -''', - [ - error(diag.nonConstantMapValue, 57, 9), - error(diag.constInitializedWithNonConstantValue, 57, 9), - ], - ); +// ^^^^^^^^^ +// [diag.nonConstantMapValue] The values in a const map literal must be constant. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } test_non_const_under_question_in_list() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' var nullVar = null; const int? intConst = 0; const String? stringConst = ""; const list = [?nullVar, intConst, stringConst]; -''', - [ - error(diag.nonConstantListElement, 92, 7), - error(diag.constInitializedWithNonConstantValue, 92, 7), - ], - ); +// ^^^^^^^ +// [diag.nonConstantListElement] The values in a const list literal must be constants. +// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart b/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart index 5408e9b15af..dab6bc46bb7 100644 --- a/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart +++ b/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullNeverNotNullTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullNeverNotNullTest extends PubPackageResolutionTest { test_nullable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? i) { i!; } @@ -24,53 +25,49 @@ void f(int? i) { } test_nullLiteral() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { null!; +//^^^^^ +// [diag.nullCheckAlwaysFails] This null-check will always throw an exception because the expression will always evaluate to 'null'. } -''', - [error(diag.nullCheckAlwaysFails, 13, 5)], - ); +'''); } test_nullLiteral_parenthesized() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { (null)!; +//^^^^^^^ +// [diag.nullCheckAlwaysFails] This null-check will always throw an exception because the expression will always evaluate to 'null'. } -''', - [error(diag.nullCheckAlwaysFails, 13, 7)], - ); +'''); } test_nullType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { g()!; +//^^^^ +// [diag.nullCheckAlwaysFails] This null-check will always throw an exception because the expression will always evaluate to 'null'. } Null g() => null; -''', - [error(diag.nullCheckAlwaysFails, 13, 4)], - ); +'''); } test_nullType_awaited() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() async { (await g())!; +//^^^^^^^^^^^^ +// [diag.nullCheckAlwaysFails] This null-check will always throw an exception because the expression will always evaluate to 'null'. } Future g() async => null; -''', - [error(diag.nullCheckAlwaysFails, 19, 12)], - ); +'''); } test_potentiallyNullableTypeVariable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T i) { i!; } diff --git a/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart b/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart index 6a0f124a91b..1064719efd3 100644 --- a/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart +++ b/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart @@ -2,15 +2,16 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReadWriteTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -20,7 +21,7 @@ class ReadWriteTest extends PubPackageResolutionTest { bool get retainDataForTesting => true; test_final_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { x; @@ -30,7 +31,7 @@ void f(final x) { } test_final_definitelyAssigned_read_prefixNegate() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { -x; @@ -40,134 +41,124 @@ void f(final x) { } test_final_definitelyAssigned_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { x += 1; +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 36, 1)], - ); +'''); _assertAssigned('x +=', assigned: true, unassigned: false); } test_final_definitelyAssigned_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { x++; +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 36, 1)], - ); +'''); _assertAssigned('x++', assigned: true, unassigned: false); } test_final_definitelyAssigned_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { ++x; +// ^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 38, 1)], - ); +'''); _assertAssigned('x;', assigned: true, unassigned: false); } test_final_definitelyAssigned_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { x = 0; +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 36, 1)], - ); +'''); _assertAssigned('x =', assigned: true, unassigned: false); } test_final_definitelyAssigned_write_forEachLoop_identifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 void f(final x) { for (x in [0, 1, 2]) { +// ^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. x; } } -''', - [error(diag.assignmentToFinalLocal, 41, 1)], - ); +'''); _assertAssigned('x in', assigned: true, unassigned: false); } test_final_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { final x; x; // 0 +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. x(); +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. } -''', - [ - error(diag.readPotentiallyUnassignedFinal, 24, 1), - error(diag.readPotentiallyUnassignedFinal, 34, 1), - ], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); _assertAssigned('x()', assigned: false, unassigned: true); } test_final_definitelyUnassigned_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable final x; x += 1; +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. } -''', - [error(diag.readPotentiallyUnassignedFinal, 58, 1)], - ); +'''); _assertAssigned('x +=', assigned: false, unassigned: true); } test_final_definitelyUnassigned_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable final x; x++; +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. } -''', - [error(diag.readPotentiallyUnassignedFinal, 58, 1)], - ); +'''); _assertAssigned('x++', assigned: false, unassigned: true); } test_final_definitelyUnassigned_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable final x; ++x; // 0 +// ^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. } -''', - [error(diag.readPotentiallyUnassignedFinal, 60, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_final_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable final x; @@ -178,90 +169,79 @@ void f() { } test_final_neither_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { final x; if (b) x = 0; x; // 0 +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. } -''', - [error(diag.readPotentiallyUnassignedFinal, 46, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: false); } test_final_neither_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable final x; if (b) x = 0; x += 1; +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [ - error(diag.assignmentToFinalLocal, 80, 1), - error(diag.readPotentiallyUnassignedFinal, 80, 1), - ], - ); +'''); _assertAssigned('x +=', assigned: false, unassigned: false); } test_final_neither_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable final x; if (b) x = 0; x++; +//^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [ - error(diag.assignmentToFinalLocal, 80, 1), - error(diag.readPotentiallyUnassignedFinal, 80, 1), - ], - ); +'''); _assertAssigned('x++', assigned: false, unassigned: false); } test_final_neither_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable final x; if (b) x = 0; ++x; // 0 +// ^ +// [diag.readPotentiallyUnassignedFinal] The final variable 'x' can't be read because it's potentially unassigned at this point. +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [ - error(diag.assignmentToFinalLocal, 82, 1), - error(diag.readPotentiallyUnassignedFinal, 82, 1), - ], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: false); } test_final_neither_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable final x; if (b) x = 0; x = 1; +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 80, 1)], - ); +'''); _assertAssigned('x = 1', assigned: false, unassigned: false); } test_lateFinal_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late final x; x = 0; @@ -272,122 +252,114 @@ void f() { } test_lateFinal_definitelyAssigned_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; x = 0; x += 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 72, 1)], - ); +'''); _assertAssigned('x +=', assigned: true, unassigned: false); } test_lateFinal_definitelyAssigned_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; x = 0; x++; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 72, 1)], - ); +'''); _assertAssigned('x++', assigned: true, unassigned: false); } test_lateFinal_definitelyAssigned_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; x = 0; ++x; // 0 +// ^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 74, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: true, unassigned: false); } test_lateFinal_definitelyAssigned_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; x = 0; x = 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 72, 1)], - ); +'''); _assertAssigned('x = 1', assigned: true, unassigned: false); } test_lateFinal_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late final x; x; // 0 +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 29, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateFinal_definitelyUnassigned_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; x += 1; +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 63, 1)], - ); +'''); _assertAssigned('x +=', assigned: false, unassigned: true); } test_lateFinal_definitelyUnassigned_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; x++; +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 63, 1)], - ); +'''); _assertAssigned('x++', assigned: false, unassigned: true); } test_lateFinal_definitelyUnassigned_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; ++x; // 0 +// ^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 65, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateFinal_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final x; @@ -398,7 +370,7 @@ void f() { } test_lateFinal_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { late final x; if (b) x = 0; @@ -409,7 +381,7 @@ void f(bool b) { } test_lateFinal_neither_readWrite_compoundAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final x; @@ -421,7 +393,7 @@ void f(bool b) { } test_lateFinal_neither_readWrite_postfixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final x; @@ -433,7 +405,7 @@ void f(bool b) { } test_lateFinal_neither_readWrite_prefixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final x; @@ -445,7 +417,7 @@ void f(bool b) { } test_lateFinal_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final x; @@ -457,7 +429,7 @@ void f(bool b) { } test_lateFinalNullable_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late final int? x; x = 0; @@ -468,131 +440,120 @@ void f() { } test_lateFinalNullable_definitelyAssigned_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; x = 0; x += 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 77, 1)], - ); +'''); _assertAssigned('x +=', assigned: true, unassigned: false); } test_lateFinalNullable_definitelyAssigned_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; x = 0; x++; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 77, 1)], - ); +'''); _assertAssigned('x++', assigned: true, unassigned: false); } test_lateFinalNullable_definitelyAssigned_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; x = 0; ++x; // 0 +// ^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 79, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: true, unassigned: false); } test_lateFinalNullable_definitelyAssigned_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; x = 0; x = 1; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 77, 1)], - ); +'''); _assertAssigned('x = 1', assigned: true, unassigned: false); } test_lateFinalNullable_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late final int? x; x; // 0 +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 34, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateFinalNullable_definitelyUnassigned_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; x += 1; +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. +// ^^ +// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'. } -''', - [ - error(diag.definitelyUnassignedLateLocalVariable, 68, 1), - error(diag.uncheckedMethodInvocationOfNullableValue, 70, 2), - ], - ); +'''); _assertAssigned('x +=', assigned: false, unassigned: true); } test_lateFinalNullable_definitelyUnassigned_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; x++; +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. +// ^^ +// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'. } -''', - [ - error(diag.definitelyUnassignedLateLocalVariable, 68, 1), - error(diag.uncheckedMethodInvocationOfNullableValue, 69, 2), - ], - ); +'''); _assertAssigned('x++', assigned: false, unassigned: true); } test_lateFinalNullable_definitelyUnassigned_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; ++x; // 0 +//^^ +// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'. +// ^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [ - error(diag.definitelyUnassignedLateLocalVariable, 70, 1), - error(diag.uncheckedMethodInvocationOfNullableValue, 68, 2), - ], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateFinalNullable_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late final int? x; @@ -603,7 +564,7 @@ void f() { } test_lateFinalNullable_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { late final int? x; if (b) x = 0; @@ -614,52 +575,49 @@ void f(bool b) { } test_lateFinalNullable_neither_readWrite_compoundAssignment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final int? x; if (b) x = 0; x += 1; +// ^^ +// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'. } -''', - [error(diag.uncheckedMethodInvocationOfNullableValue, 92, 2)], - ); +'''); _assertAssigned('x +=', assigned: false, unassigned: false); } test_lateFinalNullable_neither_readWrite_postfixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final int? x; if (b) x = 0; x++; +// ^^ +// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'. } -''', - [error(diag.uncheckedMethodInvocationOfNullableValue, 91, 2)], - ); +'''); _assertAssigned('x++', assigned: false, unassigned: false); } test_lateFinalNullable_neither_readWrite_prefixIncrement() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final int? x; if (b) x = 0; ++x; // 0 +//^^ +// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'. } -''', - [error(diag.uncheckedMethodInvocationOfNullableValue, 90, 2)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: false); } test_lateFinalNullable_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late final int? x; @@ -671,7 +629,7 @@ void f(bool b) { } test_lateFinalPotentiallyNonNullable_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) { late final T x; x = t; @@ -682,35 +640,33 @@ void f(T t) { } test_lateFinalPotentiallyNonNullable_definitelyAssigned_write() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t, T t2) { // ignore:unused_local_variable late final T x; x = t; x = t2; +//^ +// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned. } -''', - [error(diag.lateFinalLocalAlreadyAssigned, 86, 1)], - ); +'''); _assertAssigned('x = t2', assigned: true, unassigned: false); } test_lateFinalPotentiallyNonNullable_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late final T x; x; // 0 +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 34, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateFinalPotentiallyNonNullable_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) { // ignore:unused_local_variable late final T x; @@ -721,7 +677,7 @@ void f(T t) { } test_lateFinalPotentiallyNonNullable_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, T t) { late final T x; if (b) x = t; @@ -732,7 +688,7 @@ void f(bool b, T t) { } test_lateFinalPotentiallyNonNullable_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, T t, T t2) { // ignore:unused_local_variable late final T x; @@ -744,7 +700,7 @@ void f(bool b, T t, T t2) { } test_lateNullable_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late int? x; x = 0; @@ -755,20 +711,19 @@ void f() { } test_lateNullable_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late int? x; x; // 0 +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 28, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateNullable_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { late int? x; if (b) x = 0; @@ -779,7 +734,7 @@ void f(bool b) { } test_latePotentiallyNonNullable_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) { late T x; x = t; @@ -790,20 +745,19 @@ void f(T t) { } test_latePotentiallyNonNullable_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late T x; x; // 0 +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 28, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_latePotentiallyNonNullable_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, T t) { late T x; if (b) x = t; @@ -814,7 +768,7 @@ void f(bool b, T t) { } test_lateVar_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late var x; x = 0; @@ -825,7 +779,7 @@ void f() { } test_lateVar_definitelyAssigned_readWrite_compoundAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late var x; @@ -837,7 +791,7 @@ void f() { } test_lateVar_definitelyAssigned_readWrite_postfixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late var x; @@ -849,7 +803,7 @@ void f() { } test_lateVar_definitelyAssigned_readWrite_prefixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late var x; @@ -861,7 +815,7 @@ void f() { } test_lateVar_definitelyAssigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable late var x; @@ -873,20 +827,19 @@ void f() { } test_lateVar_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { late var x; x; // 0 +//^ +// [diag.definitelyUnassignedLateLocalVariable] The late local variable 'x' is definitely unassigned at this point. } -''', - [error(diag.definitelyUnassignedLateLocalVariable, 27, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_lateVar_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { late var x; if (b) x = 0; @@ -897,7 +850,7 @@ void f(bool b) { } test_lateVar_neither_readWrite_compoundAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late var x; @@ -909,7 +862,7 @@ void f(bool b) { } test_lateVar_neither_readWrite_postfixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late var x; @@ -921,7 +874,7 @@ void f(bool b) { } test_lateVar_neither_readWrite_prefixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late var x; @@ -933,7 +886,7 @@ void f(bool b) { } test_lateVar_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable late var x; @@ -945,7 +898,7 @@ void f(bool b) { } test_notNullable_write_forEachLoop_identifier() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int x; for (x in [0, 1, 2]) { @@ -958,7 +911,7 @@ void f() { } test_nullable_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? x) { x; } @@ -967,7 +920,7 @@ void f(int? x) { } test_nullable_definitelyAssigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? x) { x = 0; } @@ -976,7 +929,7 @@ void f(int? x) { } test_nullable_definitelyUnassigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int? x; x; // 0 @@ -986,7 +939,7 @@ void f() { } test_nullable_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable int? x; @@ -997,7 +950,7 @@ void f() { } test_nullable_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { int? x; if (b) x = 0; @@ -1008,7 +961,7 @@ void f(bool b) { } test_nullable_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable int? x; @@ -1020,7 +973,7 @@ void f(bool b) { } test_potentiallyNonNullable_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { x; // 0 } @@ -1029,7 +982,7 @@ void f(T x) { } test_potentiallyNonNullable_definitelyAssigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T x, T t) { x = t; } @@ -1038,20 +991,19 @@ void f(T x, T t) { } test_potentiallyNonNullable_definitelyUnassigned_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { T x; x; // 0 +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'x' must be assigned before it can be used. } -''', - [error(diag.notAssignedPotentiallyNonNullableLocalVariable, 23, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: true); } test_potentiallyNonNullable_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(T t) { // ignore:unused_local_variable T x; @@ -1062,21 +1014,20 @@ void f(T t) { } test_potentiallyNonNullable_neither_read() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, T t) { T x; if (b) x = t; x; // 0 +//^ +// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'x' must be assigned before it can be used. } -''', - [error(diag.notAssignedPotentiallyNonNullableLocalVariable, 50, 1)], - ); +'''); _assertAssigned('x; // 0', assigned: false, unassigned: false); } test_potentiallyNonNullable_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b, T t, T t2) { // ignore:unused_local_variable T x; @@ -1088,7 +1039,7 @@ void f(bool b, T t, T t2) { } test_var_definitelyAssigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { x; } @@ -1097,7 +1048,7 @@ void f(x) { } test_var_definitelyAssigned_readWrite_compoundAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { x += 1; } @@ -1106,7 +1057,7 @@ void f(x) { } test_var_definitelyAssigned_readWrite_postfixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { x++; } @@ -1115,7 +1066,7 @@ void f(x) { } test_var_definitelyAssigned_readWrite_prefixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { ++x; } @@ -1124,7 +1075,7 @@ void f(x) { } test_var_definitelyAssigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(x) { x = 0; } @@ -1133,7 +1084,7 @@ void f(x) { } test_var_definitelyUnassigned_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var x; x; // 0 @@ -1143,7 +1094,7 @@ void f() { } test_var_definitelyUnassigned_readWrite_compoundAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable var x; @@ -1154,7 +1105,7 @@ void f() { } test_var_definitelyUnassigned_readWrite_postfixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable var x; @@ -1165,7 +1116,7 @@ void f() { } test_var_definitelyUnassigned_readWrite_prefixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable var x; @@ -1176,7 +1127,7 @@ void f() { } test_var_definitelyUnassigned_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable var x; @@ -1187,7 +1138,7 @@ void f() { } test_var_neither_read() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { var x; if (b) x = 0; @@ -1198,7 +1149,7 @@ void f(bool b) { } test_var_neither_readWrite_compoundAssignment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable var x; @@ -1206,11 +1157,11 @@ void f(bool b) { x += 1; } '''); - _assertAssigned('x += 1', assigned: false, unassigned: false); + _assertAssigned('x +=', assigned: false, unassigned: false); } test_var_neither_readWrite_postfixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable var x; @@ -1222,7 +1173,7 @@ void f(bool b) { } test_var_neither_readWrite_prefixIncrement() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable var x; @@ -1234,7 +1185,7 @@ void f(bool b) { } test_var_neither_write() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(bool b) { // ignore:unused_local_variable var x; diff --git a/pkg/analyzer/test/src/diagnostics/nullable_type_in_catch_clause_test.dart b/pkg/analyzer/test/src/diagnostics/nullable_type_in_catch_clause_test.dart index 6d7d6449ac8..857fa35976c 100644 --- a/pkg/analyzer/test/src/diagnostics/nullable_type_in_catch_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/nullable_type_in_catch_clause_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullableTypeInCatchClauseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullableTypeInCatchClauseTest extends PubPackageResolutionTest { test_noOnClause() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f() { try { } catch (e) { @@ -26,21 +27,20 @@ f() { } test_on_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} f() { try { } on dynamic { +// ^^^^^^^ +// [diag.nullableTypeInCatchClause] A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression. } } -''', - [error(diag.nullableTypeInCatchClause, 32, 7)], - ); +'''); } test_on_functionType_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f() { try { } on void Function() { @@ -50,20 +50,19 @@ f() { } test_on_functionType_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { try { } on void Function()? { +// ^^^^^^^^^^^^^^^^ +// [diag.nullableTypeInCatchClause] A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression. } } -''', - [error(diag.nullableTypeInCatchClause, 21, 16)], - ); +'''); } test_on_interfaceType_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f() { try { } on int { @@ -73,20 +72,19 @@ f() { } test_on_interfaceType_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' f() { try { } on int? { +// ^^^^ +// [diag.nullableTypeInCatchClause] A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression. } } -''', - [error(diag.nullableTypeInCatchClause, 21, 4)], - ); +'''); } test_on_typeParameter_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { m() { try { @@ -98,17 +96,16 @@ class A { } test_on_typeParameter_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { m() { try { } on B { +// ^ +// [diag.nullableTypeInCatchClause] A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression. } } } -''', - [error(diag.nullableTypeInCatchClause, 40, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/nullable_type_in_extends_clause_test.dart b/pkg/analyzer/test/src/diagnostics/nullable_type_in_extends_clause_test.dart index e367233e68d..178a60109a8 100644 --- a/pkg/analyzer/test/src/diagnostics/nullable_type_in_extends_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/nullable_type_in_extends_clause_test.dart @@ -2,60 +2,58 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullableTypeInExtendsClauseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullableTypeInExtendsClauseTest extends PubPackageResolutionTest { test_class_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B extends A {} '''); } test_class_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} class B extends A? {} -''', - [error(diag.nullableTypeInExtendsClause, 27, 2)], - ); +// ^^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_class_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A; class C extends B? {} -''', - [error(diag.nullableTypeInExtendsClause, 42, 2)], - ); +// ^^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_class_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A?; class C extends B {} -''', - [error(diag.nullableTypeInExtendsClause, 43, 1)], - ); +// ^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_classAlias_withClass_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A with B; @@ -63,42 +61,39 @@ class C = A with B; } test_classAlias_withClass_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A? with B; -''', - [error(diag.nullableTypeInExtendsClause, 32, 2)], - ); +// ^^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_classAlias_withClass_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = A; class D = C? with B; -''', - [error(diag.nullableTypeInExtendsClause, 47, 2)], - ); +// ^^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_classAlias_withClass_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = A?; class D = C with B; -''', - [error(diag.nullableTypeInExtendsClause, 48, 1)], - ); +// ^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_classAlias_withMixin_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A with B; @@ -106,37 +101,34 @@ class C = A with B; } test_classAlias_withMixin_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A? with B; -''', - [error(diag.nullableTypeInExtendsClause, 32, 2)], - ); +// ^^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_classAlias_withMixin_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = A; class D = C? with B; -''', - [error(diag.nullableTypeInExtendsClause, 47, 2)], - ); +// ^^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } test_classAlias_withMixin_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = A?; class D = C with B; -''', - [error(diag.nullableTypeInExtendsClause, 48, 1)], - ); +// ^ +// [diag.nullableTypeInExtendsClause] Nullable types can't be extended. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/nullable_type_in_implements_clause_test.dart b/pkg/analyzer/test/src/diagnostics/nullable_type_in_implements_clause_test.dart index a429fb7fd06..d400daea7b5 100644 --- a/pkg/analyzer/test/src/diagnostics/nullable_type_in_implements_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/nullable_type_in_implements_clause_test.dart @@ -2,133 +2,125 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullableTypeInImplementsClauseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullableTypeInImplementsClauseTest extends PubPackageResolutionTest { test_class_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B implements A {} '''); } test_class_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} class B implements A? {} -''', - [error(diag.nullableTypeInImplementsClause, 30, 2)], - ); +// ^^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_class_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A; class C implements B? {} -''', - [error(diag.nullableTypeInImplementsClause, 45, 2)], - ); +// ^^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_class_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A?; class C implements B {} -''', - [error(diag.nullableTypeInImplementsClause, 46, 1)], - ); +// ^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_extensionType_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} extension type E(A _) implements A {} '''); } test_extensionType_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} extension type E(A _) implements A? {} -''', - [error(diag.nullableTypeInImplementsClause, 44, 2)], - ); +// ^^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_extensionType_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A; extension type E(A _) implements B? {} -''', - [error(diag.nullableTypeInImplementsClause, 59, 2)], - ); +// ^^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_extensionType_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A?; extension type E(A _) implements B {} -''', - [error(diag.nullableTypeInImplementsClause, 60, 1)], - ); +// ^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_mixin_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B implements A {} '''); } test_mixin_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B implements A? {} -''', - [error(diag.nullableTypeInImplementsClause, 30, 2)], - ); +// ^^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_mixin_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A; mixin C implements B? {} -''', - [error(diag.nullableTypeInImplementsClause, 45, 2)], - ); +// ^^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } test_mixin_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A?; mixin C implements B {} -''', - [error(diag.nullableTypeInImplementsClause, 46, 1)], - ); +// ^ +// [diag.nullableTypeInImplementsClause] Nullable types can't be implemented. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart b/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart index fef46eaba3a..32f3b834000 100644 --- a/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/nullable_type_in_on_clause_test.dart @@ -2,55 +2,53 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullableTypeInOnClauseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullableTypeInOnClauseTest extends PubPackageResolutionTest { test_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B on A {} '''); } test_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B on A? {} -''', - [error(diag.nullableTypeInOnClause, 22, 2)], - ); +// ^^ +// [diag.nullableTypeInOnClause] Nullable types can't be used as a superclass constraint. +'''); } test_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A; mixin C on B? {} -''', - [error(diag.nullableTypeInOnClause, 37, 2)], - ); +// ^^ +// [diag.nullableTypeInOnClause] Nullable types can't be used as a superclass constraint. +'''); } test_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} typedef B = A?; mixin C on B {} -''', - [error(diag.nullableTypeInOnClause, 38, 1)], - ); +// ^ +// [diag.nullableTypeInOnClause] Nullable types can't be used as a superclass constraint. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/nullable_type_in_with_clause_test.dart b/pkg/analyzer/test/src/diagnostics/nullable_type_in_with_clause_test.dart index a4c8159bb1e..3eceb015937 100644 --- a/pkg/analyzer/test/src/diagnostics/nullable_type_in_with_clause_test.dart +++ b/pkg/analyzer/test/src/diagnostics/nullable_type_in_with_clause_test.dart @@ -2,60 +2,58 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NullableTypeInWithClauseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NullableTypeInWithClauseTest extends PubPackageResolutionTest { test_class_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' mixin A {} class B with A {} '''); } test_class_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin A {} class B with A? {} -''', - [error(diag.nullableTypeInWithClause, 24, 2)], - ); +// ^^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_class_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin A {} typedef B = A; class C with B? {} -''', - [error(diag.nullableTypeInWithClause, 39, 2)], - ); +// ^^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_class_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin A {} typedef B = A?; class C with B {} -''', - [error(diag.nullableTypeInWithClause, 40, 1)], - ); +// ^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_classAlias_withClass_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A with B; @@ -63,42 +61,39 @@ class C = A with B; } test_classAlias_withClass_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A with B?; -''', - [error(diag.nullableTypeInWithClause, 39, 2)], - ); +// ^^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_classAlias_withClass_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = B; class D = A with C?; -''', - [error(diag.nullableTypeInWithClause, 54, 2)], - ); +// ^^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_classAlias_withClass_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = B?; class D = A with C; -''', - [error(diag.nullableTypeInWithClause, 55, 1)], - ); +// ^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_classAlias_withMixin_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A with B; @@ -106,37 +101,34 @@ class C = A with B; } test_classAlias_withMixin_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} class C = A with B?; -''', - [error(diag.nullableTypeInWithClause, 39, 2)], - ); +// ^^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_classAlias_withMixin_nullable_alias() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = B; class D = A with C?; -''', - [error(diag.nullableTypeInWithClause, 54, 2)], - ); +// ^^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } test_classAlias_withMixin_nullable_alias2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} mixin B {} typedef C = B?; class D = A with C; -''', - [error(diag.nullableTypeInWithClause, 55, 1)], - ); +// ^ +// [diag.nullableTypeInWithClause] Nullable types can't be mixed in. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/number_literals_with_separators_test.dart b/pkg/analyzer/test/src/diagnostics/number_literals_with_separators_test.dart index 501aa407655..a760b383aac 100644 --- a/pkg/analyzer/test/src/diagnostics/number_literals_with_separators_test.dart +++ b/pkg/analyzer/test/src/diagnostics/number_literals_with_separators_test.dart @@ -2,75 +2,115 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; -import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NumberLiteralsWithSeparatorsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class NumberLiteralsWithSeparatorsTest extends PubPackageResolutionTest { - Future assertHasErrors(String code) async { - addTestFile(code); - await resolveTestFile(); - expect(result.diagnostics, isNotEmpty); - } - Future test_double_with_separators_and_e() async { - await assertNoErrorsInCode('double x = 1.234_567e2;'); + await resolveTestCodeWithDiagnostics(''' +double x = 1.234_567e2; +'''); } Future test_missing_number_after_e_1() async { - await assertErrorsInCode('dynamic x = 1_234_567e;', [ - error(diag.missingDigit, 21, 1), - ]); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1_234_567e; +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_missing_number_after_e_2() async { - await assertErrorsInCode('dynamic x = 1.234_567e;', [ - error(diag.missingDigit, 21, 1), - ]); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1.234_567e; +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_other_erroneous_1() async { - await assertHasErrors('dynamic x = 1_1e;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1_1e; +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_other_erroneous_2() async { - await assertHasErrors('dynamic x = 1_e;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1_e; +// ^ +// [diag.unexpectedSeparatorInNumber] Digit separators ('_') in a number literal can only be placed between two digits. +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_other_erroneous_3() async { - await assertHasErrors('dynamic x = 1e_;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1e_; +// ^ +// [diag.unexpectedSeparatorInNumber] Digit separators ('_') in a number literal can only be placed between two digits. +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_other_erroneous_4() async { - await assertHasErrors('dynamic x = 1e-_;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1e-_; +// ^ +// [diag.unexpectedSeparatorInNumber] Digit separators ('_') in a number literal can only be placed between two digits. +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_other_erroneous_5() async { - await assertHasErrors('dynamic x = 1e-_1;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1e-_1; +// ^ +// [diag.unexpectedSeparatorInNumber] Digit separators ('_') in a number literal can only be placed between two digits. +'''); } Future test_other_erroneous_6() async { - await assertHasErrors('dynamic x = 1e+_;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1e+_; +// ^ +// [diag.unexpectedSeparatorInNumber] Digit separators ('_') in a number literal can only be placed between two digits. +// ^ +// [diag.missingDigit] Decimal digit expected. +'''); } Future test_other_erroneous_7() async { - await assertHasErrors('dynamic x = 1e+_1;'); + await resolveTestCodeWithDiagnostics(''' +dynamic x = 1e+_1; +// ^ +// [diag.unexpectedSeparatorInNumber] Digit separators ('_') in a number literal can only be placed between two digits. +'''); } Future test_simple_double_with_separators() async { - await assertNoErrorsInCode('double x = 1.234_567;'); + await resolveTestCodeWithDiagnostics(''' +double x = 1.234_567; +'''); } Future test_simple_int_with_separators() async { - await assertNoErrorsInCode('int x = 1_234_567;'); + await resolveTestCodeWithDiagnostics(''' +int x = 1_234_567; +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/obsolete_colon_for_default_value_test.dart b/pkg/analyzer/test/src/diagnostics/obsolete_colon_for_default_value_test.dart index 9329d01ace6..43ea98462f6 100644 --- a/pkg/analyzer/test/src/diagnostics/obsolete_colon_for_default_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/obsolete_colon_for_default_value_test.dart @@ -2,28 +2,28 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ObsoleteColonForDefaultValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ObsoleteColonForDefaultValueTest extends PubPackageResolutionTest { test_noDefault() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({int? x}) {} '''); } test_superFormalParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { String? a; A({this.a}); @@ -31,23 +31,22 @@ class A { class B extends A { B({super.a : ''}); +// ^ +// [diag.obsoleteColonForDefaultValue] Using a colon as the separator before a default value is no longer supported. } -''', - [error(diag.obsoleteColonForDefaultValue, 74, 1)], - ); +'''); } test_usesColon() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f({int x : 0}) {} -''', - [error(diag.obsoleteColonForDefaultValue, 14, 1)], - ); +// ^ +// [diag.obsoleteColonForDefaultValue] Using a colon as the separator before a default value is no longer supported. +'''); } test_usesEqual() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f({int x = 0}) {} '''); } diff --git a/pkg/analyzer/test/src/diagnostics/on_repeated_test.dart b/pkg/analyzer/test/src/diagnostics/on_repeated_test.dart index 83bd9cfa03e..153e188f3f7 100644 --- a/pkg/analyzer/test/src/diagnostics/on_repeated_test.dart +++ b/pkg/analyzer/test/src/diagnostics/on_repeated_test.dart @@ -6,23 +6,24 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(OnRepeatedTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class OnRepeatedTest extends PubPackageResolutionTest { test_2times() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A, A {} -''', - [error(diag.onRepeated, 25, 1)], - ); +// ^ +// [diag.onRepeated] The type 'A' can be included in the superclass constraints only once. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -46,13 +47,12 @@ augment mixin M on A {} } test_2times_viaTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} typedef B = A; mixin M on A, B {} -''', - [error(diag.onRepeated, 40, 1)], - ); +// ^ +// [diag.onRepeated] The type 'A' can be included in the superclass constraints only once. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/optional_parameter_in_operator_test.dart b/pkg/analyzer/test/src/diagnostics/optional_parameter_in_operator_test.dart index 79d7b2ed5a3..ae4949b450d 100644 --- a/pkg/analyzer/test/src/diagnostics/optional_parameter_in_operator_test.dart +++ b/pkg/analyzer/test/src/diagnostics/optional_parameter_in_operator_test.dart @@ -2,54 +2,52 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(OptionalParameterInOperatorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class OptionalParameterInOperatorTest extends PubPackageResolutionTest { test_optionalNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +({Object? other}) => 0; +// ^^^^^^^^^^^^^ +// [diag.optionalParameterInOperator] Optional parameters aren't allowed when defining an operator. } -''', - [error(diag.optionalParameterInOperator, 28, 13)], - ); +'''); } test_optionalPositional() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +([Object? other]) => 0; +// ^^^^^^^^^^^^^ +// [diag.optionalParameterInOperator] Optional parameters aren't allowed when defining an operator. } -''', - [error(diag.optionalParameterInOperator, 28, 13)], - ); +'''); } test_requiredNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +({required Object other}) => 0; +// ^^^^^^^^^^^^^^^^^^^^^ +// [diag.optionalParameterInOperator] Optional parameters aren't allowed when defining an operator. } -''', - [error(diag.optionalParameterInOperator, 28, 21)], - ); +'''); } test_requiredPositional() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +(Object other) => 0; } diff --git a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_field_test.dart b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_field_test.dart index 4bc56c28304..9f626b86ea2 100644 --- a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_field_test.dart +++ b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_field_test.dart @@ -2,37 +2,38 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(OverrideOnNonOverridingFieldTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class OverrideOnNonOverridingFieldTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { @override int? foo; +// ^^^ +// [diag.overrideOnNonOverridingField] The field doesn't override an inherited getter or setter. } -''', - [error(diag.overrideOnNonOverridingField, 29, 3)], - ); +'''); } test_class_extends() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get a => 0; void set b(_) {} +// ^ +// [context 1] The setter being overridden. int c = 0; } class B extends A { @@ -40,22 +41,15 @@ class B extends A { final int a = 1; @override int b = 0; +// ^ +// [diag.invalidOverrideSetter][context 1] The setter 'B.b' ('void Function(int)') isn't a valid override of 'A.b' ('void Function(dynamic)'). @override int c = 0; -}''', - [ - error( - diag.invalidOverrideSetter, - 131, - 1, - contextMessages: [message(testFile, 39, 1)], - ), - ], - ); +}'''); } test_class_extends_primaryConstructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { int get foo; } @@ -64,7 +58,7 @@ class B(@override final int foo) extends A; } test_class_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get a => 0; } @@ -75,28 +69,22 @@ class B implements A { } test_class_implements_overriddenSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void set b(_) {} +// ^ +// [context 1] The setter being overridden. } class B implements A { @override int b = 0; -}''', - [ - error( - diag.invalidOverrideSetter, - 72, - 1, - contextMessages: [message(testFile, 21, 1)], - ), - ], - ); +// ^ +// [diag.invalidOverrideSetter][context 1] The setter 'B.b' ('void Function(int)') isn't a valid override of 'A.b' ('void Function(dynamic)'). +}'''); } test_class_implements_overrideIsFinal() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int c = 0; } @@ -107,48 +95,45 @@ class B implements A { } test_class_implements_primaryConstructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A(final int foo); class B(@override final int foo) implements A; '''); } test_class_primaryConstructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(@override final int foo); -''', - [error(diag.overrideOnNonOverridingField, 28, 3)], - ); +// ^^^ +// [diag.overrideOnNonOverridingField] The field doesn't override an inherited getter or setter. +'''); } test_class_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { @override static int foo = 1; +// ^^^ +// [diag.overrideOnNonOverridingField] The field doesn't override an inherited getter or setter. } -''', - [error(diag.overrideOnNonOverridingField, 35, 3)], - ); +'''); } test_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; @override final int foo = 0; +// ^^^ +// [diag.overrideOnNonOverridingField] The field doesn't override an inherited getter or setter. } -''', - [error(diag.overrideOnNonOverridingField, 38, 3)], - ); +'''); } test_enum_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get a => 0; void set b(int _) {} @@ -166,7 +151,7 @@ enum E implements A { } test_enum_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int get a => 0; void set b(int _) {} diff --git a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_getter_test.dart b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_getter_test.dart index 7598ce2dea1..ea346dc0446 100644 --- a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_getter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_getter_test.dart @@ -2,33 +2,33 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(OverrideOnNonOverridingGetterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class OverrideOnNonOverridingGetterTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { @override int get foo => 0; +// ^^^ +// [diag.overrideOnNonOverridingGetter] The getter doesn't override an inherited getter. } -''', - [error(diag.overrideOnNonOverridingGetter, 32, 3)], - ); +'''); } test_class_extends() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; } @@ -41,7 +41,7 @@ class B extends A { } test_class_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; } @@ -54,32 +54,30 @@ class B implements A { } test_class_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { @override static int get foo => 0; +// ^^^ +// [diag.overrideOnNonOverridingGetter] The getter doesn't override an inherited getter. } -''', - [error(diag.overrideOnNonOverridingGetter, 39, 3)], - ); +'''); } test_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; @override int get foo => 0; +// ^^^ +// [diag.overrideOnNonOverridingGetter] The getter doesn't override an inherited getter. } -''', - [error(diag.overrideOnNonOverridingGetter, 36, 3)], - ); +'''); } test_enum_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; } @@ -93,7 +91,7 @@ enum E implements A { } test_enum_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int get foo => 0; } @@ -107,36 +105,33 @@ enum E with M { } test_extension() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { @override int get foo => 1; +// ^^^ +// [diag.overrideOnNonOverridingGetter] The getter doesn't override an inherited getter. } -''', - [error(diag.overrideOnNonOverridingGetter, 43, 3)], - ); +'''); } test_mixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { @override int get foo => 0; +// ^^^ +// [diag.overrideOnNonOverridingGetter] The getter doesn't override an inherited getter. } -''', - [error(diag.overrideOnNonOverridingGetter, 32, 3)], - ); +'''); } test_topLevel() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' @override int get foo => 1; -''', - [error(diag.overrideOnNonOverridingGetter, 18, 3)], - ); +// ^^^ +// [diag.overrideOnNonOverridingGetter] The getter doesn't override an inherited getter. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_method_test.dart b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_method_test.dart index 848ad48e1ba..5a416b6283f 100644 --- a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_method_test.dart +++ b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_method_test.dart @@ -2,35 +2,35 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(OverrideOnNonOverridingMethodTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class OverrideOnNonOverridingMethodTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A { @override void foo() {} +// ^^^ +// [diag.overrideOnNonOverridingMethod] The method doesn't override an inherited method. } -''', - [error(diag.overrideOnNonOverridingMethod, 51, 3)], - ); +'''); } test_class_extends() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -42,7 +42,7 @@ class B extends A { } test_class_extends_abstract() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -54,7 +54,7 @@ class B extends A { } test_class_extends_wildcardParams() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo(int x) {} } @@ -66,7 +66,7 @@ class B extends A { } test_class_extends_wildcardParams_preWildCards() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) @@ -81,23 +81,22 @@ class B extends A { } test_class_field_missingName() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { +// ^ +// [diag.unusedField][column 7][length 0] The value of the field '' isn't used. @override Object? foo,; +// ^^^ +// [diag.overrideOnNonOverridingField] The field doesn't override an inherited getter or setter. +// ^ +// [diag.missingIdentifier] Expected an identifier. } -''', - [ - error(diag.unusedField, 6, 0), - error(diag.overrideOnNonOverridingField, 32, 3), - error(diag.missingIdentifier, 36, 1), - ], - ); +'''); } test_class_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -109,7 +108,7 @@ class B implements A { } test_class_implements2() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class I { void foo(int _); } @@ -125,60 +124,56 @@ class C implements I, J { } test_class_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A { @override static void foo() {} +// ^^^ +// [diag.overrideOnNonOverridingMethod] The method doesn't override an inherited method. } -''', - [error(diag.overrideOnNonOverridingMethod, 58, 3)], - ); +'''); } test_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; @override void foo() {} +// ^^^ +// [diag.overrideOnNonOverridingMethod] The method doesn't override an inherited method. } -''', - [error(diag.overrideOnNonOverridingMethod, 33, 3)], - ); +'''); } test_extension() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { @override void foo() {} +// ^^^ +// [diag.overrideOnNonOverridingMethod] The method doesn't override an inherited method. } -''', - [error(diag.overrideOnNonOverridingMethod, 40, 3)], - ); +'''); } test_mixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A { @override void foo() {} +// ^^^ +// [diag.overrideOnNonOverridingMethod] The method doesn't override an inherited method. } -''', - [error(diag.overrideOnNonOverridingMethod, 46, 3)], - ); +'''); } test_mixin_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -191,7 +186,7 @@ mixin M implements A { } test_mixin_on() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } diff --git a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_setter_test.dart b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_setter_test.dart index ae80742c4bd..e74625a2c05 100644 --- a/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_setter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/override_on_non_overriding_setter_test.dart @@ -2,35 +2,35 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(OverrideOnNonOverridingSetterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class OverrideOnNonOverridingSetterTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A { @override set foo(int _) {} +// ^^^ +// [diag.overrideOnNonOverridingSetter] The setter doesn't override an inherited setter. } -''', - [error(diag.overrideOnNonOverridingSetter, 50, 3)], - ); +'''); } test_class_extends() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set m(int x) {} } @@ -41,7 +41,7 @@ class B extends A { } test_class_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set m(int x) {} } @@ -52,34 +52,32 @@ class B implements A { } test_class_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B extends A { @override static set foo(int _) {} +// ^^^ +// [diag.overrideOnNonOverridingSetter] The setter doesn't override an inherited setter. } -''', - [error(diag.overrideOnNonOverridingSetter, 57, 3)], - ); +'''); } test_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; @override set foo(int _) {} +// ^^^ +// [diag.overrideOnNonOverridingSetter] The setter doesn't override an inherited setter. } -''', - [error(diag.overrideOnNonOverridingSetter, 32, 3)], - ); +'''); } test_enum_implements() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set foo(int _) {} } @@ -93,7 +91,7 @@ enum E implements A { } test_enum_with() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { set foo(int _) {} } @@ -107,38 +105,35 @@ enum E with M { } test_extension() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { @override set foo(int _) {} +// ^^^ +// [diag.overrideOnNonOverridingSetter] The setter doesn't override an inherited setter. } -''', - [error(diag.overrideOnNonOverridingSetter, 39, 3)], - ); +'''); } test_mixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M on A { @override set foo(int _) {} +// ^^^ +// [diag.overrideOnNonOverridingSetter] The setter doesn't override an inherited setter. } -''', - [error(diag.overrideOnNonOverridingSetter, 45, 3)], - ); +'''); } test_topLevel() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' @override set foo(int _) {} -''', - [error(diag.overrideOnNonOverridingSetter, 14, 3)], - ); +// ^^^ +// [diag.overrideOnNonOverridingSetter] The setter doesn't override an inherited setter. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/packed_annotation_alignment_test.dart b/pkg/analyzer/test/src/diagnostics/packed_annotation_alignment_test.dart index 790bd13959d..c4c8330e26c 100644 --- a/pkg/analyzer/test/src/diagnostics/packed_annotation_alignment_test.dart +++ b/pkg/analyzer/test/src/diagnostics/packed_annotation_alignment_test.dart @@ -2,35 +2,35 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PackedAnnotationAlignment); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PackedAnnotationAlignment extends PubPackageResolutionTest { test_error() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed(3) +// ^ +// [diag.packedAnnotationAlignment] Only packing to 1, 2, 4, 8, and 16 bytes is supported. final class C extends Struct { external Pointer notEmpty; } -''', - [error(diag.packedAnnotationAlignment, 28, 1)], - ); +'''); } test_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed(1) diff --git a/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart b/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart index 43f6c670d00..b3b03f864c2 100644 --- a/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart +++ b/pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart @@ -2,54 +2,50 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PackedAnnotation); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PackedAnnotation extends PubPackageResolutionTest { test_error_double() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed(1) @Packed(1) +// [diag.packedAnnotation][column 1][length 10] Structs must have at most one 'Packed' annotation. final class C extends Struct { external Pointer notEmpty; } -''', - [error(diag.packedAnnotation, 31, 10)], - ); +'''); } /// Regress test for http://dartbug.com/45498. test_error_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed() +// [diag.packedAnnotationAlignment][column 1][length 9] Only packing to 1, 2, 4, 8, and 16 bytes is supported. +// ^ +// [diag.notEnoughPositionalArgumentsNameSingular] 1 positional argument expected by 'Packed.new', but 0 found. final class C extends Struct { external Pointer notEmpty; } -''', - [ - error(diag.packedAnnotationAlignment, 20, 9), - error(diag.notEnoughPositionalArgumentsNameSingular, 28, 1), - ], - ); +'''); } test_no_error_struct_no_annotation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @@ -59,7 +55,7 @@ final class C extends Struct { } test_no_error_struct_one_annotation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed(1) @@ -71,7 +67,7 @@ final class C extends Struct { /// Doesn't do anything on Unions. test_no_error_union_no_annotation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Union { @@ -82,7 +78,7 @@ final class C extends Union { /// Doesn't do anything on Unions. test_no_error_union_one_annotation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed(1) @@ -94,7 +90,7 @@ final class C extends Union { /// Doesn't do anything on Unions. test_no_error_union_two_annotations() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @Packed(1) diff --git a/pkg/analyzer/test/src/diagnostics/part_of_non_part_test.dart b/pkg/analyzer/test/src/diagnostics/part_of_non_part_test.dart index 3f9fd3a653e..fbb4e512fe9 100644 --- a/pkg/analyzer/test/src/diagnostics/part_of_non_part_test.dart +++ b/pkg/analyzer/test/src/diagnostics/part_of_non_part_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PartOfNonPartTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,13 +20,12 @@ class PartOfNonPartTest extends PubPackageResolutionTest { newFile('$testPackageLibPath/l2.dart', ''' library l2; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' library l1; part 'l2.dart'; -''', - [error(diag.partOfNonPart, 17, 9)], - ); +// ^^^^^^^^^ +// [diag.partOfNonPart] The included part 'package:test/l2.dart' must have a part-of directive. +'''); } test_partOf_dotted() async { @@ -34,19 +34,18 @@ part of foo.bar; '''); // No error reported in the library, only in the part. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' library foo.bar; part 'a.dart'; '''); } test_self() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' library lib; part 'test.dart'; -''', - [error(diag.partOfNonPart, 18, 11)], - ); +// ^^^^^^^^^^^ +// [diag.partOfNonPart] The included part 'package:test/test.dart' must have a part-of directive. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/pattern_assignment_not_local_variable_test.dart b/pkg/analyzer/test/src/diagnostics/pattern_assignment_not_local_variable_test.dart index f26fea1a245..3ad073c472d 100644 --- a/pkg/analyzer/test/src/diagnostics/pattern_assignment_not_local_variable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/pattern_assignment_not_local_variable_test.dart @@ -2,43 +2,42 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PatternAssignmentNotLocalVariableTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PatternAssignmentNotLocalVariableTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() { (int) = 0; +// ^^^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } -''', - [error(diag.patternAssignmentNotLocalVariable, 14, 3)], - ); +'''); } test_class_instanceField_ofSelf() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { var x = 0; void f() { (x) = 0; +// ^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } } -''', - [error(diag.patternAssignmentNotLocalVariable, 42, 1)], - ); +'''); var node = findNode.singlePatternAssignment; assertResolvedNodeText(node, r''' @@ -61,8 +60,7 @@ PatternAssignment } test_class_instanceField_ofSuperClass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { var x = 0; } @@ -70,11 +68,11 @@ class A { class B extends A { void f() { (x) = 0; +// ^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } } -''', - [error(diag.patternAssignmentNotLocalVariable, 64, 1)], - ); +'''); var node = findNode.singlePatternAssignment; assertResolvedNodeText(node, r''' @@ -97,18 +95,17 @@ PatternAssignment } test_class_staticField() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static var x = 0; void f() { (x) = 0; +// ^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } } -''', - [error(diag.patternAssignmentNotLocalVariable, 49, 1)], - ); +'''); var node = findNode.singlePatternAssignment; assertResolvedNodeText(node, r''' @@ -131,50 +128,46 @@ PatternAssignment } test_class_typeParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { void f() { (T) = 0; +// ^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } } -''', - [error(diag.patternAssignmentNotLocalVariable, 31, 1)], - ); +'''); } test_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() { (dynamic) = 0; +// ^^^^^^^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } -''', - [error(diag.patternAssignmentNotLocalVariable, 14, 7)], - ); +'''); } test_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() { (f) = 0; +// ^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } -''', - [error(diag.patternAssignmentNotLocalVariable, 14, 1)], - ); +'''); } test_topLevelVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var x = 0; void f() { (x) = 0; +// ^ +// [diag.patternAssignmentNotLocalVariable] Only local variables can be assigned in pattern assignments. } -''', - [error(diag.patternAssignmentNotLocalVariable, 26, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/pattern_never_matches_value_type_test.dart b/pkg/analyzer/test/src/diagnostics/pattern_never_matches_value_type_test.dart index 07400df337e..fdf1cb49fdb 100644 --- a/pkg/analyzer/test/src/diagnostics/pattern_never_matches_value_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/pattern_never_matches_value_type_test.dart @@ -2,32 +2,32 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PatternNeverMatchesValueTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PatternNeverMatchesValueTypeTest extends PubPackageResolutionTest { test_functionType_interfaceType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function() x) { if (x case int _) {} +// ^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'void Function()' can never match the required type 'int'. } -''', - [error(diag.patternNeverMatchesValueType, 41, 3)], - ); +'''); } test_functionType_interfaceType_function() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function() x) { if (x case Function _) {} } @@ -35,7 +35,7 @@ void f(void Function() x) { } test_functionType_interfaceType_object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function() x) { if (x case Object _) {} } @@ -43,7 +43,7 @@ void f(void Function() x) { } test_functionType_interfaceType_objectQuestion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function() x) { if (x case Object? _) {} } @@ -51,18 +51,17 @@ void f(void Function() x) { } test_functionType_recordType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function() x) { if (x case (int,) _) {} +// ^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'void Function()' can never match the required type '(int,)'. } -''', - [error(diag.patternNeverMatchesValueType, 41, 6)], - ); +'''); } test_functionTypeQuestion_interfaceType_object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function()? x) { if (x case Object _) {} } @@ -70,7 +69,7 @@ void f(void Function()? x) { } test_functionTypeQuestion_interfaceType_objectQuestion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function()? x) { if (x case Object? _) {} } @@ -78,7 +77,7 @@ void f(void Function()? x) { } test_interfaceType2_generic_argumentsMatch() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(List x) { if (x case List _) {} } @@ -89,21 +88,20 @@ final class B extends A {} } test_interfaceType2_generic_argumentsNotMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(List x) { if (x case List _) {} +// ^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'List' can never match the required type 'List'. } final class A {} final class B {} -''', - [error(diag.patternNeverMatchesValueType, 33, 7)], - ); +'''); } test_interfaceType2_matchedDouble_requiredInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(double x) { if (x case int _) {} } @@ -111,7 +109,7 @@ void f(double x) { } test_interfaceType2_matchedExtensionType_requiredExtensionType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case A _) {} } @@ -121,7 +119,7 @@ extension type A(int _) {} } test_interfaceType2_matchedExtensionType_requiredRepresentation() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case int _) {} } @@ -131,10 +129,11 @@ extension type A(int _) {} } test_interfaceType2_matchedExtensionTypeUnrelated_requiredFinal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case C _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'C'. } extension type A(B _) {} @@ -142,13 +141,11 @@ extension type A(B _) {} class B {} final class C {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_matchedFinal_enumSubtype() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case E _) {} } @@ -161,23 +158,22 @@ enum E implements A { } test_interfaceType2_matchedFinal_hasSubtypes_noneImplementsRequired() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } final class A {} final class A2 extends A {} final class A3 implements A {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_matchedFinal_hasSubtypes_oneExtendsRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -189,7 +185,7 @@ class R {} } test_interfaceType2_matchedFinal_hasSubtypes_oneImplementsRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -201,7 +197,7 @@ class R {} } test_interfaceType2_matchedFinal_hasSubtypes_oneImplementsRequired2() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -214,7 +210,7 @@ class R {} } test_interfaceType2_matchedFinal_hasSubtypes_oneMixesRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -226,7 +222,7 @@ mixin class R {} } test_interfaceType2_matchedFinal_it_implementsGenericRequired_isGeneric_argumentCouldMatch() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -237,21 +233,20 @@ class R {} } test_interfaceType2_matchedFinal_it_implementsGenericRequired_notGeneric_differentArguments() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } final class A extends R {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 6)], - ); +'''); } test_interfaceType2_matchedFinal_itImplementsRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -262,7 +257,7 @@ class R {} } test_interfaceType2_matchedFinal_itMixesRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -273,7 +268,7 @@ mixin class R {} } test_interfaceType2_matchedFinal_requiredFutureOrIt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -285,8 +280,7 @@ void f(A x) { } test_interfaceType2_matchedFinal_requiredFutureOrOther() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -294,28 +288,27 @@ class B {} void f(A x) { if (x case FutureOr _) {} +// ^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'FutureOr'. } -''', - [error(diag.patternNeverMatchesValueType, 78, 11)], - ); +'''); } test_interfaceType2_matchedFinal_requiredUnrelated() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } final class A {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_matchedFutureFinal_requiredFutureOrIt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -327,7 +320,7 @@ void f(Future x) { } test_interfaceType2_matchedFutureOrFinal_requiredFutureIt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -339,7 +332,7 @@ void f(FutureOr x) { } test_interfaceType2_matchedFutureOrFinal_requiredFutureOrIt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -351,7 +344,7 @@ void f(FutureOr x) { } test_interfaceType2_matchedFutureOrFinal_requiredIt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -365,7 +358,7 @@ void f(FutureOr x) { /// `Future` is an interface, so there can be a class that implements both /// `B` and `Future`. test_interfaceType2_matchedFutureOrFinal_requiredOther() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; final class A {} @@ -378,7 +371,7 @@ void f(FutureOr x) { } test_interfaceType2_matchedInt_requiredDouble() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case double _) {} } @@ -386,7 +379,7 @@ void f(int x) { } test_interfaceType2_matchedObject_requiredClass() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { if (x case A _) {} } @@ -396,7 +389,7 @@ class A {} } test_interfaceType2_matchedObject_requiredFinalClass() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { if (x case int _) {} } @@ -404,7 +397,7 @@ void f(Object x) { } test_interfaceType2_matchedObjectQuestion_requiredClass() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { if (x case A _) {} } @@ -414,7 +407,7 @@ class A {} } test_interfaceType2_matchedObjectQuestion_requiredFinalClass() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { if (x case int _) {} } @@ -422,7 +415,7 @@ void f(Object? x) { } test_interfaceType2_matchedRepresentation_requiredExtensionType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case A _) {} } @@ -432,7 +425,7 @@ extension type A(int _) {} } test_interfaceType2_matchedSealed_enumSubtype() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case E _) {} } @@ -445,7 +438,7 @@ enum E implements A { } test_interfaceType2_matchedSealed_hasNonFinalSubtype() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -459,7 +452,7 @@ class R {} test_interfaceType2_matchedSealed_mixinSubtype() async { // No warning, because `M` can be implemented outside. - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case M _) {} } @@ -470,39 +463,37 @@ mixin M implements A {} } test_interfaceType2_matchedSealed_onlyFinalSubtypes_noneImplementsRequired() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } sealed class A {} final class A2 extends A {} final class A3 implements A {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_matchedSealed_onlyFinalSubtypes_noneImplementsRequired2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } sealed class A {} sealed class A2 extends A {} final class A3 implements A {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_matchedSealed_onlyFinalSubtypes_oneImplementsRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -514,7 +505,7 @@ class R {} } test_interfaceType2_requiredFinal_matchedSelf() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case A _) {} } @@ -524,7 +515,7 @@ final class A {} } test_interfaceType2_requiredFinal_matchedSelf_generic_argumentsMatch() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case A _) {} } @@ -536,22 +527,21 @@ final class C extends B {} } test_interfaceType2_requiredFinal_matchedSelf_generic_argumentsNotMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case A _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'A'. } final class A {} final class B {} final class C {} -''', - [error(diag.patternNeverMatchesValueType, 30, 4)], - ); +'''); } test_interfaceType2_requiredFinal_matchedSubtype() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(B x) { if (x case A _) {} } @@ -562,23 +552,22 @@ final class B extends A {} } test_interfaceType2_requiredFinal_matchedSubtype_generic_argumentsNotMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(B x) { if (x case A _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'B' can never match the required type 'A'. } final class A {} final class B extends A {} final class C {} final class D {} -''', - [error(diag.patternNeverMatchesValueType, 27, 4)], - ); +'''); } test_interfaceType2_requiredFinal_matchedSupertype() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B _) {} } @@ -589,7 +578,7 @@ final class B extends A {} } test_interfaceType2_requiredFinal_matchedSupertype_generic_argumentsMatch() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B _) {} } @@ -601,23 +590,22 @@ final class C {} } test_interfaceType2_requiredFinal_matchedSupertype_generic_argumentsNotMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'B'. } class A {} final class B extends A {} final class C {} final class D {} -''', - [error(diag.patternNeverMatchesValueType, 30, 1)], - ); +'''); } test_interfaceType2_requiredFinal_matchedSupertype_generic_differentArguments() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B _) {} } @@ -628,21 +616,20 @@ final class B extends A {} } test_interfaceType2_requiredFinal_matchedUnrelated() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'B'. } class A {} final class B {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_requiredSealed_hasNonFinalSubtype() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -655,23 +642,22 @@ class R2 extends R {} } test_interfaceType2_requiredSealed_onlyFinalSubtypes_noneImplementsMatched() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } class A {} sealed class R {} final class R1 extends R {} final class R2 extends R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_interfaceType2_requiredSealed_onlyFinalSubtypes_oneImplementsMatched() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -684,18 +670,17 @@ final class R2 extends R implements A {} } test_interfaceType_functionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case void Function() _) {} +// ^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'int' can never match the required type 'void Function()'. } -''', - [error(diag.patternNeverMatchesValueType, 29, 15)], - ); +'''); } test_interfaceType_functionType_function() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Function x) { if (x case void Function() _) {} } @@ -703,7 +688,7 @@ void f(Function x) { } test_interfaceType_functionType_object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { if (x case void Function() _) {} } @@ -711,20 +696,19 @@ void f(Object x) { } test_interfaceType_recordType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case (A,) _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type '(A,)'. } class A {} -''', - [error(diag.patternNeverMatchesValueType, 27, 4)], - ); +'''); } test_interfaceType_recordType_object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { if (x case (int,) _) {} } @@ -732,7 +716,7 @@ void f(Object x) { } test_interfaceType_recordType_record() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Record x) { if (x case (int,) _) {} } @@ -740,35 +724,33 @@ void f(Record x) { } test_matchedEnum_requiredDifferentEnum() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } enum A { v } enum R { v } -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_matchedEnum_requiredNotEnum() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } enum A { v } class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 1)], - ); +'''); } test_matchedEnum_requiredNotEnum_implemented() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -779,7 +761,7 @@ class R {} } test_matchedEnum_requiredNotEnum_implemented_generic_rightTypeArguments() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -790,7 +772,7 @@ class R {} } test_matchedEnum_requiredNotEnum_implemented_generic_rightTypeArguments2() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -805,24 +787,24 @@ class R {} } test_matchedEnum_requiredNotEnum_implemented_generic_wrongTypeArguments() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } enum A implements R { v } class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 6)], - ); +'''); } test_matchedEnum_requiredNotEnum_implemented_generic_wrongTypeArguments2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} +// ^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'R'. } enum A implements R { @@ -831,13 +813,11 @@ enum A implements R { } class R {} -''', - [error(diag.patternNeverMatchesValueType, 27, 9)], - ); +'''); } test_matchedEnum_requiredNotEnum_mixed() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case R _) {} } @@ -848,7 +828,7 @@ mixin R {} } test_matchedEnum_requiredSameEnum() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(E? x) { if (x case E _) {} } @@ -858,7 +838,7 @@ enum E { v } } test_matchedEnum_requiredSameEnum_generic_hasValue() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(E? x) { if (x case E _) {} } @@ -868,20 +848,19 @@ enum E { v() } } test_matchedEnum_requiredSameEnum_generic_noValue() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(E? x) { if (x case E _) {} +// ^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'E?' can never match the required type 'E'. } enum E { v1(), v2() } -''', - [error(diag.patternNeverMatchesValueType, 34, 9)], - ); +'''); } test_matchedFutureOrRecord_requiredFutureRecord_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(FutureOr<(int,)> x) { @@ -891,20 +870,19 @@ void f(FutureOr<(int,)> x) { } test_matchedFutureOrRecord_requiredFutureRecord_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(FutureOr<(int,)> x) { if (x case Future<(String,)> _) {} +// ^^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'FutureOr<(int,)>' can never match the required type 'Future<(String,)>'. } -''', - [error(diag.patternNeverMatchesValueType, 64, 17)], - ); +'''); } test_matchedFutureOrRecord_requiredRecord_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(FutureOr<(int,)> x) { @@ -914,20 +892,19 @@ void f(FutureOr<(int,)> x) { } test_matchedFutureOrRecord_requiredRecord_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(FutureOr<(int,)> x) { if (x case (String,) _) {} +// ^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'FutureOr<(int,)>' can never match the required type '(String,)'. } -''', - [error(diag.patternNeverMatchesValueType, 64, 9)], - ); +'''); } test_matchedFutureRecord_requiredFutureOrRecord_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(Future<(int,)> x) { @@ -937,36 +914,33 @@ void f(Future<(int,)> x) { } test_matchedFutureRecord_requiredFutureOrRecord_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(Future<(int,)> x) { if (x case FutureOr<(String,)> _) {} +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'Future<(int,)>' can never match the required type 'FutureOr<(String,)>'. } -''', - [error(diag.patternNeverMatchesValueType, 62, 19)], - ); +'''); } test_matchedNull_requiredNotNullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Null x) { if (x case A _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type 'Null' can never match the required type 'A'. +// ^^ +// [diag.deadCode] Dead code. } class A {} -''', - [ - error(diag.patternNeverMatchesValueType, 30, 1), - error(diag.deadCode, 35, 2), - ], - ); +'''); } test_matchedNull_requiredNull() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Null x) { if (x case Null _) {} } @@ -974,21 +948,19 @@ void f(Null x) { } test_matchedNull_requiredObject() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Null x) { if (x case Object _) {} +// ^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'Null' can never match the required type 'Object'. +// ^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.patternNeverMatchesValueType, 30, 6), - error(diag.deadCode, 40, 2), - ], - ); +'''); } test_matchedRecord_requiredFutureOrRecord_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f((int,) x) { @@ -998,56 +970,52 @@ void f((int,) x) { } test_matchedRecord_requiredFutureOrRecord_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f((int,) x) { if (x case FutureOr<(String,)> _) {} +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '(int,)' can never match the required type 'FutureOr<(String,)>'. } -''', - [error(diag.patternNeverMatchesValueType, 54, 19)], - ); +'''); } test_recordType2_named_differentCount() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(({int f1,}) x) { if (x case ({int f1, int f2,}) _) {} +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '({int f1})' can never match the required type '({int f1, int f2})'. } -''', - [error(diag.patternNeverMatchesValueType, 37, 19)], - ); +'''); } test_recordType2_named_differentNames() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(({int a, int b}) x) { if (x case ({int f1, int f2,}) _) {} +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '({int a, int b})' can never match the required type '({int f1, int f2})'. } -''', - [error(diag.patternNeverMatchesValueType, 42, 19)], - ); +'''); } test_recordType2_named_unrelated() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(({A f1,}) x) { if (x case ({R f1,}) _) {} +// ^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '({A f1})' can never match the required type '({R f1})'. } final class A {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 35, 9)], - ); +'''); } test_recordType2_positional_canMatch() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f((A,) x) { if (x case (B,) _) {} } @@ -1058,56 +1026,52 @@ class B {} } test_recordType2_positional_differentCount() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) x) { if (x case (int, String) _) {} +// ^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '(int,)' can never match the required type '(int, String)'. } -''', - [error(diag.patternNeverMatchesValueType, 32, 13)], - ); +'''); } test_recordType2_positional_unrelated() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((A,) x) { if (x case (R,) _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '(A,)' can never match the required type '(R,)'. } final class A {} class R {} -''', - [error(diag.patternNeverMatchesValueType, 30, 4)], - ); +'''); } test_recordType_functionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) x) { if (x case void Function() _) {} +// ^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '(int,)' can never match the required type 'void Function()'. } -''', - [error(diag.patternNeverMatchesValueType, 32, 15)], - ); +'''); } test_recordType_interfaceType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((A,) x) { if (x case A _) {} +// ^ +// [diag.patternNeverMatchesValueType] The matched value type '(A,)' can never match the required type 'A'. } class A {} -''', - [error(diag.patternNeverMatchesValueType, 30, 1)], - ); +'''); } test_recordType_interfaceType_object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f((int,)? x) { if (x case Object _) {} } @@ -1115,7 +1079,7 @@ void f((int,)? x) { } test_recordType_interfaceType_record() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f((int,)? x) { if (x case Record _) {} } @@ -1123,7 +1087,7 @@ void f((int,)? x) { } test_refutable_pattern_castPattern_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case _ as int) {} } @@ -1131,43 +1095,39 @@ void f(num x) { } test_refutable_pattern_castPattern_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(String x) { if (x case _ as int) {} +// ^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'String' can never match the required type 'int'. } -''', - [error(diag.patternNeverMatchesValueType, 37, 3)], - ); +'''); } test_refutable_pattern_declaredVariablePattern_match() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case int a) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [error(diag.unusedLocalVariable, 33, 1)], - ); +'''); } test_refutable_pattern_declaredVariablePattern_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(String x) { if (x case int a) {} +// ^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'String' can never match the required type 'int'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternNeverMatchesValueType, 32, 3), - error(diag.unusedLocalVariable, 36, 1), - ], - ); +'''); } test_refutable_pattern_listPattern_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(List x) { if (x case []) {} } @@ -1175,18 +1135,17 @@ void f(List x) { } test_refutable_pattern_listPattern_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case []) {} +// ^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'int' can never match the required type 'List'. } -''', - [error(diag.patternNeverMatchesValueType, 29, 7)], - ); +'''); } test_refutable_pattern_mapPattern_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { if (x case {0: _}) {} } @@ -1194,18 +1153,17 @@ void f(Object? x) { } test_refutable_pattern_mapPattern_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case {0: _}) {} +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'int' can never match the required type 'Map'. } -''', - [error(diag.patternNeverMatchesValueType, 29, 19)], - ); +'''); } test_refutable_pattern_objectPattern_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case int()) {} } @@ -1213,50 +1171,47 @@ void f(num x) { } test_refutable_pattern_objectPattern_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(String x) { if (x case int()) {} +// ^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'String' can never match the required type 'int'. } -''', - [error(diag.patternNeverMatchesValueType, 32, 3)], - ); +'''); } test_refutable_pattern_reportPattern_match() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) x) { switch (x) { case (int f,): +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'f' isn't used. break; } } -''', - [error(diag.unusedLocalVariable, 48, 1)], - ); +'''); } test_refutable_pattern_reportPattern_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) x) { switch (x) { case (int f1, int f2): +// ^^^^^^^^^^^^^^^^ +// [diag.patternNeverMatchesValueType] The matched value type '(int,)' can never match the required type '(Object?, Object?)'. +// ^^ +// [diag.unusedLocalVariable] The value of the local variable 'f1' isn't used. +// ^^ +// [diag.unusedLocalVariable] The value of the local variable 'f2' isn't used. break; } } -''', - [ - error(diag.patternNeverMatchesValueType, 43, 16), - error(diag.unusedLocalVariable, 48, 2), - error(diag.unusedLocalVariable, 56, 2), - ], - ); +'''); } test_refutable_pattern_wildcard_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { if (x case int _) {} } @@ -1264,76 +1219,67 @@ void f(num x) { } test_refutable_pattern_wildcard_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(String x) { if (x case int _) {} +// ^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'String' can never match the required type 'int'. } -''', - [error(diag.patternNeverMatchesValueType, 32, 3)], - ); +'''); } test_requiredNull_matchedNotNullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case Null _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'Null'. +// ^^ +// [diag.deadCode] Dead code. } class A {} -''', - [ - error(diag.patternNeverMatchesValueType, 27, 4), - error(diag.deadCode, 35, 2), - ], - ); +'''); } test_requiredNull_matchedNotNullable_functionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function() x) { if (x case Null _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'void Function()' can never match the required type 'Null'. +// ^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.patternNeverMatchesValueType, 41, 4), - error(diag.deadCode, 49, 2), - ], - ); +'''); } test_requiredNull_matchedNotNullable_interfaceType_object() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { if (x case Null _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'Object' can never match the required type 'Null'. +// ^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.patternNeverMatchesValueType, 32, 4), - error(diag.deadCode, 40, 2), - ], - ); +'''); } test_requiredNull_matchedNotNullable_typeParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { if (x case Null _) {} +// ^^^^ +// [diag.patternNeverMatchesValueType] The matched value type 'T' can never match the required type 'Null'. +// ^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.patternNeverMatchesValueType, 42, 4), - error(diag.deadCode, 50, 2), - ], - ); +'''); } test_requiredNull_matchedNullable_dynamicType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic x) { if (x case Null _) {} } @@ -1341,7 +1287,7 @@ void f(dynamic x) { } test_requiredNull_matchedNullable_functionType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void Function()? x) { if (x case Null _) {} } @@ -1349,7 +1295,7 @@ void f(void Function()? x) { } test_requiredNull_matchedNullable_interfaceType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A? x) { if (x case Null _) {} } @@ -1359,7 +1305,7 @@ class A {} } test_requiredNull_matchedNullable_typeParameterType_implicitBound() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(T x) { if (x case Null _) {} } @@ -1368,7 +1314,7 @@ void f(T x) { // TODO(scheglov): We should report that `B?` should be replaced with `B`. test_requiredNullable_matchedNotNullable_match() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B? _) {} } @@ -1380,21 +1326,20 @@ final class B extends A {} /// Check that nullable does not prevent reporting the warning. test_requiredNullable_matchedNotNullable_notMatch() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(A x) { if (x case B? _) {} +// ^^ +// [diag.patternNeverMatchesValueType] The matched value type 'A' can never match the required type 'B?'. } final class A {} final class B {} -''', - [error(diag.patternNeverMatchesValueType, 27, 2)], - ); +'''); } test_requiredNullable_matchedNull() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Null x) { if (x case A? _) {} } @@ -1406,7 +1351,7 @@ final class A {} /// They match only because both can be `Null`. /// Otherwise, two unrelated final classes cannot match. test_requiredNullable_matchedNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(A? x) { if (x case B? _) {} } diff --git a/pkg/analyzer/test/src/diagnostics/pattern_type_mismatch_in_irrefutable_context_test.dart b/pkg/analyzer/test/src/diagnostics/pattern_type_mismatch_in_irrefutable_context_test.dart index 550d15c3048..6b3b590ec25 100644 --- a/pkg/analyzer/test/src/diagnostics/pattern_type_mismatch_in_irrefutable_context_test.dart +++ b/pkg/analyzer/test/src/diagnostics/pattern_type_mismatch_in_irrefutable_context_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PatternTypeMismatchInIrrefutableContextTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,22 +18,21 @@ main() { class PatternTypeMismatchInIrrefutableContextTest extends PubPackageResolutionTest { test_assignedVariablePattern_recordDestruction_hasCall() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int Function(int) a, (A,) x) { (a) = x; +// ^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type '(A,)' isn't assignable to the required type 'int Function(int)'. } class A { int call(int x) => x; } -''', - [error(diag.patternTypeMismatchInIrrefutableContext, 41, 1)], - ); +'''); } test_assignedVariablePattern_valueDynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, dynamic x) { (a) = x; } @@ -40,7 +40,7 @@ void f(int a, dynamic x) { } test_assignedVariablePattern_valueSubtype() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(num a, int x) { (a) = x; } @@ -48,162 +48,142 @@ void f(num a, int x) { } test_assignedVariablePattern_valueSupertype() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, num x) { (a) = x; +// ^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'num' isn't assignable to the required type 'int'. } -''', - [error(diag.patternTypeMismatchInIrrefutableContext, 26, 1)], - ); +'''); } test_declaredVariablePattern_recordDestruction_hasCall() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f((A,) x) { var (int Function(int) v,) = x; +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'A' isn't assignable to the required type 'int Function(int)'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } class A { int call(int x) => x; } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 24, 19), - error(diag.unusedLocalVariable, 42, 1), - ], - ); +'''); } test_declaredVariablePattern_valueDynamic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic x) { var (int a) = x; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [error(diag.unusedLocalVariable, 31, 1)], - ); +'''); } test_declaredVariablePattern_valueSubtype() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { var (num a) = x; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [error(diag.unusedLocalVariable, 27, 1)], - ); +'''); } test_declaredVariablePattern_valueSupertype() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { var (int a) = x; +// ^^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'num' isn't assignable to the required type 'int'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 23, 5), - error(diag.unusedLocalVariable, 27, 1), - ], - ); +'''); } test_listPattern_differentList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(List x) { var [a] = x; +// ^^^^^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'List' isn't assignable to the required type 'List'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 31, 8), - error(diag.unusedLocalVariable, 37, 1), - ], - ); +'''); } test_listPattern_notList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { var [a] = x; +// ^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'Object' isn't assignable to the required type 'List'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 25, 3), - error(diag.unusedLocalVariable, 26, 1), - ], - ); +'''); } test_mapPattern_notMap() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { var {0: a} = x; +// ^^^^^^^^^^^^^^^^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'Object' isn't assignable to the required type 'Map'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 25, 19), - error(diag.unusedLocalVariable, 42, 1), - ], - ); +'''); } test_objectPattern_differentClass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { var String(length: a) = x; +// ^^^^^^^^^^^^^^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'Object' isn't assignable to the required type 'String'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 25, 17), - error(diag.unusedLocalVariable, 40, 1), - ], - ); +'''); } test_patternAssignment_assignedVariablePattern() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a) { (a) = 1.2; +// ^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'double' isn't assignable to the required type 'int'. } -''', - [error(diag.patternTypeMismatchInIrrefutableContext, 19, 1)], - ); +'''); } test_recordPattern_notRecord() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { var (a,) = x; +// ^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'Object' isn't assignable to the required type '(Object?,)'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 25, 4), - error(diag.unusedLocalVariable, 26, 1), - ], - ); +'''); } test_recordPattern_record_differentShape() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(({int foo}) x) { var (a,) = x; +// ^^^^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type '({int foo})' isn't assignable to the required type '(Object?,)'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 30, 4), - error(diag.unusedLocalVariable, 31, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/pattern_variable_assignment_inside_guard_test.dart b/pkg/analyzer/test/src/diagnostics/pattern_variable_assignment_inside_guard_test.dart index 438a3d6aa8d..a56b55fd38b 100644 --- a/pkg/analyzer/test/src/diagnostics/pattern_variable_assignment_inside_guard_test.dart +++ b/pkg/analyzer/test/src/diagnostics/pattern_variable_assignment_inside_guard_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PatternVariableAssignmentInsideGuardTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,104 +18,95 @@ main() { class PatternVariableAssignmentInsideGuardTest extends PubPackageResolutionTest { test_closure_outer_assignment() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when () { +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. if (x case _ when (a = 1) > 0) {} +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. return true; }()) {} } -''', - [ - error(diag.unusedLocalVariable, 33, 1), - error(diag.patternVariableAssignmentInsideGuard, 68, 1), - ], - ); +'''); } test_closure_this_assignment() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when () { +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. a = 0; +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. return true; }()) {} } -''', - [ - error(diag.unusedLocalVariable, 33, 1), - error(diag.patternVariableAssignmentInsideGuard, 49, 1), - ], - ); +'''); } test_expression_assignment() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when (a = 1) > 0) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. } -''', - [ - error(diag.unusedLocalVariable, 33, 1), - error(diag.patternVariableAssignmentInsideGuard, 41, 1), - ], - ); +'''); } test_expression_assignment_compound() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when (a += 1) > 0) {} +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. } -''', - [error(diag.patternVariableAssignmentInsideGuard, 41, 1)], - ); +'''); } test_expression_assignment_logicalOr2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case int a || int a when (a = 1) > 0) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. } -''', - [ - error(diag.unusedLocalVariable, 33, 1), - error(diag.deadCode, 35, 8), - error(diag.unusedLocalVariable, 42, 1), - error(diag.patternVariableAssignmentInsideGuard, 50, 1), - ], - ); +'''); } test_expression_postfixIncrement() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when (a++) > 0) {} +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. } -''', - [error(diag.patternVariableAssignmentInsideGuard, 41, 1)], - ); +'''); } test_expression_prefixIncrement() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when (++a) > 0) {} +// ^ +// [diag.patternVariableAssignmentInsideGuard] Pattern variables can't be assigned inside the guard of the enclosing guarded pattern. } -''', - [error(diag.patternVariableAssignmentInsideGuard, 43, 1)], - ); +'''); } test_ifStatement_caseClause_insideThen() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when a > 0) { a = 0; @@ -124,20 +116,19 @@ void f(int x) { } test_otherVariable_local() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { // ignore:unused_local_variable var b = 0; if (x case var a when (b = 1) > 0) {} +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [error(diag.unusedLocalVariable, 80, 1)], - ); +'''); } test_outerPattern_variablePattern() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { if (x case var a when a > 0) { if (x case _ when (a = 1) > 0) {} diff --git a/pkg/analyzer/test/src/diagnostics/positional_super_formal_parameter_with_positional_argument_test.dart b/pkg/analyzer/test/src/diagnostics/positional_super_formal_parameter_with_positional_argument_test.dart index 7ef01205f30..e26a20eeaca 100644 --- a/pkg/analyzer/test/src/diagnostics/positional_super_formal_parameter_with_positional_argument_test.dart +++ b/pkg/analyzer/test/src/diagnostics/positional_super_formal_parameter_with_positional_argument_test.dart @@ -2,16 +2,17 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests( PositionalSuperFormalParameterWithPositionalArgumentTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,7 +20,7 @@ main() { class PositionalSuperFormalParameterWithPositionalArgumentTest extends PubPackageResolutionTest { test_primaryConstructor_notReported() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a); } @@ -31,22 +32,21 @@ class B(super.a) extends A { } test_primaryConstructor_reported() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a, int b); } class B(super.a) extends A { +// ^ +// [diag.positionalSuperFormalParameterWithPositionalArgument] Positional super parameters can't be used when the super constructor invocation has a positional argument. this : super(0); } -''', - [error(diag.positionalSuperFormalParameterWithPositionalArgument, 46, 1)], - ); +'''); } test_secondaryConstructor_notReported() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a); } @@ -58,17 +58,16 @@ class B extends A { } test_secondaryConstructor_reported() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a, int b); } class B extends A { B(super.b) : super(0); +// ^ +// [diag.positionalSuperFormalParameterWithPositionalArgument] Positional super parameters can't be used when the super constructor invocation has a positional argument. } -''', - [error(diag.positionalSuperFormalParameterWithPositionalArgument, 62, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/prefix_collides_with_top_level_member_test.dart b/pkg/analyzer/test/src/diagnostics/prefix_collides_with_top_level_member_test.dart index 4e082c96fec..fc989162149 100644 --- a/pkg/analyzer/test/src/diagnostics/prefix_collides_with_top_level_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/prefix_collides_with_top_level_member_test.dart @@ -6,131 +6,102 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PrefixCollidesWithTopLevelMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PrefixCollidesWithTopLevelMemberTest extends PubPackageResolutionTest { test_library_functionTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. typedef foo = void Function(); -''', - [ - error(diag.unusedImport, 7, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 22, - 3, - contextMessages: [message(testFile, 35, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_library_no_collision() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. void bar() {} -''', - [error(diag.unusedImport, 7, 11)], - ); +'''); } test_library_topLevelFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. void foo() {} -''', - [ - error(diag.unusedImport, 7, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 22, - 3, - contextMessages: [message(testFile, 32, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_library_topLevelGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. int get foo => 0; -''', - [ - error(diag.unusedImport, 7, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 22, - 3, - contextMessages: [message(testFile, 35, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_library_topLevelSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. set foo(int _) {} -''', - [ - error(diag.unusedImport, 7, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 22, - 3, - contextMessages: [message(testFile, 31, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_library_topLevelVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. var foo = 0; -''', - [ - error(diag.unusedImport, 7, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 22, - 3, - contextMessages: [message(testFile, 31, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_library_type() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. class foo {} -''', - [ - error(diag.unusedImport, 7, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 22, - 3, - contextMessages: [message(testFile, 33, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_part_topLevelFunction_inLibrary() async { @@ -161,22 +132,17 @@ import 'dart:math' as foo; part 'test.dart'; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' part of 'a.dart'; import 'dart:math' as foo; +// ^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:math'. +// ^^^ +// [diag.prefixCollidesWithTopLevelMember][context 1] The name 'foo' is already used as an import prefix and can't be used to name a top-level element. void foo() {} -''', - [ - error(diag.unusedImport, 25, 11), - error( - diag.prefixCollidesWithTopLevelMember, - 40, - 3, - contextMessages: [message(testFile, 50, 3)], - ), - ], - ); +// ^^^ +// [context 1] The first definition of this name. +'''); } test_part_topLevelFunction_inPart2() async { diff --git a/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart b/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart index 52cceb50541..56b8fd542d2 100644 --- a/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart +++ b/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PrefixIdentifierNotFollowedByDotTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,54 +20,50 @@ class PrefixIdentifierNotFollowedByDotTest extends PubPackageResolutionTest { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; class C { f() { p += 1; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 46, 1)], - ); +'''); } test_assignment_compound_not_in_method() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { p += 1; +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 32, 1)], - ); +'''); } test_assignment_in_method() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; class C { f() { p = 1; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 46, 1)], - ); +'''); } test_assignment_in_method_hasSuperField() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as p; class A { @@ -76,41 +73,39 @@ class A { class B extends A { void f() { p = 1; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 85, 1)], - ); +'''); } test_assignment_not_in_method() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { p = 1; +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 32, 1)], - ); +'''); } test_compoundAssignment() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { p += 1; +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 32, 1)], - ); +'''); } test_conditionalMethodInvocation() async { @@ -118,30 +113,28 @@ f() { library lib; g() {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { p?.g(); +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 32, 1)], - ); +'''); } test_conditionalPropertyAccess_call_loadLibrary() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' deferred as p; f() { p?.loadLibrary(); +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 41, 1)], - ); +'''); } test_conditionalPropertyAccess_get() async { @@ -149,30 +142,28 @@ f() { library lib; var x; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { return p?.x; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 39, 1)], - ); +'''); } test_conditionalPropertyAccess_get_loadLibrary() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' deferred as p; f() { return p?.loadLibrary; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 48, 1)], - ); +'''); } test_conditionalPropertyAccess_set() async { @@ -180,44 +171,41 @@ f() { library lib; var x; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { p?.x = null; +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 32, 1)], - ); +'''); } test_conditionalPropertyAccess_set_loadLibrary() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' deferred as p; f() { p?.loadLibrary = null; +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 41, 1)], - ); +'''); } test_prefix_not_followed_by_dot() async { newFile('$testPackageLibPath/lib.dart', ''' library lib; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib.dart' as p; f() { return p; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'p' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 39, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/prefix_shadowed_by_local_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/prefix_shadowed_by_local_declaration_test.dart index 92b0934692a..4853617d441 100644 --- a/pkg/analyzer/test/src/diagnostics/prefix_shadowed_by_local_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/prefix_shadowed_by_local_declaration_test.dart @@ -2,21 +2,22 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PrefixShadowedByLocalDeclarationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PrefixShadowedByLocalDeclarationTest extends PubPackageResolutionTest { test_function_return_type_not_shadowed_by_parameter() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as a; a.Future? f(int a) { return null; @@ -25,97 +26,85 @@ a.Future? f(int a) { } test_local_variable_type_inside_function_with_shadowing_parameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as a; +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. f(int a) { a.Future? x = null; +//^ +// [diag.prefixShadowedByLocalDeclaration] The prefix 'a' can't be used here because it's shadowed by a local declaration. return x; } -''', - [ - error(diag.unusedImport, 7, 12), - error(diag.prefixShadowedByLocalDeclaration, 39, 1), - ], - ); +'''); } test_local_variable_type_inside_function_with_shadowing_variable_after() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as a; +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. f() { a.Future? x = null; +//^ +// [diag.prefixShadowedByLocalDeclaration] The prefix 'a' can't be used here because it's shadowed by a local declaration. +// [diag.referencedBeforeDeclaration][context 1] Local variable 'a' can't be referenced before it is declared. int a = 0; +// ^ +// [context 1] The declaration of 'a' is here. return [x, a]; } -''', - [ - error(diag.unusedImport, 7, 12), - error( - diag.referencedBeforeDeclaration, - 34, - 1, - contextMessages: [message(testFile, 60, 1)], - ), - error(diag.prefixShadowedByLocalDeclaration, 34, 1), - ], - ); +'''); } test_local_variable_type_inside_function_with_shadowing_variable_before() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as a; +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. f() { int a = 0; a.Future? x = null; +//^ +// [diag.prefixShadowedByLocalDeclaration] The prefix 'a' can't be used here because it's shadowed by a local declaration. return [x, a]; } -''', - [ - error(diag.unusedImport, 7, 12), - error(diag.prefixShadowedByLocalDeclaration, 47, 1), - ], - ); +'''); } test_shadowedBy_class_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:core' as core; class A { core.List foo = 0; +//^^^^ +// [diag.prefixShadowedByLocalDeclaration] The prefix 'core' can't be used here because it's shadowed by a local declaration. get core => 0; } -''', - [error(diag.prefixShadowedByLocalDeclaration, 40, 4)], - ); +'''); } test_shadowedBy_class_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:core' as core; class A { core.List foo = 0; +//^^^^ +// [diag.prefixShadowedByLocalDeclaration] The prefix 'core' can't be used here because it's shadowed by a local declaration. void core() {} } -''', - [error(diag.prefixShadowedByLocalDeclaration, 40, 4)], - ); +'''); } test_shadowedBy_class_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:core' as core; class A { core.List foo = 0; +//^^^^ +// [diag.prefixShadowedByLocalDeclaration] The prefix 'core' can't be used here because it's shadowed by a local declaration. set core(_) {} } -''', - [error(diag.prefixShadowedByLocalDeclaration, 40, 4)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/private_collision_in_mixin_application_test.dart b/pkg/analyzer/test/src/diagnostics/private_collision_in_mixin_application_test.dart index 766e841761c..fe4413a482a 100644 --- a/pkg/analyzer/test/src/diagnostics/private_collision_in_mixin_application_test.dart +++ b/pkg/analyzer/test/src/diagnostics/private_collision_in_mixin_application_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PrivateCollisionInMixinApplicationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,7 +23,7 @@ mixin A { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C implements A {} @@ -37,7 +38,7 @@ mixin class A { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C implements A {} @@ -56,14 +57,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A, B {} -''', - [error(diag.privateCollisionInMixinApplication, 49, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_mixinAndMixin_indirect() async { @@ -77,15 +77,14 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A {} class D extends C with B {} -''', - [error(diag.privateCollisionInMixinApplication, 74, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_mixinAndMixin_indirect_mixinClass() async { @@ -99,15 +98,14 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A {} class D extends C with B {} -''', - [error(diag.privateCollisionInMixinApplication, 74, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_mixinAndMixin_mixinClass() async { @@ -121,14 +119,13 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A, B {} -''', - [error(diag.privateCollisionInMixinApplication, 49, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_mixinAndMixin_withoutExtends() async { @@ -142,14 +139,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C with A, B {} -''', - [error(diag.privateCollisionInMixinApplication, 34, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_mixinAndMixin_withoutExtends_mixinClass() async { @@ -163,14 +159,13 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C with A, B {} -''', - [error(diag.privateCollisionInMixinApplication, 34, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_staticAndInstanceElement() async { @@ -184,7 +179,7 @@ mixin B { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A, B {} @@ -202,7 +197,7 @@ mixin class B { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A, B {} @@ -220,7 +215,7 @@ mixin B { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A, B {} @@ -238,7 +233,7 @@ mixin class B { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends Object with A, B {} @@ -256,14 +251,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends A with B {} -''', - [error(diag.privateCollisionInMixinApplication, 41, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_superclassAndMixin_getter2_mixinClass() async { @@ -277,14 +271,13 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends A with B {} -''', - [error(diag.privateCollisionInMixinApplication, 41, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_superclassAndMixin_method2() async { @@ -298,14 +291,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends A with B {} -''', - [error(diag.privateCollisionInMixinApplication, 41, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_superclassAndMixin_method2_mixinClass() async { @@ -319,48 +311,49 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends A with B {} -''', - [error(diag.privateCollisionInMixinApplication, 41, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_superclassAndMixin_sameLibrary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin A { void _foo() {} +// ^^^^ +// [diag.unusedElement] The declaration '_foo' isn't referenced. } mixin B { void _foo() {} +// ^^^^ +// [diag.unusedElement] The declaration '_foo' isn't referenced. } class C extends Object with A, B {} -''', - [error(diag.unusedElement, 17, 4), error(diag.unusedElement, 47, 4)], - ); +'''); } test_class_superclassAndMixin_sameLibrary_mixinClass() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin class A { void _foo() {} +// ^^^^ +// [diag.unusedElement] The declaration '_foo' isn't referenced. } mixin class B { void _foo() {} +// ^^^^ +// [diag.unusedElement] The declaration '_foo' isn't referenced. } class C extends Object with A, B {} -''', - [error(diag.unusedElement, 23, 4), error(diag.unusedElement, 59, 4)], - ); +'''); } test_class_superclassAndMixin_setter2() async { @@ -374,21 +367,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends A with B {} -''', - [ - error( - diag.privateCollisionInMixinApplication, - 41, - 1, - messageContains: ["'_foo'"], - ), - ], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_class_superclassAndMixin_setter2_mixinClass() async { @@ -402,21 +387,13 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C extends A with B {} -''', - [ - error( - diag.privateCollisionInMixinApplication, - 41, - 1, - messageContains: ["'_foo'"], - ), - ], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_classTypeAlias_mixinAndMixin() async { @@ -430,14 +407,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C = Object with A, B; -''', - [error(diag.privateCollisionInMixinApplication, 43, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_classTypeAlias_mixinAndMixin_indirect() async { @@ -451,15 +427,14 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C = Object with A; class D = C with B; -''', - [error(diag.privateCollisionInMixinApplication, 60, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_classTypeAlias_mixinAndMixin_indirect_mixinClass() async { @@ -473,15 +448,14 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C = Object with A; class D = C with B; -''', - [error(diag.privateCollisionInMixinApplication, 60, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_classTypeAlias_mixinAndMixin_mixinClass() async { @@ -495,14 +469,13 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C = Object with A, B; -''', - [error(diag.privateCollisionInMixinApplication, 43, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_classTypeAlias_superclassAndMixin() async { @@ -516,14 +489,13 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C = A with B; -''', - [error(diag.privateCollisionInMixinApplication, 35, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_classTypeAlias_superclassAndMixin_mixinClass() async { @@ -537,14 +509,13 @@ mixin class B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; class C = A with B; -''', - [error(diag.privateCollisionInMixinApplication, 35, 1)], - ); +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. +'''); } test_enum_getter_mixinAndMixin() async { @@ -558,16 +529,15 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; enum E with A, B { +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. v } -''', - [error(diag.privateCollisionInMixinApplication, 33, 1)], - ); +'''); } test_enum_method_interfaceAndMixin_same() async { @@ -577,7 +547,7 @@ mixin A { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; mixin B implements A {} @@ -598,16 +568,15 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; enum E with A, B { +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. v } -''', - [error(diag.privateCollisionInMixinApplication, 33, 1)], - ); +'''); } test_enum_method_staticAndInstanceElement() async { @@ -621,7 +590,7 @@ mixin B { } '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; enum E with A, B { @@ -641,22 +610,14 @@ mixin B { } '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; enum E with A, B { +// ^ +// [diag.privateCollisionInMixinApplication] The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. v } -''', - [ - error( - diag.privateCollisionInMixinApplication, - 33, - 1, - messageContains: ["'_foo'"], - ), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/private_optional_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/private_optional_parameter_test.dart index 758c70992a8..98d7094c6b3 100644 --- a/pkg/analyzer/test/src/diagnostics/private_optional_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/private_optional_parameter_test.dart @@ -2,311 +2,274 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PrivateOptionalParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class PrivateOptionalParameterTest extends PubPackageResolutionTest { test_class_constructorDeclaration_fieldFormal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? _p; +// ^^ +// [diag.unusedField] The value of the field '_p' isn't used. A({this._p = 0}); } -''', - [error(diag.unusedField, 17, 2)], - ); +'''); } test_class_constructorDeclaration_nonFieldParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { C({int? _notField}); +// ^^^^^^^^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. } -''', - [error(diag.privateNamedNonFieldParameter, 20, 9)], - ); +'''); } test_class_constructorDeclaration_noPublicName_nonIdentifier() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { int? _123; +// ^^^^ +// [diag.unusedField] The value of the field '_123' isn't used. C({this._123}) {} +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. } -''', - [ - error(diag.unusedField, 17, 4), - error(diag.privateNamedParameterWithoutPublicName, 33, 4), - ], - ); +'''); } test_class_constructorDeclaration_noPublicName_preFeature() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' // @dart=3.10 class C { int? _123; +// ^^^^ +// [diag.unusedField] The value of the field '_123' isn't used. C({this._123}) {} +// ^^^^ +// [diag.experimentNotEnabled] This requires the 'private-named-parameters' language feature to be enabled. } -''', - [error(diag.unusedField, 31, 4), error(diag.experimentNotEnabled, 47, 4)], - ); +'''); } test_class_constructorDeclaration_noPublicName_reservedWord() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { int? _for; +// ^^^^ +// [diag.unusedField] The value of the field '_for' isn't used. C({this._for}) {} +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. } -''', - [ - error(diag.unusedField, 17, 4), - error(diag.privateNamedParameterWithoutPublicName, 33, 4), - ], - ); +'''); } test_class_constructorDeclaration_noPublicName_stillPrivate() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { int? __extraPrivate; +// ^^^^^^^^^^^^^^ +// [diag.unusedField] The value of the field '__extraPrivate' isn't used. C({this.__extraPrivate}) {} +// ^^^^^^^^^^^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. } -''', - [ - error(diag.unusedField, 17, 14), - error(diag.privateNamedParameterWithoutPublicName, 43, 14), - ], - ); +'''); } test_class_constructorDeclaration_noPublicName_wildcard() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. C({this._}) {} +// ^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. } -''', - [ - error(diag.unusedField, 17, 1), - error(diag.privateNamedParameterWithoutPublicName, 30, 1), - ], - ); +'''); } test_class_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void f({int? _p}) {} +// ^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. } -''', - [error(diag.privateNamedNonFieldParameter, 25, 2)], - ); +'''); } test_class_method_noPublicName() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void f({int? _123}) {} +// ^^^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. } -''', - [error(diag.privateNamedNonFieldParameter, 25, 4)], - ); +'''); } test_class_primaryConstructor_declaringFormalParameter_optionalNamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A({final int _p = 0}) {} -''', - [error(diag.unusedFieldFromPrimaryConstructor, 19, 2)], - ); +// ^^ +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_p' isn't used. +'''); } test_class_primaryConstructor_declaringFormalParameter_optionalNamed_noPublicName_nonIdentifier() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({final int? _123}) {} -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 20, 4), - error(diag.unusedFieldFromPrimaryConstructor, 20, 4), - ], - ); +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_123' isn't used. +'''); } test_class_primaryConstructor_declaringFormalParameter_optionalNamed_noPublicName_reservedWord() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({final int? _for}) {} -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 20, 4), - error(diag.unusedFieldFromPrimaryConstructor, 20, 4), - ], - ); +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_for' isn't used. +'''); } test_class_primaryConstructor_declaringFormalParameter_optionalNamed_noPublicName_stillPrivate() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({final int? __extraPrivate}) {} -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 20, 14), - error(diag.unusedFieldFromPrimaryConstructor, 20, 14), - ], - ); +// ^^^^^^^^^^^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '__extraPrivate' isn't used. +'''); } test_class_primaryConstructor_declaringFormalParameter_optionalNamed_noPublicName_wildcard() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({final int? _}) {} -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 20, 1), - error(diag.unusedFieldFromPrimaryConstructor, 20, 1), - ], - ); +// ^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. +'''); } test_class_primaryConstructor_formalParameter_optionalNamed_fieldFormal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A({this._p = 0}) { int? _p; +// ^^ +// [diag.unusedField] The value of the field '_p' isn't used. } -''', - [error(diag.unusedField, 32, 2)], - ); +'''); } test_class_primaryConstructor_formalParameter_optionalNamed_fieldFormal_noPublicName_nonIdentifier() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({this._123}) { +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. int? _123; +// ^^^^ +// [diag.unusedField] The value of the field '_123' isn't used. } -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 14, 4), - error(diag.unusedField, 30, 4), - ], - ); +'''); } test_class_primaryConstructor_formalParameter_optionalNamed_fieldFormal_noPublicName_reservedWord() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({this._for}) { +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. int? _for; +// ^^^^ +// [diag.unusedField] The value of the field '_for' isn't used. } -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 14, 4), - error(diag.unusedField, 30, 4), - ], - ); +'''); } test_class_primaryConstructor_formalParameter_optionalNamed_fieldFormal_noPublicName_stillPrivate() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({this.__extraPrivate}) { +// ^^^^^^^^^^^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. int? __extraPrivate; +// ^^^^^^^^^^^^^^ +// [diag.unusedField] The value of the field '__extraPrivate' isn't used. } -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 14, 14), - error(diag.unusedField, 40, 14), - ], - ); +'''); } test_class_primaryConstructor_formalParameter_optionalNamed_fieldFormal_noPublicName_wildcard() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({this._}) { +// ^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. } -''', - [ - error(diag.privateNamedParameterWithoutPublicName, 14, 1), - error(diag.unusedField, 27, 1), - ], - ); +'''); } test_class_primaryConstructor_formalParameter_optionalNamed_nonFieldFormal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C({int? _notField}) {} -''', - [error(diag.privateNamedNonFieldParameter, 14, 9)], - ); +// ^^^^^^^^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. +'''); } test_extensionType_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension type E(int it) { void f({int? _p}) {} +// ^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. } -''', - [error(diag.privateNamedNonFieldParameter, 42, 2)], - ); +'''); } test_extensionType_primaryConstructor_requiredNamed() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' extension type E({required int _it}); '''); } test_extensionType_primaryConstructor_requiredNamed_noPublicName_nonIdentifier() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension type E({required int _123}); -''', - [error(diag.privateNamedParameterWithoutPublicName, 31, 4)], - ); +// ^^^^ +// [diag.privateNamedParameterWithoutPublicName] A private named parameter must be a public identifier after removing the leading underscore. +'''); } test_topLevel_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f({int? _p}) {} -''', - [error(diag.privateNamedNonFieldParameter, 13, 2)], - ); +// ^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. +'''); } test_topLevel_function_withDefaultValue() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f({int _p = 0}) {} -''', - [error(diag.privateNamedNonFieldParameter, 12, 2)], - ); +// ^^ +// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/private_setter_test.dart b/pkg/analyzer/test/src/diagnostics/private_setter_test.dart index 655741fe904..2323851656c 100644 --- a/pkg/analyzer/test/src/diagnostics/private_setter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/private_setter_test.dart @@ -2,14 +2,15 @@ // 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:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(PrivateSetterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -21,16 +22,15 @@ class A { static int _foo = 0; } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; main() { A._foo = 0; +// ^^^^ +// [diag.privateSetter] The setter '_foo' is private and can't be accessed outside the library that declares it. } -''', - [error(diag.privateSetter, 31, 4)], - ); +'''); var assignment = findNode.assignment('_foo ='); assertResolvedNodeText(assignment, r''' @@ -62,7 +62,7 @@ AssignmentExpression } test_typeLiteral_privateField_sameLibrary() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { // ignore:unused_field static int _foo = 0; @@ -82,16 +82,15 @@ class A { static int get _foo => 0; } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; main() { A._foo = 0; +// ^^^^ +// [diag.privateSetter] The setter '_foo' is private and can't be accessed outside the library that declares it. } -''', - [error(diag.privateSetter, 31, 4)], - ); +'''); var assignment = findNode.assignment('_foo ='); assertResolvedNodeText(assignment, r''' @@ -128,16 +127,15 @@ class A { static set _foo(int _) {} } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; main() { A._foo = 0; +// ^^^^ +// [diag.privateSetter] The setter '_foo' is private and can't be accessed outside the library that declares it. } -''', - [error(diag.privateSetter, 31, 4)], - ); +'''); var assignment = findNode.assignment('_foo ='); assertResolvedNodeText(assignment, r''' @@ -169,7 +167,7 @@ AssignmentExpression } test_typeLiteral_privateSetter_sameLibrary() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static set _foo(int _) {} }