From 245105300cd00a7e6d8600a5a9666ec9eb4d310f Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 12 May 2026 13:16:41 -0700 Subject: [PATCH] CQ. Migrate diagnostics tests to resolveTestCodeWithDiagnostics. A-B. Change-Id: I260150562d253f480f70f04b7038fc7bcdadca26 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501764 Reviewed-by: Johnni Winther Commit-Queue: Konstantin Shcheglov --- .../resolution/node_text_expectations.dart | 5 + .../test/src/dart/resolution/resolution.dart | 18 + .../abi_specific_integer_mapping_test.dart | 71 +- .../abstract_class_member_test.dart | 8 +- ...ct_field_constructor_initializer_test.dart | 43 +- .../abstract_field_initializer_test.dart | 25 +- .../abstract_super_member_reference_test.dart | 118 +- .../diagnostics/ambiguous_export_test.dart | 22 +- ...mbiguous_extension_member_access_test.dart | 241 +- .../diagnostics/ambiguous_import_test.dart | 205 +- .../ambiguous_set_or_map_literal_test.dart | 55 +- .../annotation_on_pointer_field_test.dart | 21 +- .../diagnostics/annotation_syntax_test.dart | 17 +- .../argument_must_be_a_constant_test.dart | 48 +- .../argument_type_not_assignable_test.dart | 496 +- ..._not_assignable_to_error_handler_test.dart | 343 +- ...ssert_in_redirecting_constructor_test.dart | 93 +- .../assignment_of_do_not_store_test.dart | 219 +- .../diagnostics/assignment_to_const_test.dart | 58 +- .../assignment_to_final_local_test.dart | 169 +- .../assignment_to_final_no_setter_test.dart | 103 +- .../diagnostics/assignment_to_final_test.dart | 294 +- .../assignment_to_function_test.dart | 12 +- .../assignment_to_method_test.dart | 72 +- ...to_primary_constructor_parameter_test.dart | 195 +- .../diagnostics/assignment_to_type_test.dart | 57 +- .../async_for_in_wrong_context_test.dart | 17 +- ...async_keyword_used_as_identifier_test.dart | 90 +- ...on_of_different_declaration_kind_test.dart | 654 +-- ...ation_of_mixin_application_class_test.dart | 20 +- ...ugmentation_type_parameter_bound_test.dart | 170 +- ...ugmentation_type_parameter_count_test.dart | 240 +- ...augmentation_type_parameter_name_test.dart | 80 +- ...augmentation_without_declaration_test.dart | 895 ++-- ..._late_local_variable_initializer_test.dart | 31 +- .../await_in_wrong_context_test.dart | 21 +- .../await_of_incompatible_type_test.dart | 36 +- ...s_implemented_outside_of_library_test.dart | 100 +- ...n_implemented_outside_of_library_test.dart | 89 +- .../binary_operator_written_out_test.dart | 58 +- ...ht_complete_normally_catch_error_test.dart | 38 +- ...might_complete_normally_nullable_test.dart | 35 +- .../body_might_complete_normally_test.dart | 155 +- .../break_label_on_switch_member_test.dart | 21 +- ..._in_identifier_as_extension_name_test.dart | 43 +- ...dentifier_as_extension_type_name_test.dart | 43 +- ...ilt_in_identifier_as_prefix_name_test.dart | 77 +- ...built_in_identifier_as_type_name_test.dart | 116 +- ...dentifier_as_type_parameter_name_test.dart | 97 +- ...lt_in_identifier_as_typedef_name_test.dart | 143 +- .../duplicate_definition_test.dart | 4016 ++++++----------- 51 files changed, 4166 insertions(+), 6127 deletions(-) diff --git a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart index 71a7ef3779b..db24cef53d1 100644 --- a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart +++ b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart @@ -186,6 +186,11 @@ class NodeTextExpectationsCollector { methodName: 'assertResolvedNodeText', argument: _ArgumentIndex(1), ), + _AssertMethod( + className: 'ResolutionTest', + methodName: 'resolveTestCodeWithDiagnostics', + argument: _ArgumentIndex(0), + ), _AssertMethod( className: 'SearchTest', methodName: 'assertDeclarationsText', diff --git a/pkg/analyzer/test/src/dart/resolution/resolution.dart b/pkg/analyzer/test/src/dart/resolution/resolution.dart index 34abb10af42..e123945af47 100644 --- a/pkg/analyzer/test/src/dart/resolution/resolution.dart +++ b/pkg/analyzer/test/src/dart/resolution/resolution.dart @@ -24,6 +24,7 @@ import 'package:analyzer/src/test_utilities/find_element2.dart'; import 'package:analyzer/src/test_utilities/find_node.dart'; import 'package:analyzer_testing/resource_provider_mixin.dart'; import 'package:analyzer_testing/src/analysis_rule/pub_package_resolution.dart'; +import 'package:analyzer_testing/src/expected_diagnostics.dart'; import 'package:analyzer_utilities/testing/tree_string_sink.dart'; import 'package:test/test.dart'; @@ -462,6 +463,23 @@ mixin ResolutionTest implements ResourceProviderMixin { return resolveTestFile(); } + /// Resolves [code] and checks that its inline diagnostic markers match the + /// diagnostics. Unmarked code is expected to have no diagnostics. + Future resolveTestCodeWithDiagnostics(String code) async { + addTestFile(code); + await resolveTestFile(); + + var actual = updateExpectedDiagnostics( + content: code, + actualDiagnostics: result.diagnostics, + ); + if (actual != code) { + NodeTextExpectationsCollector.add(actual); + printPrettyDiff(code, actual); + fail('See the difference above.'); + } + } + Future resolveTestFile() { return resolveFile2(testFile); } diff --git a/pkg/analyzer/test/src/diagnostics/abi_specific_integer_mapping_test.dart b/pkg/analyzer/test/src/diagnostics/abi_specific_integer_mapping_test.dart index e4153db3f0e..73b7931cec7 100644 --- a/pkg/analyzer/test/src/diagnostics/abi_specific_integer_mapping_test.dart +++ b/pkg/analyzer/test/src/diagnostics/abi_specific_integer_mapping_test.dart @@ -2,66 +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(AbiSpecificIntegerMappingTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AbiSpecificIntegerMappingTest extends PubPackageResolutionTest { test_doubleMapping() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @AbiSpecificIntegerMapping({}) @AbiSpecificIntegerMapping({}) +// [diag.abiSpecificIntegerMappingExtra][column 2][length 25] Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a 'NativeType' integer with a fixed size. final class UintPtr extends AbiSpecificInteger { const UintPtr(); } -''', - [error(diag.abiSpecificIntegerMappingExtra, 51, 25)], - ); +'''); } test_invalidMapping() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), Abi.androidArm64: IntPtr(), +// ^^^^^^^^ +// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'IntPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported. Abi.androidIA32: UintPtr(), +// ^^^^^^^^^ +// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'UintPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported. }) final class UintPtr extends AbiSpecificInteger { const UintPtr(); } -''', - [ - error( - diag.abiSpecificIntegerMappingUnsupported, - 96, - 8, - messageContains: ["Invalid mapping to 'IntPtr'"], - ), - error( - diag.abiSpecificIntegerMappingUnsupported, - 125, - 9, - messageContains: ["Invalid mapping to 'UintPtr'"], - ), - ], - ); +'''); } test_invalidMapping_identifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; const c = { Abi.androidArm: Uint32(), @@ -69,41 +55,28 @@ const c = { Abi.androidIA32: UintPtr(), }; @AbiSpecificIntegerMapping(c) +// ^ +// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'IntPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported. +// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'UintPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported. final class UintPtr extends AbiSpecificInteger { const UintPtr(); } -''', - [ - error( - diag.abiSpecificIntegerMappingUnsupported, - 149, - 1, - messageContains: ["Invalid mapping to 'IntPtr'"], - ), - error( - diag.abiSpecificIntegerMappingUnsupported, - 149, - 1, - messageContains: ["Invalid mapping to 'UintPtr'"], - ), - ], - ); +'''); } test_noMapping() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class UintPtr extends AbiSpecificInteger { +// ^^^^^^^ +// [diag.abiSpecificIntegerMappingMissing] Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a 'NativeType' integer with a fixed size. const UintPtr(); } -''', - [error(diag.abiSpecificIntegerMappingMissing, 31, 7)], - ); +'''); } test_singleMapping() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @AbiSpecificIntegerMapping({}) final class UintPtr extends AbiSpecificInteger { @@ -113,7 +86,7 @@ final class UintPtr extends AbiSpecificInteger { } test_validMapping() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; @AbiSpecificIntegerMapping({ Abi.androidArm: Uint32(), diff --git a/pkg/analyzer/test/src/diagnostics/abstract_class_member_test.dart b/pkg/analyzer/test/src/diagnostics/abstract_class_member_test.dart index 17c3a99d709..9a57faea57d 100644 --- a/pkg/analyzer/test/src/diagnostics/abstract_class_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/abstract_class_member_test.dart @@ -5,17 +5,19 @@ 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(AbstractClassMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AbstractClassMemberTest extends PubPackageResolutionTest { test_abstract_field_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract dynamic x; } @@ -23,7 +25,7 @@ abstract class A { } test_abstract_field_untyped() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract var x; } @@ -31,7 +33,7 @@ abstract class A { } test_abstract_field_untyped_covariant() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract covariant var x; } diff --git a/pkg/analyzer/test/src/diagnostics/abstract_field_constructor_initializer_test.dart b/pkg/analyzer/test/src/diagnostics/abstract_field_constructor_initializer_test.dart index 3652752b0d0..8859ed70fe5 100644 --- a/pkg/analyzer/test/src/diagnostics/abstract_field_constructor_initializer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/abstract_field_constructor_initializer_test.dart @@ -2,57 +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(AbstractFieldConstructorInitializerTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AbstractFieldConstructorInitializerTest extends PubPackageResolutionTest { test_abstract_field_constructor_initializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract int x; A() : x = 0; +// ^ +// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers. } -''', - [error(diag.abstractFieldConstructorInitializer, 45, 1)], - ); +'''); } test_abstract_field_final_constructor_initializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract final int x; A() : x = 0; +// ^ +// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers. } -''', - [error(diag.abstractFieldConstructorInitializer, 51, 1)], - ); +'''); } test_abstract_field_final_initializing_formal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract final int x; A(this.x); +// ^ +// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers. } -''', - [error(diag.abstractFieldConstructorInitializer, 52, 1)], - ); +'''); } test_abstract_field_final_no_initialization() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract final int x; A(); @@ -61,19 +59,18 @@ abstract class A { } test_abstract_field_initializing_formal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract int x; A(this.x); +// ^ +// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers. } -''', - [error(diag.abstractFieldConstructorInitializer, 46, 1)], - ); +'''); } test_abstract_field_no_initialization() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract int x; A(); diff --git a/pkg/analyzer/test/src/diagnostics/abstract_field_initializer_test.dart b/pkg/analyzer/test/src/diagnostics/abstract_field_initializer_test.dart index 8971a010dfd..a7ecb485a2e 100644 --- a/pkg/analyzer/test/src/diagnostics/abstract_field_initializer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/abstract_field_initializer_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(AbstractFieldInitializerTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AbstractFieldInitializerTest extends PubPackageResolutionTest { test_abstract_field_final_initializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract final int x = 0; +// ^ +// [diag.abstractFieldInitializer] Abstract fields can't have initializers. } -''', - [error(diag.abstractFieldInitializer, 40, 1)], - ); +'''); } test_abstract_field_final_no_initializer() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract final int x; } @@ -35,18 +35,17 @@ abstract class A { } test_abstract_field_initializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract int x = 0; +// ^ +// [diag.abstractFieldInitializer] Abstract fields can't have initializers. } -''', - [error(diag.abstractFieldInitializer, 34, 1)], - ); +'''); } test_abstract_field_no_initializer() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract int x; } diff --git a/pkg/analyzer/test/src/diagnostics/abstract_super_member_reference_test.dart b/pkg/analyzer/test/src/diagnostics/abstract_super_member_reference_test.dart index 669d924fa91..84bdcbdd97f 100644 --- a/pkg/analyzer/test/src/diagnostics/abstract_super_member_reference_test.dart +++ b/pkg/analyzer/test/src/diagnostics/abstract_super_member_reference_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(AbstractSuperMemberReferenceTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AbstractSuperMemberReferenceTest extends PubPackageResolutionTest { test_methodInvocation_mixin_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo(int _) {} } @@ -25,11 +25,11 @@ class A { mixin M implements A { void bar() { super.foo(0); +// ^^^ +// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype. } } -''', - [error(diag.abstractSuperMemberReference, 82, 3)], - ); +'''); var node = findNode.methodInvocation('super.foo(0)'); assertResolvedNodeText(node, r''' @@ -56,7 +56,7 @@ MethodInvocation } test_methodInvocation_mixinHasConcrete() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M { @@ -92,8 +92,7 @@ MethodInvocation } test_methodInvocation_mixinHasNoSuchMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin A { void foo(); noSuchMethod(im) => 42; @@ -101,11 +100,11 @@ mixin A { class B extends Object with A { void foo() => super.foo(); // ref +// ^^^ +// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype. noSuchMethod(im) => 87; } -''', - [error(diag.abstractSuperMemberReference, 107, 3)], - ); +'''); var node = findNode.methodInvocation('super.foo()'); assertResolvedNodeText(node, r''' @@ -127,8 +126,7 @@ MethodInvocation } test_methodInvocation_superHasAbstract() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(int _); } @@ -136,13 +134,13 @@ abstract class A { abstract class B extends A { void bar() { super.foo(0); +// ^^^ +// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype. } void foo(int _) {} // does not matter } -''', - [error(diag.abstractSuperMemberReference, 95, 3)], - ); +'''); var node = findNode.methodInvocation('super.foo(0)'); assertResolvedNodeText(node, r''' @@ -169,7 +167,7 @@ MethodInvocation } test_methodInvocation_superHasConcrete_mixinHasAbstract() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -205,7 +203,7 @@ MethodInvocation } test_methodInvocation_superHasNoSuchMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo(); noSuchMethod(im) => 42; @@ -237,7 +235,7 @@ MethodInvocation } test_methodInvocation_superSuperHasConcrete() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo() {} } @@ -273,8 +271,7 @@ MethodInvocation } test_propertyAccess_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { int get foo; } @@ -282,11 +279,11 @@ abstract class A { abstract class B extends A { bar() { super.foo; // ref +// ^^^ +// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype. } } -''', - [error(diag.abstractSuperMemberReference, 86, 3)], - ); +'''); var node = findNode.singlePropertyAccess; assertResolvedNodeText(node, r''' @@ -304,8 +301,7 @@ PropertyAccess } test_propertyAccess_getter_mixin_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; } @@ -313,11 +309,11 @@ class A { mixin M implements A { void bar() { super.foo; +// ^^^ +// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype. } } -''', - [error(diag.abstractSuperMemberReference, 81, 3)], - ); +'''); var node = findNode.singlePropertyAccess; assertResolvedNodeText(node, r''' @@ -335,8 +331,7 @@ PropertyAccess } test_propertyAccess_getter_mixinHasNoSuchMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin A { int get foo; noSuchMethod(im) => 1; @@ -344,11 +339,11 @@ mixin A { class B extends Object with A { int get foo => super.foo; // ref +// ^^^ +// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype. noSuchMethod(im) => 2; } -''', - [error(diag.abstractSuperMemberReference, 108, 3)], - ); +'''); var node = findNode.singlePropertyAccess; assertResolvedNodeText(node, r''' @@ -366,7 +361,7 @@ PropertyAccess } test_propertyAccess_getter_superHasNoSuchMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo; noSuchMethod(im) => 1; @@ -394,8 +389,7 @@ PropertyAccess } test_propertyAccess_getter_superImplements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; } @@ -405,10 +399,10 @@ abstract class B implements A { class C extends B { int get foo => super.foo; // ref +// ^^^ +// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype. } -''', - [error(diag.abstractSuperMemberReference, 111, 3)], - ); +'''); var node = findNode.singlePropertyAccess; assertResolvedNodeText(node, r''' @@ -426,7 +420,7 @@ PropertyAccess } test_propertyAccess_getter_superSuperHasConcrete() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { int get foo => 0; } @@ -456,8 +450,7 @@ PropertyAccess } test_propertyAccess_method_tearOff_abstract() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void foo(); } @@ -465,11 +458,11 @@ abstract class A { abstract class B extends A { void bar() { super.foo; // ref +// ^^^ +// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype. } } -''', - [error(diag.abstractSuperMemberReference, 90, 3)], - ); +'''); var node = findNode.singlePropertyAccess; assertResolvedNodeText(node, r''' @@ -487,8 +480,7 @@ PropertyAccess } test_propertyAccess_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { set foo(int _); } @@ -496,11 +488,11 @@ abstract class A { abstract class B extends A { void bar() { super.foo = 0; +// ^^^ +// [diag.abstractSuperMemberReference] The setter 'foo' is always abstract in the supertype. } } -''', - [error(diag.abstractSuperMemberReference, 94, 3)], - ); +'''); assertResolvedNodeText(findNode.assignment('foo ='), r''' AssignmentExpression @@ -529,8 +521,7 @@ AssignmentExpression } test_propertyAccess_setter_mixin_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { set foo(int _) {} } @@ -538,11 +529,11 @@ class A { mixin M implements A { void bar() { super.foo = 0; +// ^^^ +// [diag.abstractSuperMemberReference] The setter 'foo' is always abstract in the supertype. } } -''', - [error(diag.abstractSuperMemberReference, 81, 3)], - ); +'''); assertResolvedNodeText(findNode.assignment('foo ='), r''' AssignmentExpression @@ -571,8 +562,7 @@ AssignmentExpression } test_propertyAccess_setter_mixinHasNoSuchMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin A { set foo(int a); noSuchMethod(im) {} @@ -580,11 +570,11 @@ mixin A { class B extends Object with A { set foo(int a) => super.foo = a; // ref +// ^^^ +// [diag.abstractSuperMemberReference] The setter 'foo' is always abstract in the supertype. noSuchMethod(im) {} } -''', - [error(diag.abstractSuperMemberReference, 111, 3)], - ); +'''); assertResolvedNodeText(findNode.assignment('foo ='), r''' AssignmentExpression @@ -614,7 +604,7 @@ AssignmentExpression } test_propertyAccess_setter_superHasNoSuchMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set foo(int a); noSuchMethod(im) => 1; @@ -654,7 +644,7 @@ AssignmentExpression } test_propertyAccess_setter_superSuperHasConcrete() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void set foo(int _) {} } diff --git a/pkg/analyzer/test/src/diagnostics/ambiguous_export_test.dart b/pkg/analyzer/test/src/diagnostics/ambiguous_export_test.dart index 7acbd37fdd4..eb4e7b18830 100644 --- a/pkg/analyzer/test/src/diagnostics/ambiguous_export_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ambiguous_export_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(AmbiguousExportTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,13 +24,12 @@ class N {} newFile('$testPackageLibPath/lib2.dart', r''' class N {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' export 'lib1.dart'; export 'lib2.dart'; -''', - [error(diag.ambiguousExport, 27, 11)], - ); +// ^^^^^^^^^^^ +// [diag.ambiguousExport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. +'''); } test_library_extensions_bothExported() async { @@ -38,20 +39,19 @@ extension E on String {} newFile('$testPackageLibPath/lib2.dart', r''' extension E on String {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' export 'lib1.dart'; export 'lib2.dart'; -''', - [error(diag.ambiguousExport, 27, 11)], - ); +// ^^^^^^^^^^^ +// [diag.ambiguousExport] The name 'E' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. +'''); } test_library_extensions_localAndExported() async { newFile('$testPackageLibPath/lib1.dart', r''' extension E on String {} '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' export 'lib1.dart'; extension E on String {} diff --git a/pkg/analyzer/test/src/diagnostics/ambiguous_extension_member_access_test.dart b/pkg/analyzer/test/src/diagnostics/ambiguous_extension_member_access_test.dart index f6cb2123d78..7c00211c80c 100644 --- a/pkg/analyzer/test/src/diagnostics/ambiguous_extension_member_access_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ambiguous_extension_member_access_test.dart @@ -6,18 +6,19 @@ 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(AmbiguousExtensionMemberAccessTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AmbiguousExtensionMemberAccessTest extends PubPackageResolutionTest { test_call() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E1 on A { @@ -29,14 +30,13 @@ extension E2 on A { } int f(A a) => a(); -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 110, 1)], - ); +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'call' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific. +'''); } test_getter_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { void get a => 1; } @@ -47,10 +47,10 @@ extension E2 on int { f() { 0.a; +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 98, 1)], - ); +'''); var node = findNode.propertyAccess('0.a'); assertResolvedNodeText(node, r''' @@ -68,7 +68,7 @@ PropertyAccess } test_getter_getterStatic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { void get a => 1; } @@ -98,8 +98,7 @@ PropertyAccess } test_getter_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { int get a => 1; } @@ -110,10 +109,10 @@ extension E2 on int { f() { 0.a; +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E on int' and 'extension E2 on int', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 91, 1)], - ); +'''); var node = findNode.propertyAccess('0.a'); assertResolvedNodeText(node, r''' @@ -131,8 +130,7 @@ PropertyAccess } test_getter_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { int get a => 1; } @@ -143,10 +141,10 @@ extension E2 on int { f() { 0.a; +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E on int' and 'extension E2 on int', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 96, 1)], - ); +'''); var node = findNode.propertyAccess('0.a'); assertResolvedNodeText(node, r''' @@ -164,26 +162,16 @@ PropertyAccess } test_method_conflict_conflict_notSpecific() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { void foo() {} } extension E2 on int { void foo() {} } extension E on int? { void foo() {} } void f() { 0.foo(); +// ^^^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [ - error( - diag.ambiguousExtensionMemberAccessTwo, - 129, - 3, - messageContains: [ - "in 'extension E1 on int' and 'extension E2 on int',", - ], - ), - ], - ); +'''); } test_method_conflict_conflict_notSpecific_sameName() async { @@ -218,39 +206,26 @@ void f() { } test_method_conflict_conflict_notSpecific_sameName_invalidType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' // ignore_for_file: unused_element void f(Iterable p) { p.foo(); +// ^^^ +// [diag.ambiguousExtensionMemberAccessTwo][context 1][context 2] A member named 'foo' is defined in 'extension on Iterable (where is defined in /home/test/lib/test.dart)' and 'extension on Iterable (where is defined in /home/test/lib/test.dart)', and neither is more specific. } extension on Iterable { void foo() {} } +// [context 1][column 1][length 0] is defined in /home/test/lib/test.dart +// ^^^^^^ +// [diag.nonTypeAsTypeArgument] The name 'Undef1' isn't a type, so it can't be used as a type argument. extension on Iterable { void foo() {} } -''', - [ - error( - diag.ambiguousExtensionMemberAccessTwo, - 66, - 3, - messageContains: [ - "'extension on Iterable " - "(where is defined in ${testFile.path})' and " - "'extension on Iterable " - "(where is defined in ${testFile.path})',", - ], - contextMessages: [ - message(testFile, 75, 0), - message(testFile, 123, 0), - ], - ), - error(diag.nonTypeAsTypeArgument, 97, 6), - error(diag.nonTypeAsTypeArgument, 145, 6), - ], - ); +// [context 2][column 1][length 0] is defined in /home/test/lib/test.dart +// ^^^^^^ +// [diag.nonTypeAsTypeArgument] The name 'Undef2' isn't a type, so it can't be used as a type argument. +'''); } test_method_conflict_conflict_specific() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int? { void foo() {} } extension E2 on int? { void foo() {} } extension E on int { void foo() {} } @@ -261,30 +236,20 @@ void f() { } test_method_conflict_notSpecific_conflict() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { void foo() {} } extension E on int? { void foo() {} } extension E2 on int { void foo() {} } void f() { 0.foo(); +// ^^^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [ - error( - diag.ambiguousExtensionMemberAccessTwo, - 129, - 3, - messageContains: [ - "in 'extension E1 on int' and 'extension E2 on int',", - ], - ), - ], - ); +'''); } test_method_conflict_specific_conflict() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int? { void foo() {} } extension E on int { void foo() {} } extension E2 on int? { void foo() {} } @@ -295,8 +260,7 @@ void f() { } test_method_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { void a() {} } @@ -307,10 +271,10 @@ extension E2 on int { f() { 0.a(); +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 88, 1)], - ); +'''); var node = findNode.methodInvocation('0.a()'); assertResolvedNodeText(node, r''' @@ -332,54 +296,34 @@ MethodInvocation } test_method_notSpecific_conflict_conflict() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int? { void foo() {} } extension E1 on int { void foo() {} } extension E2 on int { void foo() {} } void f() { 0.foo(); +// ^^^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [ - error( - diag.ambiguousExtensionMemberAccessTwo, - 129, - 3, - messageContains: [ - "in 'extension E1 on int' and 'extension E2 on int',", - ], - ), - ], - ); +'''); } test_method_notSpecific_conflict_conflict_conflict() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int? { void foo() {} } extension E1 on int { void foo() {} } extension E2 on int { void foo() {} } extension E3 on int { void foo() {} } void f() { 0.foo(); +// ^^^ +// [diag.ambiguousExtensionMemberAccessThreeOrMore] A member named 'foo' is defined in extension 'E1', extension 'E2', and extension 'E3', and none are more specific. } -''', - [ - error( - diag.ambiguousExtensionMemberAccessThreeOrMore, - 167, - 3, - messageContains: [ - "in extension 'E1', extension 'E2', and extension 'E3',", - ], - ), - ], - ); +'''); } test_method_specific_conflict_conflict() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void foo() {} } extension E1 on int? { void foo() {} } extension E2 on int? { void foo() {} } @@ -421,8 +365,7 @@ void f() { } test_noMoreSpecificExtension() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class Target {} class SubTarget extends Target {} @@ -440,15 +383,14 @@ f(SubTarget t) { // The instantiated on type of `E2(t)` is `Target`. // Neither is a subtype of the other, so the resolution is ambiguous. t.foo; +// ^^^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on SubTarget' and 'extension E2 on Target', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 396, 3)], - ); +'''); } test_operator_binary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E1 on A { @@ -460,14 +402,13 @@ extension E2 on A { } A f(A a) => a + a; -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 122, 5)], - ); +// ^^^^^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named '+' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific. +'''); } test_operator_binary_compoundAssignment() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E1 on A { @@ -480,15 +421,14 @@ extension E2 on A { void f(A a) { a += 0; +// ^^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named '+' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 130, 2)], - ); +'''); } test_operator_index_index() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E1 on A { @@ -500,14 +440,13 @@ extension E2 on A { } int f(A a) => a[0]; -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 134, 1)], - ); +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named '[]' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific. +'''); } test_operator_index_indexEq() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { int operator[](int index) => 0; } @@ -518,15 +457,14 @@ extension E2 on int { f() { 0[1] += 2; +//^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named '[]' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 136, 1)], - ); +'''); } test_operator_unary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E1 on A { @@ -538,14 +476,13 @@ extension E2 on A { } int f(A a) => -a; -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 123, 1)], - ); +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'unary-' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific. +'''); } test_setter_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E1 on int { set a(x) {} } @@ -556,10 +493,10 @@ extension E2 on int { f() { 0.a = 3; +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific. } -''', - [error(diag.ambiguousExtensionMemberAccessTwo, 88, 1)], - ); +'''); assertResolvedNodeText(findNode.assignment('= 3'), r''' AssignmentExpression @@ -588,8 +525,7 @@ AssignmentExpression } test_unnamed_extensions() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} class B {} class C extends A implements B {} @@ -603,21 +539,12 @@ extension on List { } int f(List x) => x(); +// ^ +// [diag.ambiguousExtensionMemberAccessTwo] A member named 'call' is defined in 'extension on List' and 'extension on List', and neither is more specific. // Additional calls to avoid UNUSED_ELEMENT int g(List x) => x(); int h(List x) => x(); -''', - [ - error( - diag.ambiguousExtensionMemberAccessTwo, - 167, - 1, - messageContains: [ - "'extension on List' and 'extension on List',", - ], - ), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/ambiguous_import_test.dart b/pkg/analyzer/test/src/diagnostics/ambiguous_import_test.dart index c7f1d7966df..e99e6ff6566 100644 --- a/pkg/analyzer/test/src/diagnostics/ambiguous_import_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ambiguous_import_test.dart @@ -10,10 +10,12 @@ import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../../generated/test_support.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(AmbiguousImportTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -28,19 +30,15 @@ const foo = 0; const foo = 0; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; import 'b.dart'; @foo +// [diag.invalidAnnotation][column 1][length 4] Annotation must be either a const variable reference or const constructor invocation. +// [diag.ambiguousImport][column 2][length 3] The name 'foo' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. class A {} -''', - [ - error(diag.invalidAnnotation, 35, 4), - error(diag.ambiguousImport, 36, 3), - ], - ); +'''); } test_as() async { @@ -50,12 +48,13 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; -f(p) {p as N;}''', - [error(diag.ambiguousImport, 51, 1)], +f(p) {p as N;} +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -66,12 +65,14 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; -class A extends N {}''', - [error(diag.ambiguousImport, 56, 1), error(diag.extendsNonClass, 56, 1)], +class A extends N {} +// ^ +// [diag.extendsNonClass] Classes can only extend other classes. +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -82,15 +83,14 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; -class A implements N {}''', - [ - error(diag.implementsNonClass, 59, 1), - error(diag.ambiguousImport, 59, 1), - ], +class A implements N {} +// ^ +// [diag.implementsNonClass] Classes and mixins can only implement other classes and mixins. +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -128,13 +128,14 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' library L; import 'lib1.dart'; import 'lib2.dart'; -f() {new N();}''', - [error(diag.ambiguousImport, 60, 1)], +f() {new N();} +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -145,20 +146,18 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library L; import 'lib1.dart'; import 'lib2.dart'; f() { N n = .new(); +//^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. +// ^^^ +// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type 'InvalidType'. print(n); -}''', - [ - error(diag.ambiguousImport, 59, 1), - error(diag.dotShorthandUndefinedInvocation, 66, 3), - ], - ); +}'''); } test_is() async { @@ -168,12 +167,13 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; -f(p) {p is N;}''', - [error(diag.ambiguousImport, 51, 1)], +f(p) {p is N;} +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -184,12 +184,13 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; -g() { N.FOO; }''', - [error(diag.ambiguousImport, 46, 1)], +g() { N.FOO; } +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -199,7 +200,7 @@ g() { N.FOO; }''', newFile('$testPackageLibPath/a.dart', ''' class StreamController {} '''); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; // ignore: unused_import import 'a.dart'; @@ -208,14 +209,13 @@ StreamController s = StreamController(); } test_systemLibrary_systemLibrary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:html'; import 'dart:io'; g(File f) {} -''', - [error(diag.ambiguousImport, 40, 4)], - ); +//^^^^ +// [diag.ambiguousImport] The name 'File' is defined in the libraries 'dart:html' and 'dart:io'. +'''); } test_typeAnnotation() async { @@ -225,29 +225,34 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; typedef N FT(N p); +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. N f(N p) { +// [diag.ambiguousImport][column 1][length 1] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. N v; +//^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. return null; } class A { N m() { return null; } +//^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'. } -class B {}''', - [ - error(diag.ambiguousImport, 48, 1), - error(diag.ambiguousImport, 53, 1), - error(diag.ambiguousImport, 59, 1), - error(diag.ambiguousImport, 63, 1), - error(diag.ambiguousImport, 72, 1), - error(diag.unusedLocalVariable, 74, 1), - error(diag.ambiguousImport, 106, 1), - error(diag.ambiguousImport, 149, 1), - ], +class B {} +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -258,13 +263,14 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; class A {} -A? f() { return null; }''', - [error(diag.ambiguousImport, 56, 1)], +A? f() { return null; } +//^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -275,13 +281,14 @@ class N {}'''); newFile("$testPackageLibPath/lib2.dart", ''' library lib2; class N {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' import 'lib1.dart'; import 'lib2.dart'; class A {} -f() {new A();}''', - [error(diag.ambiguousImport, 65, 1)], +f() {new A();} +// ^ +// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''', ); } @@ -294,17 +301,16 @@ var x; var x; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; import 'b.dart'; void f() { x; +//^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. } -''', - [error(diag.ambiguousImport, 48, 1)], - ); +'''); } test_variable_read_prefixed() async { @@ -316,17 +322,16 @@ var x; var x; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as p; import 'b.dart' as p; void f() { p.x; +// ^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. } -''', - [error(diag.ambiguousImport, 60, 1)], - ); +'''); } test_variable_write() async { @@ -338,25 +343,25 @@ var x; var x; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; import 'b.dart'; void f() { x = 0; +//^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. x += 1; +//^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. ++x; +// ^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. x++; +//^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. } -''', - [ - error(diag.ambiguousImport, 48, 1, messageContains: ["'x'"]), - error(diag.ambiguousImport, 57, 1), - error(diag.ambiguousImport, 69, 1), - error(diag.ambiguousImport, 74, 1), - ], - ); +'''); } test_variable_write_prefixed() async { @@ -368,24 +373,24 @@ var x; var x; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as p; import 'b.dart' as p; void f() { p.x = 0; +// ^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. p.x += 1; +// ^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. ++p.x; +// ^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. p.x++; +// ^ +// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. } -''', - [ - error(diag.ambiguousImport, 60, 1), - error(diag.ambiguousImport, 71, 1), - error(diag.ambiguousImport, 85, 1), - error(diag.ambiguousImport, 92, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/ambiguous_set_or_map_literal_test.dart b/pkg/analyzer/test/src/diagnostics/ambiguous_set_or_map_literal_test.dart index 94da085151a..9edfdda9cf1 100644 --- a/pkg/analyzer/test/src/diagnostics/ambiguous_set_or_map_literal_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ambiguous_set_or_map_literal_test.dart @@ -2,22 +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(AmbiguousSetOrMapLiteralBothTest); defineReflectiveTests(AmbiguousSetOrMapLiteralEitherTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AmbiguousSetOrMapLiteralBothTest extends PubPackageResolutionTest { test_map() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Map map) { return {...map}; } @@ -25,7 +26,7 @@ f(Map map) { } test_map_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Map map) { return {...map}; } @@ -33,7 +34,7 @@ f(Map map) { } test_map_keyNonNullable_valueNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Map map) { return {...map}; } @@ -41,7 +42,7 @@ f(Map map) { } test_map_keyNullable_valueNonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Map map) { return {...map}; } @@ -49,7 +50,7 @@ f(Map map) { } test_map_keyNullable_valueNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Map map) { return {...map}; } @@ -57,7 +58,7 @@ f(Map map) { } test_set() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Set set) { return {...set}; } @@ -65,7 +66,7 @@ f(Set set) { } test_set_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Set set) { return {...set}; } @@ -73,7 +74,7 @@ f(Set set) { } test_set_elementNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(Set set) { return {...set}; } @@ -81,25 +82,23 @@ f(Set set) { } test_setAndMap() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Map map, Set set) { return {...set, ...map}; +// ^^^^^^^^^^^^^^^^ +// [diag.ambiguousSetOrMapLiteralBoth] The literal can't be either a map or a set because it contains at least one literal map entry or a spread operator spreading a 'Map', and at least one element which is neither of these. } -''', - [error(diag.ambiguousSetOrMapLiteralBoth, 46, 16)], - ); +'''); } test_setAndMap_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(Map map, Set set) { return {...set, ...map}; +// ^^^^^^^^^^^^^^^^ +// [diag.ambiguousSetOrMapLiteralBoth] The literal can't be either a map or a set because it contains at least one literal map entry or a spread operator spreading a 'Map', and at least one element which is neither of these. } -''', - [error(diag.ambiguousSetOrMapLiteralBoth, 48, 16)], - ); +'''); } } @@ -107,22 +106,20 @@ f(Map map, Set set) { class AmbiguousSetOrMapLiteralEitherTest extends PubPackageResolutionTest { test_invalidPrefixOperator() async { // Guard against an exception being thrown. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' union(a, b) => !{...a, ...b}; -''', - [error(diag.ambiguousSetOrMapLiteralEither, 16, 12)], - ); +// ^^^^^^^^^^^^ +// [diag.ambiguousSetOrMapLiteralEither] This literal must be either a map or a set, but the elements don't have enough information for type inference to work. +'''); } test_setAndMap() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var map; var set; var c = {...set, ...map}; -''', - [error(diag.ambiguousSetOrMapLiteralEither, 26, 16)], - ); +// ^^^^^^^^^^^^^^^^ +// [diag.ambiguousSetOrMapLiteralEither] This literal must be either a map or a set, but the elements don't have enough information for type inference to work. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/annotation_on_pointer_field_test.dart b/pkg/analyzer/test/src/diagnostics/annotation_on_pointer_field_test.dart index ccf9d3d475d..e6cdd22987e 100644 --- a/pkg/analyzer/test/src/diagnostics/annotation_on_pointer_field_test.dart +++ b/pkg/analyzer/test/src/diagnostics/annotation_on_pointer_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(AnnotationOnPointerFieldTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AnnotationOnPointerFieldTest extends PubPackageResolutionTest { test_double() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Double() +//^^^^^^^^^ +// [diag.annotationOnPointerField] Fields in a struct class whose type is 'Pointer' shouldn't have any annotations. external Pointer x; } -''', - [error(diag.annotationOnPointerField, 52, 9)], - ); +'''); } test_int32() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Int32() +//^^^^^^^^ +// [diag.annotationOnPointerField] Fields in a struct class whose type is 'Pointer' shouldn't have any annotations. external Pointer x; } -''', - [error(diag.annotationOnPointerField, 52, 8)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/annotation_syntax_test.dart b/pkg/analyzer/test/src/diagnostics/annotation_syntax_test.dart index 6c025ff9402..e6925f1dc0a 100644 --- a/pkg/analyzer/test/src/diagnostics/annotation_syntax_test.dart +++ b/pkg/analyzer/test/src/diagnostics/annotation_syntax_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(AnnotationSyntaxTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AnnotationSyntaxTest extends PubPackageResolutionTest { test_annotation_on_type_argument() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' const annotation = null; class Annotation { @@ -29,12 +29,11 @@ class A {} class C { m() => new A<@annotation @Annotation("test") C>(); +// ^^^^^^^^^^^ +// [diag.annotationOnTypeArgument] Type arguments can't have annotations because they aren't declarations. +// ^^^^^^^^^^^^^^^^^^^ +// [diag.annotationOnTypeArgument] Type arguments can't have annotations because they aren't declarations. } -''', - [ - error(diag.annotationOnTypeArgument, 146, 11), - error(diag.annotationOnTypeArgument, 158, 19), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/argument_must_be_a_constant_test.dart b/pkg/analyzer/test/src/diagnostics/argument_must_be_a_constant_test.dart index 665c0eb7919..3af9e3f6eb0 100644 --- a/pkg/analyzer/test/src/diagnostics/argument_must_be_a_constant_test.dart +++ b/pkg/analyzer/test/src/diagnostics/argument_must_be_a_constant_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(ArgumentMustBeAConstantTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ArgumentMustBeAConstantTest extends PubPackageResolutionTest { test_AsFunctionIsLeafGlobal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef Int8UnOp = Int8 Function(Int8); typedef IntUnOp = int Function(int); @@ -25,16 +25,15 @@ bool isLeaf = false; doThings() { Pointer> p = Pointer.fromAddress(1337); IntUnOp f = p.asFunction(isLeaf:isLeaf); +// ^^^^^^ +// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant. f(8); } -''', - [error(diag.argumentMustBeAConstant, 231, 6)], - ); +'''); } test_AsFunctionIsLeafLocal() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef Int8UnOp = Int8 Function(Int8); typedef IntUnOp = int Function(int); @@ -42,56 +41,53 @@ doThings() { bool isLeaf = false; Pointer> p = Pointer.fromAddress(1337); IntUnOp f = p.asFunction(isLeaf:isLeaf); +// ^^^^^^ +// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant. f(8); } -''', - [error(diag.argumentMustBeAConstant, 233, 6)], - ); +'''); } test_AsFunctionIsLeafParam() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef Int8UnOp = Int8 Function(Int8); typedef IntUnOp = int Function(int); doThings(bool isLeaf) { Pointer> p = Pointer.fromAddress(1337); IntUnOp f = p.asFunction(isLeaf:isLeaf); +// ^^^^^^ +// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant. f(8); } -''', - [error(diag.argumentMustBeAConstant, 221, 6)], - ); +'''); } test_FromFunctionExceptionReturn() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef NativeDoubleUnOp = Double Function(Double); double myTimesThree(double d) => d * 3; void testFromFunctionFunctionExceptionValueMustBeConst() { final notAConst = 1.1; Pointer.fromFunction(myTimesThree, notAConst); +// ^^^^^^^^^ +// [diag.argumentMustBeAConstant] Argument 'exceptionalReturn' must be a constant. } -''', - [error(diag.argumentMustBeAConstant, 250, 9)], - ); +'''); } test_LookupFunctionIsLeaf() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; typedef Int8UnOp = Int8 Function(Int8); typedef IntUnOp = int Function(int); doThings(bool isLeaf) { DynamicLibrary l = DynamicLibrary.open("my_lib"); l.lookupFunction("timesFour", isLeaf:isLeaf); +// ^^^^^^ +// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant. } -''', - [error(diag.argumentMustBeAConstant, 230, 6)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart index 1a236b74541..b14e4751041 100644 --- a/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart @@ -7,11 +7,13 @@ 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(ArgumentTypeNotAssignableTest); defineReflectiveTests(ArgumentTypeNotAssignableWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,15 +24,14 @@ class ArgumentTypeNotAssignableTest extends PubPackageResolutionTest { newFile('$testPackageLibPath/lib2.dart', ''' class _A {} g(h(_A a)) {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'lib2.dart'; class _A {} f() { g((_A a) {}); -}''', - [error(diag.argumentTypeNotAssignable, 42, 9)], - ); +// ^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'Null Function(_A)' can't be assigned to the parameter type 'dynamic Function(_A)'. +}'''); // The name _A is private to the library it's defined in, so this is a type // mismatch. Furthermore, the error message should mention both _A and the // filenames so the user can figure out what's going on. @@ -39,45 +40,42 @@ f() { } test_annotation_extensionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension type const A(String _) {} @A(0) +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. void f() {} -''', - [error(diag.argumentTypeNotAssignable, 40, 1)], - ); +'''); } test_annotation_namedConstructor() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.fromInt(int p); } @A.fromInt('0') +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. main() {} -''', - [error(diag.argumentTypeNotAssignable, 49, 3)], - ); +'''); } test_annotation_namedConstructor_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.fromInt(T p); } @A.fromInt('0') +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. main() { -}''', - [error(diag.argumentTypeNotAssignable, 55, 3)], - ); +}'''); } test_annotation_type_arguments_inferred() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' @C([]) int i = 0; @@ -88,69 +86,63 @@ class C { } test_annotation_unnamedConstructor() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(int p); } @A('0') +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. main() { -}''', - [error(diag.argumentTypeNotAssignable, 33, 3)], - ); +}'''); } test_binary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { operator +(int p) {} } f(A a) { a + '0'; -}''', - [error(diag.argumentTypeNotAssignable, 50, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_binary_eqEq_covariantParameterType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { bool operator==(covariant A other) => false; } void f(A a, A? aq) { a == 0; +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'. aq == 1; +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'. aq == aq; aq == null; } -''', - [ - error(diag.argumentTypeNotAssignable, 88, 1), - error(diag.argumentTypeNotAssignable, 99, 1), - ], - ); +'''); } test_call() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef bool Predicate(T object); Predicate f() => (String s) => false; void main() { f().call(3); -}''', - [error(diag.argumentTypeNotAssignable, 110, 1)], - ); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_cascadeSecond() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' // filler filler filler filler filler filler filler filler filler filler class A { B ma() { return new B(); } @@ -162,68 +154,62 @@ class B { main() { A a = new A(); a.. ma().mb(0); -}''', - [error(diag.argumentTypeNotAssignable, 186, 1)], - ); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_const() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(String p); } main() { const A(42); -}''', - [ - error(diag.argumentTypeNotAssignable, 52, 2), - error(diag.constConstructorParamTypeMismatch, 52, 2), - ], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.constConstructorParamTypeMismatch] A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor. +}'''); } test_const_super() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(String p); } class B extends A { const B() : super(42); -}''', - [error(diag.argumentTypeNotAssignable, 73, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_downcast() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' m() { num y = 1; n(y); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'num' can't be assigned to the parameter type 'int'. } n(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 23, 1)], - ); +'''); } test_downcast_nullableNonNullable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' m() { int? y; n(y); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int?' can't be assigned to the parameter type 'int'. } n(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 20, 1)], - ); +'''); } test_dynamicCast() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' m() { dynamic i; n(i); @@ -233,22 +219,19 @@ n(int i) {} } test_enumConstant() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(0); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +// [diag.constConstructorParamTypeMismatch] A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor. const E(String a); } -''', - [ - error(diag.argumentTypeNotAssignable, 13, 1), - error(diag.constConstructorParamTypeMismatch, 13, 1), - ], - ); +'''); } test_enumConstant_implicitDouble() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(0); const E(double a); @@ -257,7 +240,7 @@ enum E { } test_expressionFromConstructorTearoff_withoutTypeArgs() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class C { C(T a); } @@ -268,7 +251,7 @@ var x = g('Hello'); } test_expressionFromConstructorTearoff_withTypeArgs_assignable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class C { C(T a); } @@ -279,21 +262,20 @@ var x = g(0); } test_expressionFromConstructorTearoff_withTypeArgs_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { C(T a); } var g = C.new; var x = g('Hello'); -''', - [error(diag.argumentTypeNotAssignable, 56, 7)], - ); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +'''); } test_expressionFromFunctionTearoff_withoutTypeArgs() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(T a) {} var g = f; @@ -302,7 +284,7 @@ var x = g('Hello'); } test_expressionFromFunctionTearoff_withTypeArgs_assignable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(T a) {} var g = f; @@ -311,20 +293,19 @@ var x = g(0); } test_expressionFromFunctionTearoff_withTypeArgs_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(T a) {} var g = f; var x = g('Hello'); -''', - [error(diag.argumentTypeNotAssignable, 45, 7)], - ); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +'''); } test_for_element_type_inferred_from_rewritten_node() async { // See https://github.com/dart-lang/sdk/issues/39171 - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Iterable Function() g, int Function(T) h) { [for (var x in g()) if (x is String) h(x)]; } @@ -333,7 +314,7 @@ void f(Iterable Function() g, int Function(T) h) { test_for_statement_type_inferred_from_rewritten_node() async { // See https://github.com/dart-lang/sdk/issues/39171 - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Iterable Function() g, void Function(T) h) { for (var x in g()) { if (x is String) { @@ -345,32 +326,30 @@ void f(Iterable Function() g, void Function(T) h) { } test_functionExpressionInvocation_required() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' main() { (int x) {} (''); -}''', - [error(diag.argumentTypeNotAssignable, 23, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_functionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' m() { var a = new A(); a.n(() => 0); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'void Function()' can't be assigned to the parameter type 'void Function(int)'. } class A { n(void f(int i)) {} } -''', - [error(diag.argumentTypeNotAssignable, 31, 7)], - ); +'''); } test_implicitCallReference() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { void call(int p) {} } @@ -382,7 +361,7 @@ void g(A a) { } test_implicitCallReference_named() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { void call(int p) {} } @@ -395,7 +374,7 @@ void g(A a) { } test_implicitCallReference_namedAndRequired() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { void call(int p) {} } @@ -407,7 +386,7 @@ void g(A a) { } test_implicitCallReference_this() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { void call(int p) {} @@ -420,243 +399,225 @@ class A { } test_index_invalidRead() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator [](int index) => 0; } f(A a) { a['0']; -}''', - [error(diag.argumentTypeNotAssignable, 60, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_index_invalidRead_validWrite() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator [](int index) => 0; operator []=(String index, int value) {} } f(A a) { a['0'] += 0; +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. ++a['0']; +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. a['0']++; -}''', - [ - error(diag.argumentTypeNotAssignable, 103, 3), - error(diag.argumentTypeNotAssignable, 120, 3), - error(diag.argumentTypeNotAssignable, 130, 3), - ], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_index_invalidWrite() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { operator []=(int index, int value) {} } f(A a) { a['0'] = 0; -}''', - [error(diag.argumentTypeNotAssignable, 65, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_index_validRead_invalidWrite() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator [](String index) => 0; operator []=(int index, int value) {} } f(A a) { a['0'] += 0; +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. ++a['0']; +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. a['0']++; -}''', - [ - error(diag.argumentTypeNotAssignable, 103, 3), - error(diag.argumentTypeNotAssignable, 120, 3), - error(diag.argumentTypeNotAssignable, 130, 3), - ], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_interfaceType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' m() { var i = ''; n(i); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } n(int i) {} -''', - [error(diag.argumentTypeNotAssignable, 24, 1)], - ); +'''); } test_invocation_callParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { call(int p) {} } f(A a) { a('0'); -}''', - [error(diag.argumentTypeNotAssignable, 42, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_invocation_callVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { call(int p) {} } main() { A a = new A(); a('0'); -}''', - [error(diag.argumentTypeNotAssignable, 59, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_invocation_functionParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' a(b(int p)) { b('0'); -}''', - [error(diag.argumentTypeNotAssignable, 18, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_invocation_functionParameter_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { m(f(K k), V v) { f(v); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'V' can't be assigned to the parameter type 'K'. } -}''', - [error(diag.argumentTypeNotAssignable, 41, 1)], - ); +}'''); } test_invocation_functionTypes_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void acceptFunOptBool(void funNumOptBool([bool b])) {} void funBool(bool b) {} main() { acceptFunOptBool(funBool); -}''', - [error(diag.argumentTypeNotAssignable, 107, 7)], - ); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'. +}'''); } test_invocation_functionTypes_optional_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void acceptFunOptBool(void funOptBool([bool b])) {} class C { static void funBool(bool b) {} } main() { acceptFunOptBool(C.funBool); -}''', - [error(diag.argumentTypeNotAssignable, 125, 9)], - ); +// ^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'. +}'''); } test_invocation_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { m(T t) {} } f(A a) { a.m(1); -}''', - [error(diag.argumentTypeNotAssignable, 50, 1)], - ); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_invocation_named() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f({String p = ''}) {} main() { f(p: 42); -}''', - [error(diag.argumentTypeNotAssignable, 38, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_invocation_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f([String p = '']) {} main() { f(42); -}''', - [error(diag.argumentTypeNotAssignable, 35, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_invocation_required() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(String p) {} main() { f(42); -}''', - [error(diag.argumentTypeNotAssignable, 28, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_invocation_typedef_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A(T p); f(A a) { a('1'); -}''', - [error(diag.argumentTypeNotAssignable, 37, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_invocation_typedef_local() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A(int p); A getA() => throw ''; main() { A a = getA(); a('1'); -}''', - [error(diag.argumentTypeNotAssignable, 69, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_invocation_typedef_parameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A(int p); f(A a) { a('1'); -}''', - [error(diag.argumentTypeNotAssignable, 31, 3)], - ); +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. +}'''); } test_map_indexGet() async { // Any type may be passed to Map.operator[]. - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' main() { Map m = {}; m['x']; @@ -666,94 +627,78 @@ main() { test_map_indexSet() async { // The type passed to Map.operator[]= must match the key type. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' main() { Map m = {}; m['x'] = 0; +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } -''', - [error(diag.argumentTypeNotAssignable, 47, 3)], - ); +'''); } test_map_indexSet_ifNull() async { // The type passed to Map.operator[]= must match the key type. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' main() { Map m = {}; m['x'] ??= 0; +// ^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } -''', - [error(diag.argumentTypeNotAssignable, 47, 3)], - ); +'''); } test_new_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { A(T p) {} } main() { new A(42); -}''', - [error(diag.argumentTypeNotAssignable, 52, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_new_optional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { A([String p = '']) {} } main() { new A(42); -}''', - [error(diag.argumentTypeNotAssignable, 53, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } test_new_required() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { A(String p) {} } main() { new A(42); -}''', - [error(diag.argumentTypeNotAssignable, 46, 2)], - ); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'. +}'''); } void test_recordType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int a, int b) r) {} void g() { f((a: 1, b: 2)); +// ^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type '({int a, int b})' can't be assigned to the parameter type '(int, int)'. Expected 2 positional arguments, but got 0 instead. } -''', - [ - error( - diag.argumentTypeNotAssignable, - 44, - 12, - messageContains: [ - 'Expected 2 positional arguments, but got 0 instead.', - ], - ), - ], - ); +'''); } void test_recordType_namedArguments() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A = ({ int b, int c, @@ -763,22 +708,14 @@ void f(A a){print(a);} main() { f((bb:2, c:3)); +// ^^^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type '({int bb, int c})' can't be assigned to the parameter type 'A'. Unexpected named argument `bb` with type `int`. } -''', - [ - error( - diag.argumentTypeNotAssignable, - 74, - 11, - messageContains: ['Unexpected named argument `bb` with type `int`.'], - ), - ], - ); +'''); } void test_recordType_namedArguments_missing() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A = ({ int b, int c, @@ -788,22 +725,14 @@ void f(A a){print(a);} main() { f((b:2)); +// ^^^^^ +// [diag.argumentTypeNotAssignable] The argument type '({int b})' can't be assigned to the parameter type 'A'. Expected 2 named arguments, but got 1 instead. } -''', - [ - error( - diag.argumentTypeNotAssignable, - 74, - 5, - messageContains: ['Expected 2 named arguments, but got 1 instead.'], - ), - ], - ); +'''); } void test_recordType_positionalArguments() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A = ( int b, int c, @@ -813,19 +742,10 @@ void f(A a){print(a);} main() { f((3, 2, 1)); +// ^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type '(int, int, int)' can't be assigned to the parameter type 'A'. Expected 2 positional arguments, but got 3 instead. } -''', - [ - error( - diag.argumentTypeNotAssignable, - 72, - 9, - messageContains: [ - 'Expected 2 positional arguments, but got 3 instead.', - ], - ), - ], - ); +'''); } @failingTest diff --git a/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_to_error_handler_test.dart b/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_to_error_handler_test.dart index 46c0b238786..f9f9bc2f200 100644 --- a/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_to_error_handler_test.dart +++ b/pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_to_error_handler_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(() { @@ -24,6 +24,7 @@ main() { defineReflectiveTests( ArgumentTypeNotAssignableToErrorHandler_StreamSubscriptionOnErrorTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -31,7 +32,7 @@ main() { class ArgumentTypeNotAssignableToErrorHandler_FutureCatchErrorTest extends PubPackageResolutionTest { void test_firstParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(dynamic a) callback) { future.catchError(callback); } @@ -39,18 +40,17 @@ void f(Future future, Future Function(dynamic a) callback) { } void test_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function({Object a}) callback) { future.catchError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function({Object a})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 92, 8)], - ); +'''); } void test_firstParameterIsOptional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function([Object a]) callback) { future.catchError(callback); } @@ -58,7 +58,7 @@ void f(Future future, Future Function([Object a]) callback) { } void test_functionExpression_firstParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((dynamic a) {}); } @@ -66,7 +66,7 @@ void f(Future future) { } void test_functionExpression_firstParameterIsImplicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((a) {}); } @@ -74,18 +74,17 @@ void f(Future future) { } void test_functionExpression_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError(({Object a = 1}) {}); +// ^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 50, 19)], - ); +'''); } void test_functionExpression_firstParameterIsNullableObject() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object? a) {}); } @@ -93,7 +92,7 @@ void f(Future future) { } void test_functionExpression_firstParameterIsOptional() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError(([Object a = 1]) {}); } @@ -101,7 +100,7 @@ void f(Future future) { } void test_functionExpression_firstParameterIsUntyped() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((a) {}); } @@ -109,18 +108,17 @@ void f(Future future) { } void test_functionExpression_noParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError(() {}); +// ^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 50, 5)], - ); +'''); } void test_functionExpression_secondParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object a, dynamic b) {}); } @@ -128,7 +126,7 @@ void f(Future future) { } void test_functionExpression_secondParameterIsImplicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object a, b) {}); } @@ -136,18 +134,17 @@ void f(Future future) { } void test_functionExpression_secondParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object a, {required StackTrace b}) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {required StackTrace b})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 50, 38)], - ); +'''); } void test_functionExpression_secondParameterIsNullableStackTrace() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object a, StackTrace? b) {}); } @@ -155,7 +152,7 @@ void f(Future future) { } void test_functionExpression_secondParameterIsUntyped() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object a, b) {}); } @@ -163,51 +160,47 @@ void f(Future future) { } void test_functionExpression_tooManyParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((a, b, c) {}); +// ^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(dynamic, dynamic, dynamic)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 50, 12)], - ); +'''); } void test_functionExpression_wrongFirstParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((String a) {}); +// ^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 50, 13)], - ); +'''); } void test_functionExpression_wrongSecondParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((Object a, String b) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, String)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 50, 23)], - ); +'''); } void test_noParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function() callback) { future.catchError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function()' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 82, 8)], - ); +'''); } void test_okType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(Object, StackTrace) callback) { future.catchError(callback); } @@ -215,7 +208,7 @@ void f(Future future, Future Function(Object, StackTrace) callback) { } void test_secondParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(Object a, dynamic b) callback) { future.catchError(callback); } @@ -223,47 +216,43 @@ void f(Future future, Future Function(Object a, dynamic b) callback) { } void test_secondParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(Object a, {StackTrace b}) callback) { future.catchError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function(Object, {StackTrace b})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 106, 8)], - ); +'''); } void test_tooManyParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(int, int, int) callback) { future.catchError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function(int, int, int)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 95, 8)], - ); +'''); } void test_wrongFirstParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(String) callback) { future.catchError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function(String)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 88, 8)], - ); +'''); } void test_wrongSecondParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(Object, String) callback) { future.catchError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function(Object, String)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 96, 8)], - ); +'''); } } @@ -271,7 +260,7 @@ void f(Future future, Future Function(Object, String) callback) { class ArgumentTypeNotAssignableToErrorHandler_FutureThenTest extends PubPackageResolutionTest { void test_firstParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function(dynamic a) callback) { future.then((_) {}, onError: callback); } @@ -282,29 +271,27 @@ void f(Future future, void Function(dynamic a) callback) { // `void` must be specified explicitly on `then()`; the inferred type from // `() {}` would otherwise be `Null`, and `void` (or `Future`, or // `Future`) would be an illegal return type for the `onError` handler. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function({Object a}) callback) { future.then((_) {}, onError: callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function({Object a})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 111, 8)], - ); +'''); } void test_functionExpression_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: ({Object a = 1}) {}); +// ^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 61, 19)], - ); +'''); } void test_functionExpression_firstParameterIsNullableObject() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: (Object? a) {}); } @@ -312,29 +299,27 @@ void f(Future future) { } void test_functionExpression_noParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: () {}); +// ^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 61, 5)], - ); +'''); } void test_functionExpression_secondParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: (Object a, {StackTrace? b}) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 61, 30)], - ); +'''); } void test_functionExpression_secondParameterIsNullableStackTrace() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: (Object a, StackTrace? b) {}); } @@ -342,18 +327,17 @@ void f(Future future) { } void test_functionExpression_wrongFirstParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: (String a) {}); +// ^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'FutureOr Function(Object)' or 'FutureOr Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 61, 13)], - ); +'''); } void test_functionType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Function callback) { future.then((_) {}, onError: callback); } @@ -365,7 +349,7 @@ void f(Future future, Function callback) { class ArgumentTypeNotAssignableToErrorHandler_StreamHandleErrorTest extends PubPackageResolutionTest { void test_firstParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream, void Function(dynamic a) callback) { stream.handleError(callback); } @@ -373,29 +357,27 @@ void f(Stream stream, void Function(dynamic a) callback) { } void test_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream, Future Function({Object a}) callback) { stream.handleError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 94, 8)], - ); +'''); } void test_functionExpression_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.handleError(({Object a = 1}) {}); +// ^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 51, 19)], - ); +'''); } void test_functionExpression_firstParameterIsNullableObject() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.handleError((Object? a) {}); } @@ -403,29 +385,27 @@ void f(Stream stream) { } void test_functionExpression_noParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.handleError(() {}); +// ^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 51, 5)], - ); +'''); } void test_functionExpression_secondParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.handleError((Object a, {StackTrace? b}) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 51, 30)], - ); +'''); } void test_functionExpression_secondParameterIsNullableStackTrace() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.handleError((Object a, StackTrace? b) {}); } @@ -433,14 +413,13 @@ void f(Stream stream) { } void test_functionExpression_wrongFirstParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.handleError((String a) {}); +// ^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 51, 13)], - ); +'''); } } @@ -448,7 +427,7 @@ void f(Stream stream) { class ArgumentTypeNotAssignableToErrorHandler_StreamListenTest extends PubPackageResolutionTest { void test_firstParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream, void Function(dynamic a) callback) { stream.listen((_) {}, onError: callback); } @@ -456,29 +435,27 @@ void f(Stream stream, void Function(dynamic a) callback) { } void test_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream, Future Function({Object a}) callback) { stream.listen((_) {}, onError: callback); +// ^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 97, 17)], - ); +'''); } void test_functionExpression_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.listen((_) {}, onError: ({Object a = 1}) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 54, 28)], - ); +'''); } void test_functionExpression_firstParameterIsNullableObject() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.listen((_) {}, onError: (Object? a) {}); } @@ -486,29 +463,27 @@ void f(Stream stream) { } void test_functionExpression_noParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.listen((_) {}, onError: () {}); +// ^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 54, 14)], - ); +'''); } void test_functionExpression_secondParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.listen((_) {}, onError: (Object a, {StackTrace? b}) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 54, 39)], - ); +'''); } void test_functionExpression_secondParameterIsNullableStackTrace() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.listen((_) {}, onError: (Object a, StackTrace? b) {}); } @@ -516,14 +491,13 @@ void f(Stream stream) { } void test_functionExpression_wrongFirstParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Stream stream) { stream.listen((_) {}, onError: (String a) {}); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 54, 22)], - ); +'''); } } @@ -531,7 +505,7 @@ void f(Stream stream) { class ArgumentTypeNotAssignableToErrorHandler_StreamSubscriptionOnErrorTest extends PubPackageResolutionTest { void test_firstParameterIsDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f( StreamSubscription subscription, void Function(dynamic a) callback) { @@ -541,33 +515,31 @@ void f( } void test_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f( StreamSubscription subscription, Future Function({Object a}) callback) { subscription.onError(callback); +// ^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 144, 8)], - ); +'''); } void test_functionExpression_firstParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(StreamSubscription subscription) { subscription.onError(({Object a = 1}) {}); +// ^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 92, 19)], - ); +'''); } void test_functionExpression_firstParameterIsNullableObject() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(StreamSubscription subscription) { subscription.onError((Object? a) {}); @@ -576,31 +548,29 @@ void f(StreamSubscription subscription) { } void test_functionExpression_noParameters() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(StreamSubscription subscription) { subscription.onError(() {}); +// ^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 92, 5)], - ); +'''); } void test_functionExpression_secondParameterIsNamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(StreamSubscription subscription) { subscription.onError((Object a, {StackTrace? b}) {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 92, 30)], - ); +'''); } void test_functionExpression_secondParameterIsNullableStackTrace() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(StreamSubscription subscription) { subscription.onError((Object a, StackTrace? b) {}); @@ -609,14 +579,13 @@ void f(StreamSubscription subscription) { } void test_functionExpression_wrongFirstParameterType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(StreamSubscription subscription) { subscription.onError((String a) {}); +// ^^^^^^^^^^^^^ +// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'. } -''', - [error(diag.argumentTypeNotAssignableToErrorHandler, 92, 13)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assert_in_redirecting_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/assert_in_redirecting_constructor_test.dart index 77ab9b03004..03c39e25ab8 100644 --- a/pkg/analyzer/test/src/diagnostics/assert_in_redirecting_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assert_in_redirecting_constructor_test.dart @@ -2,57 +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(AssertInRedirectingConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssertInRedirectingConstructorTest extends PubPackageResolutionTest { test_class_primary_assertBeforeRedirection() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { A.named() : this(0); this : assert(x > 0), this.named(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [error(diag.primaryConstructorCannotRedirect, 64, 4)], - ); +'''); } test_class_primary_redirectionBeforeAssert() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { A.named() : this(0); this : this.named(), assert(x > 0); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [error(diag.primaryConstructorCannotRedirect, 49, 4)], - ); +'''); } test_class_typeName_assertBeforeRedirection() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int x) : assert(x > 0), this.name(); +// ^^^^^^^^^^^^^ +// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer. A.name() {} } -''', - [error(diag.assertInRedirectingConstructor, 23, 13)], - ); +'''); } test_class_typeName_justAssert() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int x) : assert(x > 0); A.name() {} @@ -61,7 +59,7 @@ class A { } test_class_typeName_justRedirection() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int x) : this.name(); A.name() {} @@ -70,77 +68,70 @@ class A { } test_class_typeName_redirectionBeforeAssert() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int x) : this.name(), assert(x > 0); +// ^^^^^^^^^^^^^ +// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer. A.name() {} } -''', - [error(diag.assertInRedirectingConstructor, 36, 13)], - ); +'''); } test_enum_primary_assertBeforeRedirection() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(int x) { v(0); const E.named() : this(0); +// ^^^^^^^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. this : assert(x > -1), this.named(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [ - error(diag.recursiveConstantConstructor, 32, 7), - error(diag.primaryConstructorCannotRedirect, 78, 4), - ], - ); +'''); } test_enum_primary_redirectionBeforeAssert() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(int x) { v(0); const E.named() : this(0); +// ^^^^^^^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. this : this.named(), assert(x > -1); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [ - error(diag.recursiveConstantConstructor, 32, 7), - error(diag.primaryConstructorCannotRedirect, 62, 4), - ], - ); +'''); } test_enum_redirectionBeforeAssert() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(42); const E(int x) : this.name(), assert(x > 0); +// ^^^^^^^^^^^^^ +// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer. const E.name(); } -''', - [error(diag.assertInRedirectingConstructor, 50, 13)], - ); +'''); } test_enum_typeName_assertBeforeRedirection() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(42); const E(int x) : assert(x > 0), this.name(); +// ^^^^^^^^^^^^^ +// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer. const E.name(); } -''', - [error(diag.assertInRedirectingConstructor, 37, 13)], - ); +'''); } test_enum_typeName_justAssert() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(42); const E(int x) : assert(x > 0); @@ -149,7 +140,7 @@ enum E { } test_enum_typeName_justRedirection() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(0); const E(int x) : this.name(); diff --git a/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart index 5f5c3f294df..ef8fdc4a289 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart @@ -6,11 +6,13 @@ 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(AssignmentOfDoNotStoreTest); defineReflectiveTests(AssignmentOfDoNotStoreInTestsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -26,7 +28,7 @@ class AssignmentOfDoNotStoreInTestsTest extends PubPackageResolutionTest { // Code that is in a test dir (the default for PubPackageResolutionTests) // should not trigger the hint. // (See:https://github.com/dart-lang/sdk/issues/45594) - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -54,7 +56,7 @@ class AssignmentOfDoNotStoreTest extends PubPackageResolutionTest { } test_cascadeExpression_assignment() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = A()..f = v; @@ -69,8 +71,7 @@ String get v => ''; } test_class_containingInstanceGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore class A { @@ -78,14 +79,13 @@ class A { } String f = A().v; -''', - [error(diag.assignmentOfDoNotStore, 91, 5)], - ); +// ^^^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. +'''); } test_class_containingInstanceMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore class A { @@ -93,14 +93,13 @@ class A { } String f = A().v(); -''', - [error(diag.assignmentOfDoNotStore, 89, 7)], - ); +// ^^^^^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. +'''); } test_class_containingStaticGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore class A { @@ -108,14 +107,13 @@ class A { } String f = A.v; -''', - [error(diag.assignmentOfDoNotStore, 98, 3)], - ); +// ^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. +'''); } test_class_containingStaticMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore class A { @@ -123,14 +121,13 @@ class A { } String f = A.v(); -''', - [error(diag.assignmentOfDoNotStore, 96, 5)], - ); +// ^^^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. +'''); } test_classMemberGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -140,17 +137,14 @@ class A { class B { String f = A().v; +// ^^^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [ - error(diag.assignmentOfDoNotStore, 106, 5, messageContains: ["'v'"]), - ], - ); +'''); } test_classStaticGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -160,14 +154,14 @@ class A { class B { String f = A.v; +// ^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [error(diag.assignmentOfDoNotStore, 113, 3)], - ); +'''); } test_functionAssignment() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -180,8 +174,7 @@ class C { } test_functionReturnValue() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -189,14 +182,14 @@ String getV() => ''; class A { final f = getV(); +// ^^^^^^ +// [diag.assignmentOfDoNotStore] 'getV' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [error(diag.assignmentOfDoNotStore, 90, 6)], - ); +'''); } test_localVariable_assignment() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -211,7 +204,7 @@ void f() { } test_localVariable_declaration() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -225,8 +218,7 @@ void f() { } test_methodReturnValue() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -236,15 +228,14 @@ class A { class B { final f = A().getV(); +// ^^^^^^^^^^ +// [diag.assignmentOfDoNotStore] 'getV' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [error(diag.assignmentOfDoNotStore, 106, 10)], - ); +'''); } test_mixin_containingInstanceMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore mixin M { @@ -254,14 +245,14 @@ mixin M { abstract class A { M get m; late String f = m.v(); +// ^^^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [error(diag.assignmentOfDoNotStore, 126, 5)], - ); +'''); } test_tearOff() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -274,8 +265,7 @@ class A { } test_topLevelGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -283,15 +273,14 @@ String get v => ''; class A { final f = v; +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [error(diag.assignmentOfDoNotStore, 89, 1)], - ); +'''); } test_topLevelGetter_binaryExpression() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -299,13 +288,12 @@ String? get v => ''; class A { final f = v ?? v; +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [ - error(diag.assignmentOfDoNotStore, 90, 1), - error(diag.assignmentOfDoNotStore, 95, 1), - ], - ); +'''); } @FailingTest(reason: 'Not yet implemented') @@ -324,75 +312,65 @@ String get v => ''; } test_topLevelVariable_assignment_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; String top = A().f; +// ^^^^^ +// [diag.assignmentOfDoNotStore] 'f' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. class A{ @doNotStore String get f => ''; } -''', - [ - error(diag.assignmentOfDoNotStore, 47, 5, messageContains: ["'f'"]), - ], - ); +'''); } test_topLevelVariable_assignment_functionExpression() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore String get _v => ''; var c = () => _v; +// ^^ +// [diag.assignmentOfDoNotStore] '_v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. String v = c(); -''', - [error(diag.assignmentOfDoNotStore, 82, 2)], - ); +'''); } test_topLevelVariable_assignment_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; String top = v; +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. @doNotStore String get v => ''; -''', - [ - error(diag.assignmentOfDoNotStore, 47, 1, messageContains: ["'v'"]), - ], - ); +'''); } test_topLevelVariable_assignment_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; String top = A().v(); +// ^^^^^^^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. class A{ @doNotStore String v() => ''; } -''', - [ - error(diag.assignmentOfDoNotStore, 47, 7, messageContains: ["'v'"]), - ], - ); +'''); } test_topLevelVariable_cascadeExpression_propertyAccess() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = A()..v; @@ -420,22 +398,20 @@ String get v => ''; } test_topLevelVariable_conditionalExpression() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { final f = 1 == 2 ? v : v; +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } @doNotStore String get v => ''; -''', - [ - error(diag.assignmentOfDoNotStore, 65, 1), - error(diag.assignmentOfDoNotStore, 69, 1), - ], - ); +'''); } @FailingTest(reason: 'Not yet implemented') @@ -456,7 +432,7 @@ class A { } test_topLevelVariable_forElement() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = [for (var _ in [1]) v]; @@ -467,7 +443,7 @@ String get v => ''; } test_topLevelVariable_ifElement() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = [if (true) v]; @@ -478,7 +454,7 @@ String get v => ''; } test_topLevelVariable_instanceCreationExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -493,7 +469,7 @@ String get v => ''; } test_topLevelVariable_isExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = v is int; @@ -513,20 +489,19 @@ import 'package:meta/meta.dart'; final v = ''; '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'library.dart'; class A { final f = v; +// ^ +// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable. } -''', - [error(diag.assignmentOfDoNotStore, 46, 1)], - ); +'''); } test_topLevelVariable_listLiteral() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = [v]; @@ -537,7 +512,7 @@ String? get v => ''; } test_topLevelVariable_mapLiteral_key() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = {v: 1}; @@ -548,7 +523,7 @@ String get v => ''; } test_topLevelVariable_mapLiteral_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = {1: v}; @@ -559,7 +534,7 @@ String get v => ''; } test_topLevelVariable_nonAssignment_argToFunctionCall() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var top = print(v); @@ -585,7 +560,7 @@ String? get v => ''; } test_topLevelVariable_nullAwareElement() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = [?v]; @@ -596,7 +571,7 @@ String? get v => ''; } test_topLevelVariable_prefixExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = -v; @@ -607,7 +582,7 @@ int get v => 1; } test_topLevelVariable_recordLiteral_namedField() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = (a: v, ); @@ -618,7 +593,7 @@ String? get v => ''; } test_topLevelVariable_recordLiteral_positionalField() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = (v, ); @@ -629,7 +604,7 @@ String? get v => ''; } test_topLevelVariable_setLiteral() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = {v}; @@ -640,7 +615,7 @@ String get v => ''; } test_topLevelVariable_spreadElement() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = [...v]; @@ -669,7 +644,7 @@ String? get v => ''; } test_topLevelVariable_switchExpression_condition() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = switch (v) { @@ -683,7 +658,7 @@ String? get v => ''; } test_topLevelVariable_throwExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; final f = throw v; diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_const_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_const_test.dart index 853010841b9..035a3dfe198 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_const_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_const_test.dart @@ -2,83 +2,77 @@ // 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(AssignmentToConstTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToConstTest extends PubPackageResolutionTest { test_instanceVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static const v = 0; } f() { A.v = 1; -}''', - [error(diag.assignmentToConst, 44, 1)], - ); +// ^ +// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization. +}'''); } test_instanceVariable_plusEq() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static const v = 0; } f() { A.v += 1; -}''', - [error(diag.assignmentToConst, 44, 1)], - ); +// ^ +// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization. +}'''); } test_localVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { const x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x = 1; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToConst, 23, 1), - ], - ); +//^ +// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization. +}'''); } test_localVariable_inForEach() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { const x = 0; for (x in [1, 2]) { +// ^ +// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization. print(x); } -}''', - [error(diag.assignmentToConst, 28, 1)], - ); +}'''); } test_localVariable_plusEq() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { const x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x += 1; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToConst, 23, 1), - ], - ); +//^ +// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart index 6995c79ecf9..fe0ff0f3652 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart @@ -2,83 +2,77 @@ // 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(AssignmentToFinalLocalTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToFinalLocalTest extends PubPackageResolutionTest { test_localVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x = 1; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 23, 1), - ], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_localVariable_forEach() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final i; for (i in [1, 2, 3]) { +// ^ +// [diag.assignmentToFinalLocal] The final variable 'i' can only be set once. print(i); } } -''', - [error(diag.assignmentToFinalLocal, 24, 1)], - ); +'''); } test_localVariable_inForEach() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; for (x in [1, 2]) { +// ^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. print(x); } -}''', - [error(diag.assignmentToFinalLocal, 28, 1)], - ); +}'''); } test_localVariable_plusEq() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x += 1; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 23, 1), - ], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_parameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 f(final x) { x = 1; -}''', - [error(diag.assignmentToFinalLocal, 31, 1)], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } /// See `10.6.1 Generative Constructors`. @@ -92,129 +86,114 @@ f(final x) { /// Note that it says 'final local variable', regardless whether the instance /// variable is final. test_parameter_fieldFormal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int x; final Object y; A(this.x) : y = (() { x = 0; +// ^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. }); } -''', - [error(diag.assignmentToFinalLocal, 65, 1)], - ); +'''); } test_parameter_superFormal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a); } class B extends A { var x; B(super.a) : x = (() { a = 0; }); +// ^ +// [diag.assignmentToFinalLocal] The final variable 'a' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 78, 1)], - ); +'''); } test_patternVariable_final() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() { final (a) = 0; a = 1; +//^ +// [diag.assignmentToFinalLocal] The final variable 'a' can only be set once. a; } -''', - [error(diag.assignmentToFinalLocal, 30, 1)], - ); +'''); } test_postfixMinusMinus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x--; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 23, 1), - ], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_postfixPlusPlus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x++; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 23, 1), - ], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_prefixMinusMinus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. --x; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 25, 1), - ], - ); +// ^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_prefixPlusPlus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. ++x; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 25, 1), - ], - ); +// ^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_suffixMinusMinus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x--; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 23, 1), - ], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } test_suffixPlusPlus() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { final x = 0; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used. x++; -}''', - [ - error(diag.unusedLocalVariable, 14, 1), - error(diag.assignmentToFinalLocal, 23, 1), - ], - ); +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_final_no_setter_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_final_no_setter_test.dart index e2ea5f6a69a..9f6b1296e9b 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_final_no_setter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_final_no_setter_test.dart @@ -2,131 +2,132 @@ // 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(AssignmentToFinalNoSetterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToFinalNoSetterTest extends PubPackageResolutionTest { test_prefixedIdentifier_class_instanceGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; } void f(A a) { a.x = 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. a.x += 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. ++a.x; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. a.x++; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. } -''', - [ - error(diag.assignmentToFinalNoSetter, 49, 1), - error(diag.assignmentToFinalNoSetter, 60, 1), - error(diag.assignmentToFinalNoSetter, 74, 1), - error(diag.assignmentToFinalNoSetter, 81, 1), - ], - ); +'''); } test_propertyAccess_class_instanceGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; } void f(A a) { (a).x = 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. (a).x += 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. ++(a).x; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. (a).x++; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. } -''', - [ - error(diag.assignmentToFinalNoSetter, 51, 1), - error(diag.assignmentToFinalNoSetter, 64, 1), - error(diag.assignmentToFinalNoSetter, 80, 1), - error(diag.assignmentToFinalNoSetter, 89, 1), - ], - ); +'''); } test_propertyAccess_extension_instanceGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { int get x => 0; } void f() { 0.x = 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'. 0.x += 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'. ++0.x; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'. 0.x++; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'. } -''', - [ - error(diag.assignmentToFinalNoSetter, 57, 1), - error(diag.assignmentToFinalNoSetter, 68, 1), - error(diag.assignmentToFinalNoSetter, 82, 1), - error(diag.assignmentToFinalNoSetter, 89, 1), - ], - ); +'''); } test_simpleIdentifier_class_instanceGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; void f() { x = 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. x += 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. ++x; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. x++; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. } } -''', - [ - error(diag.assignmentToFinalNoSetter, 46, 1), - error(diag.assignmentToFinalNoSetter, 57, 1), - error(diag.assignmentToFinalNoSetter, 71, 1), - error(diag.assignmentToFinalNoSetter, 78, 1), - ], - ); +'''); } test_simpleIdentifier_class_staticGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get x => 0; void f() { x = 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. x += 0; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. ++x; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. x++; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. } } -''', - [ - error(diag.assignmentToFinalNoSetter, 53, 1), - error(diag.assignmentToFinalNoSetter, 64, 1), - error(diag.assignmentToFinalNoSetter, 78, 1), - error(diag.assignmentToFinalNoSetter, 85, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_final_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_final_test.dart index 54379978934..1cb0c84ec98 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_final_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_final_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(AssignmentToFinalTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToFinalTest extends PubPackageResolutionTest { test_prefixedIdentifier_instanceField() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { var x = 0; } @@ -31,7 +32,7 @@ void f(A a) { } test_prefixedIdentifier_instanceField_abstract() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract int x; } @@ -46,30 +47,30 @@ void f(A a) { } test_prefixedIdentifier_instanceField_abstractFinal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { abstract final int x; } void f(A a) { a.x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++a.x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 64, 1), - error(diag.assignmentToFinal, 75, 1), - error(diag.assignmentToFinal, 89, 1), - error(diag.assignmentToFinal, 96, 1), - ], - ); +'''); } test_prefixedIdentifier_instanceField_external() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { external int x; } @@ -84,53 +85,53 @@ void f(A a) { } test_prefixedIdentifier_instanceField_externalFinal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { external final int x; } void f(A a) { a.x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++a.x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 64, 1), - error(diag.assignmentToFinal, 75, 1), - error(diag.assignmentToFinal, 89, 1), - error(diag.assignmentToFinal, 96, 1), - ], - ); +'''); } test_prefixedIdentifier_instanceField_final() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { final x = 0; } void f(A a) { a.x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++a.x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 46, 1), - error(diag.assignmentToFinal, 57, 1), - error(diag.assignmentToFinal, 71, 1), - error(diag.assignmentToFinal, 78, 1), - ], - ); +'''); } test_prefixedIdentifier_instanceField_lateFinal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { late final int x; } @@ -145,53 +146,53 @@ void f(A a) { } test_prefixedIdentifier_instanceField_lateFinal_hasInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { late final int x = 0; } void f(A a) { a.x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++a.x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. a.x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 64, 1), - error(diag.assignmentToFinal, 75, 1), - error(diag.assignmentToFinal, 89, 1), - error(diag.assignmentToFinal, 96, 1), - ], - ); +'''); } test_prefixedIdentifier_staticField_externalFinal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { external static final int x; } void f() { A.x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. A.x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++A.x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. A.x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 68, 1), - error(diag.assignmentToFinal, 79, 1), - error(diag.assignmentToFinal, 93, 1), - error(diag.assignmentToFinal, 100, 1), - ], - ); +'''); } test_prefixedIdentifier_staticField_lateFinal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { static late final int x; } @@ -206,30 +207,30 @@ void f() { } test_prefixedIdentifier_staticField_lateFinal_hasInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { static late final int x = 0; } void f() { A.x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. A.x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++A.x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. A.x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 68, 1), - error(diag.assignmentToFinal, 79, 1), - error(diag.assignmentToFinal, 93, 1), - error(diag.assignmentToFinal, 100, 1), - ], - ); +'''); } test_propertyAccess_instanceField_lateFinal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { late final int x; } @@ -244,31 +245,30 @@ void f(A a) { } test_propertyAccess_instanceField_lateFinal_hasInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { late final int x = 0; } void f(A a) { (a).x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. (a).x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++(a).x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. (a).x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 66, 1), - error(diag.assignmentToFinal, 79, 1), - error(diag.assignmentToFinal, 95, 1), - error(diag.assignmentToFinal, 104, 1), - ], - ); +'''); } test_simpleIdentifier_inheritedSetter_shadowedBy_topLevelGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { void set foo(int _) {} } @@ -278,15 +278,15 @@ int get foo => 0; class B extends A { void bar() { foo = 0; +// ^^^ +// [diag.assignmentToFinal] 'foo' can't be used as a setter because it's final. } } -''', - [error(diag.assignmentToFinal, 96, 3)], - ); +'''); } test_simpleIdentifier_instanceField_lateFinal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { late final int x; @@ -301,30 +301,30 @@ abstract class A { } test_simpleIdentifier_instanceField_lateFinal_hasInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { late final int x = 0; void f() { x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } } -''', - [ - error(diag.assignmentToFinal, 61, 1), - error(diag.assignmentToFinal, 72, 1), - error(diag.assignmentToFinal, 86, 1), - error(diag.assignmentToFinal, 93, 1), - ], - ); +'''); } test_simpleIdentifier_staticField_lateFinal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { static late final int x; @@ -339,51 +339,51 @@ abstract class A { } test_simpleIdentifier_staticField_lateFinal_hasInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { static late final int x = 0; void f() { x = 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x += 0; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x++; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } } -''', - [ - error(diag.assignmentToFinal, 68, 1), - error(diag.assignmentToFinal, 79, 1), - error(diag.assignmentToFinal, 93, 1), - error(diag.assignmentToFinal, 100, 1), - ], - ); +'''); } test_simpleIdentifier_topLevelGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int get x => 0; void f() { x = 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x += 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x++; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 30, 1), - error(diag.assignmentToFinal, 39, 1), - error(diag.assignmentToFinal, 51, 1), - error(diag.assignmentToFinal, 56, 1), - ], - ); +'''); } test_simpleIdentifier_topLevelVariable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' var x = 0; void f() { @@ -396,7 +396,7 @@ void f() { } test_simpleIdentifier_topLevelVariable_external() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' external int x; void f() { @@ -409,49 +409,49 @@ void f() { } test_simpleIdentifier_topLevelVariable_externalFinal() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' external final x; void f() { x = 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x += 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x++; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 32, 1), - error(diag.assignmentToFinal, 41, 1), - error(diag.assignmentToFinal, 53, 1), - error(diag.assignmentToFinal, 58, 1), - ], - ); +'''); } test_simpleIdentifier_topLevelVariable_final() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' final x = 0; void f() { x = 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x += 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x++; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 27, 1), - error(diag.assignmentToFinal, 36, 1), - error(diag.assignmentToFinal, 48, 1), - error(diag.assignmentToFinal, 53, 1), - ], - ); +'''); } test_simpleIdentifier_topLevelVariable_lateFinal() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' late final int x; void f() { @@ -464,23 +464,23 @@ void f() { } test_simpleIdentifier_topLevelVariable_lateFinal_hasInitializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' late final int x = 0; void f() { x = 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x += 0; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. ++x; +// ^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. x++; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [ - error(diag.assignmentToFinal, 36, 1), - error(diag.assignmentToFinal, 45, 1), - error(diag.assignmentToFinal, 57, 1), - error(diag.assignmentToFinal, 62, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_function_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_function_test.dart index b436bf96b11..6c254d00b1f 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_function_test.dart @@ -2,27 +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(AssignmentToFunctionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToFunctionTest extends PubPackageResolutionTest { test_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() {} main() { f = null; -}''', - [error(diag.assignmentToFunction, 18, 1)], - ); +//^ +// [diag.assignmentToFunction] Functions can't be assigned a value. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_method_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_method_test.dart index 761baf9e9f5..009cc7c5470 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_method_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_method_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(AssignmentToMethodTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToMethodTest extends PubPackageResolutionTest { test_instance_extendedHasMethod_extensionHasSetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { void foo() {} } @@ -28,69 +28,69 @@ extension E on C { void f(C c) { c.foo = 0; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. c.foo += 1; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. c.foo++; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. --c.foo; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. } -''', - [ - error(diag.assignmentToMethod, 94, 3), - error(diag.assignmentToMethod, 107, 3), - error(diag.assignmentToMethod, 121, 3), - error(diag.assignmentToMethod, 134, 3), - ], - ); +'''); } test_prefixedIdentifier_instanceMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } void f(A a) { a.foo = 0; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. a.foo += 1; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. a.foo++; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. ++a.foo; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. } -''', - [ - error(diag.assignmentToMethod, 47, 3), - error(diag.assignmentToMethod, 60, 3), - error(diag.assignmentToMethod, 74, 3), - error(diag.assignmentToMethod, 87, 3), - ], - ); +'''); } test_propertyAccess_instanceMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } void f(A a) { (a).foo = 0; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. (a).foo += 1; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. (a).foo++; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. ++(a).foo; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. } -''', - [ - error(diag.assignmentToMethod, 49, 3), - error(diag.assignmentToMethod, 64, 3), - error(diag.assignmentToMethod, 80, 3), - error(diag.assignmentToMethod, 95, 3), - ], - ); +'''); } test_this_extendedHasMethod_extensionHasSetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { void foo() {} } @@ -100,10 +100,10 @@ extension E on C { f() { this.foo = 0; +// ^^^ +// [diag.assignmentToMethod] Methods can't be assigned a value. } } -''', - [error(diag.assignmentToMethod, 91, 3)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_primary_constructor_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_primary_constructor_parameter_test.dart index 6b1f99a1660..1e7a1b582fa 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_primary_constructor_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_primary_constructor_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(AssignmentToPrimaryConstructorParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,169 +18,153 @@ main() { class AssignmentToPrimaryConstructorParameterTest extends PubPackageResolutionTest { test_fieldInitializer_late() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { late int y = x = 0; +// ^ +// [diag.undefinedIdentifier] Undefined name 'x'. } -''', - [error(diag.undefinedIdentifier, 32, 1)], - ); +'''); } test_fieldInitializer_notLate() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y = x = 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 27, 1)], - ); +'''); } test_fieldInitializer_notLate_closure() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { var f = () { x = 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. }; } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 36, 1)], - ); +'''); } test_fieldInitializer_notLate_nullAware() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int? x) { int y = x ??= 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 28, 1)], - ); +'''); } test_fieldInitializer_notLate_pattern_list() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { List y = [x] = [2]; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 34, 1)], - ); +'''); } test_fieldInitializer_notLate_pattern_logicalAnd() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x, int z) { int y = (x && z) = 2; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [ - error(diag.assignmentToPrimaryConstructorParameter, 35, 1), - error(diag.assignmentToPrimaryConstructorParameter, 40, 1), - ], - ); +'''); } test_fieldInitializer_notLate_pattern_map() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { Map y = {null: x} = {null: 2}; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 45, 1)], - ); +'''); } test_fieldInitializer_notLate_pattern_nullAssert() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int? x) { int y = (x!) = 2; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. +// ^ +// [diag.unnecessaryNullAssertPattern] The null-assert pattern will have no effect because the matched type isn't nullable. } -''', - [ - error(diag.assignmentToPrimaryConstructorParameter, 29, 1), - error(diag.unnecessaryNullAssertPattern, 30, 1), - ], - ); +'''); } test_fieldInitializer_notLate_pattern_object() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { Object y = int(sign: x) = 2; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 40, 1)], - ); +'''); } test_fieldInitializer_notLate_pattern_parenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y = (x) = 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 28, 1)], - ); +'''); } test_fieldInitializer_notLate_pattern_record() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { (int, {bool name}) y = (x, name: _) = (2, name: true); +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 43, 1)], - ); +'''); } test_fieldInitializer_notLate_plusEq() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y = x += 1; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 27, 1)], - ); +'''); } test_fieldInitializer_notLate_postfix() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y = x++; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 27, 1)], - ); +'''); } test_fieldInitializer_notLate_prefix() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y = ++x; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 29, 1)], - ); +'''); } test_primaryConstructor_body() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { this { x = 0; @@ -189,76 +174,70 @@ class A(int x) { } test_primaryConstructor_initializer() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y; this : y = x = 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 39, 1)], - ); +'''); } test_primaryConstructor_initializer_closure() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { var f; this : f = (() { x = 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. }); } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 49, 1)], - ); +'''); } test_primaryConstructor_initializer_nullAware() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int? x) { int y; this : y = x ??= 0; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 40, 1)], - ); +'''); } test_primaryConstructor_initializer_plusEq() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y; this : y = x += 1; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 39, 1)], - ); +'''); } test_primaryConstructor_initializer_postfix() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y; this : y = x++; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 39, 1)], - ); +'''); } test_primaryConstructor_initializer_prefix() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A(int x) { int y; this : y = ++x; +// ^ +// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer. } -''', - [error(diag.assignmentToPrimaryConstructorParameter, 41, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_type_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_type_test.dart index 21741035630..b28e0417bac 100644 --- a/pkg/analyzer/test/src/diagnostics/assignment_to_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/assignment_to_type_test.dart @@ -2,89 +2,84 @@ // 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(AssignmentToTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AssignmentToTypeTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C {} main() { C = null; +//^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 22, 1)], - ); +'''); } test_dynamic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { dynamic = 1; +//^^^^^^^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 13, 7)], - ); +'''); } test_enum() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' enum E { e } main() { E = null; +//^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 24, 1)], - ); +'''); } test_typedef_functionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef void F(); main() { F = null; +//^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 29, 1)], - ); +'''); } test_typedef_interfaceType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef F = List; void f() { F = null; +//^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 37, 1)], - ); +'''); } test_typeParameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { f() { T = null; +// ^ +// [diag.assignmentToType] Types can't be assigned a value. } } -''', - [error(diag.assignmentToType, 25, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/async_for_in_wrong_context_test.dart b/pkg/analyzer/test/src/diagnostics/async_for_in_wrong_context_test.dart index 8c1195d252e..697f725ef91 100644 --- a/pkg/analyzer/test/src/diagnostics/async_for_in_wrong_context_test.dart +++ b/pkg/analyzer/test/src/diagnostics/async_for_in_wrong_context_test.dart @@ -2,31 +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(AsyncForInWrongContextTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AsyncForInWrongContextTest extends PubPackageResolutionTest { test_syncFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(list) { await for (var e in list) { +//^^^^^ +// [diag.asyncForInWrongContext] The async for-in loop can only be used in an async function. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used. } } -''', - [ - error(diag.asyncForInWrongContext, 12, 5), - error(diag.unusedLocalVariable, 27, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/async_keyword_used_as_identifier_test.dart b/pkg/analyzer/test/src/diagnostics/async_keyword_used_as_identifier_test.dart index 77146eda109..6194c9a303d 100644 --- a/pkg/analyzer/test/src/diagnostics/async_keyword_used_as_identifier_test.dart +++ b/pkg/analyzer/test/src/diagnostics/async_keyword_used_as_identifier_test.dart @@ -2,113 +2,95 @@ // 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(AsyncKeywordUsedAsIdentifierTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AsyncKeywordUsedAsIdentifierTest extends PubPackageResolutionTest { test_async_async() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { m() async { int async; +// ^^^^^ +// [diag.unusedLocalVariable] The value of the local variable 'async' isn't used. } } -''', - [error(diag.unusedLocalVariable, 32, 5)], - ); +'''); } test_await_async() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() async { var await = 1; +// ^^^^^ +// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function. +// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used. } -''', - [ - error(diag.asyncKeywordUsedAsIdentifier, 18, 5), - error(diag.unusedLocalVariable, 18, 5), - ], - ); +'''); } test_await_asyncStar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() async* { var await = 1; +// ^^^^^ +// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function. +// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used. } -''', - [ - error(diag.asyncKeywordUsedAsIdentifier, 19, 5), - error(diag.unusedLocalVariable, 19, 5), - ], - ); +'''); } test_await_syncStar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() sync* { var await = 1; +// ^^^^^ +// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function. +// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used. } -''', - [ - error(diag.asyncKeywordUsedAsIdentifier, 18, 5), - error(diag.unusedLocalVariable, 18, 5), - ], - ); +'''); } test_yield_async() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() async { var yield = 1; +// ^^^^^ +// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function. +// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used. } -''', - [ - error(diag.asyncKeywordUsedAsIdentifier, 18, 5), - error(diag.unusedLocalVariable, 18, 5), - ], - ); +'''); } test_yield_asyncStar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() async* { var yield = 1; +// ^^^^^ +// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function. +// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used. } -''', - [ - error(diag.asyncKeywordUsedAsIdentifier, 19, 5), - error(diag.unusedLocalVariable, 19, 5), - ], - ); +'''); } test_yield_syncStar() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() sync* { var yield = 1; +// ^^^^^ +// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function. +// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used. } -''', - [ - error(diag.asyncKeywordUsedAsIdentifier, 18, 5), - error(diag.unusedLocalVariable, 18, 5), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart index 121c26a3ecd..1acf48329e1 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_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(AugmentationOfDifferentDeclarationKindTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,143 +18,87 @@ main() { class AugmentationOfDifferentDeclarationKindTest extends PubPackageResolutionTest { test_class_augments_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} +// ^ +// [context 1] The declaration being augmented. augment class A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 5, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a enum with a class. +'''); } test_class_augments_extension() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} +// ^ +// [context 1] The declaration being augmented. augment class A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 22, - 7, - contextMessages: [message(testFile, 10, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a extension with a class. +'''); } test_class_augments_extensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} +// ^ +// [context 1] The declaration being augmented. augment class A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 28, - 7, - contextMessages: [message(testFile, 15, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a extension type with a class. +'''); } test_class_augments_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} +// ^^^ +// [context 1] The declaration being augmented. augment class foo {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 14, - 7, - contextMessages: [message(testFile, 5, 3)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a function with a class. +'''); } test_class_augments_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int get foo => 0; +// ^^^ +// [context 1] The declaration being augmented. augment class foo {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 18, - 7, - contextMessages: [message(testFile, 8, 3)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a getter with a class. +'''); } test_class_augments_mixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} +// ^ +// [context 1] The declaration being augmented. augment class A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a mixin with a class. +'''); } test_class_augments_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' set foo(int _) {} +// ^^^ +// [context 1] The declaration being augmented. augment class foo {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 18, - 7, - contextMessages: [message(testFile, 4, 3)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a setter with a class. +'''); } test_class_augments_variable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int foo = 0; +// ^^^ +// [context 1] The declaration being augmented. augment class foo {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 13, - 7, - contextMessages: [message(testFile, 4, 3)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a top level variable with a class. +'''); } test_class_constructor_augments_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); } @@ -164,49 +109,37 @@ augment class A { } test_class_constructor_augments_staticField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int foo = 0; +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment A.foo(); +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a constructor. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 54, - 7, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_class_constructor_augments_staticMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment A.foo(); +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a constructor. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 55, - 7, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_class_instanceField_augments_instanceField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; } @@ -217,34 +150,25 @@ augment class A { } test_class_instanceField_augments_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} +// ^^^ +// [context 1] The declaration being augmented. +// [context 2] The first definition of this name. } augment class A { augment int foo = 0; +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a field. +// ^^^ +// [diag.duplicateDefinition][context 2] The name 'foo' is already defined. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 48, - 7, - contextMessages: [message(testFile, 17, 3)], - ), - error( - diag.duplicateDefinition, - 60, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_class_instanceGetter_augments_instanceField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; } @@ -255,70 +179,52 @@ augment class A { } test_class_instanceGetter_augments_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a getter. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 48, - 7, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_class_instanceMethod_augments_instanceField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 47, - 7, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_class_instanceMethod_augments_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a getter with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 52, - 7, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } test_class_instanceMethod_augments_instanceMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -329,28 +235,22 @@ augment class A { } test_class_instanceMethod_augments_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { set foo(int _) {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a setter with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 52, - 7, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_class_instanceSetter_augments_instanceField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; } @@ -361,262 +261,186 @@ augment class A { } test_class_instanceSetter_augments_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a setter. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 48, - 7, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_class_staticField_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); +// ^^^ +// [context 1] The declaration being augmented. +// [diag.conflictingConstructorAndStaticField] 'foo' can't be used to name both a constructor and a static field in this class. } augment class A { augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a field. } -''', - [ - error(diag.conflictingConstructorAndStaticField, 14, 3), - error( - diag.augmentationOfDifferentDeclarationKind, - 43, - 7, - contextMessages: [message(testFile, 14, 3)], - ), - ], - ); +'''); } test_class_staticField_augments_staticMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} +// ^^^ +// [context 1] The declaration being augmented. +// [context 2] The first definition of this name. } augment class A { augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a field. +// ^^^ +// [diag.duplicateDefinition][context 2] The name 'foo' is already defined. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 55, - 7, - contextMessages: [message(testFile, 24, 3)], - ), - error( - diag.duplicateDefinition, - 74, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_class_staticGetter_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a getter. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 43, - 7, - contextMessages: [message(testFile, 14, 3)], - ), - ], - ); +'''); } test_class_staticGetter_augments_staticMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a getter. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 55, - 7, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_class_staticMethod_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 43, - 7, - contextMessages: [message(testFile, 14, 3)], - ), - ], - ); +'''); } test_class_staticMethod_augments_staticField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int foo = 0; +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 54, - 7, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_class_staticMethod_augments_staticGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get foo => 0; +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a getter with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 59, - 7, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_class_staticMethod_augments_staticSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static set foo(int _) {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a setter with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 59, - 7, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_class_staticSetter_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a setter. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 43, - 7, - contextMessages: [message(testFile, 14, 3)], - ), - ], - ); +'''); } test_class_staticSetter_augments_staticMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} +// ^^^ +// [context 1] The declaration being augmented. } augment class A { augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a setter. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 55, - 7, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_enum_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} +// ^ +// [context 1] The declaration being augmented. augment enum A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a enum. +'''); } test_enum_constant_augments_constant() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum A { foo } @@ -627,153 +451,101 @@ augment enum A { } test_enum_constant_augments_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { v; void foo() {} } augment enum A { augment foo(), +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } -''', - [ - error(diag.augmentationWithoutDeclaration, 51, 7), - error(diag.conflictingStaticAndInstance, 59, 3), - ], - ); +'''); } test_enum_staticMethod_augments_constant() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { foo +//^^^ +// [context 1] The declaration being augmented. } augment enum A {; augment static void foo() {} +//^^^^^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a method. } -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 37, - 7, - contextMessages: [message(testFile, 11, 3)], - ), - ], - ); +'''); } test_extension_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} +// ^ +// [context 1] The declaration being augmented. augment extension A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a extension. +'''); } test_extensionType_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} +// ^ +// [context 1] The declaration being augmented. augment extension type A(int it) {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a extension type. +'''); } test_function_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} +// ^ +// [context 1] The declaration being augmented. augment void A() {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a function. +'''); } test_mixin_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} +// ^ +// [context 1] The declaration being augmented. augment mixin A {} -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a mixin. +'''); } test_typedef_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment typedef A = int; -''', - [error(diag.typedefAugmentation, 11, 7)], - ); +// [diag.typedefAugmentation][column 1][length 7] Type aliases can't be augmented. +'''); } test_variable_augments_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} +// ^ +// [context 1] The declaration being augmented. augment int A = 0; -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 11, - 7, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a top level variable. +'''); } test_variable_augments_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} +// ^^^ +// [context 1] The declaration being augmented. augment int foo = 0; -''', - [ - error( - diag.augmentationOfDifferentDeclarationKind, - 14, - 7, - contextMessages: [message(testFile, 5, 3)], - ), - ], - ); +// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a function with a top level variable. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_of_mixin_application_class_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_of_mixin_application_class_test.dart index 7136b9d1369..9dd33234876 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_of_mixin_application_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_of_mixin_application_class_test.dart @@ -2,35 +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(AugmentationOfMixinApplicationClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AugmentationOfMixinApplicationClassTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M {} class C = A with M; +// ^ +// [context 1] The declaration being augmented. augment class C {} -''', - [ - error( - diag.augmentationOfMixinApplicationClass, - 42, - 7, - contextMessages: [message(testFile, 28, 1)], - ), - ], - ); +// [diag.augmentationOfMixinApplicationClass][column 1][length 7][context 1] Mixin application classes can't be augmented. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart index 30011e63578..b813650a501 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart @@ -2,45 +2,44 @@ // 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(AugmentationTypeParameterBoundTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AugmentationTypeParameterBoundTest extends PubPackageResolutionTest { test_class_method_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} augment void foo(); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. } -''', - [error(diag.augmentationTypeParameterBound, 58, 3)], - ); +'''); } test_class_method_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} augment void foo(); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. } -''', - [error(diag.augmentationTypeParameterBound, 70, 3)], - ); +'''); } test_class_method_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} augment void foo(); @@ -49,41 +48,39 @@ class A { } test_class_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterBound, 40, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_class_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterBound, 52, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_class_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} '''); } test_class_num_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} '''); } test_class_num_num_viaTypeAlias() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef N = num; class A {} @@ -92,7 +89,7 @@ augment class A {} } test_class_num_num_withImportPrefix() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:core'; import 'dart:core' as core; @@ -102,180 +99,169 @@ augment class A {} } test_class_num_Object() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterBound, 52, 6)], - ); +// ^^^^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_enum_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterBound, 39, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_enum_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterBound, 51, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_enum_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} '''); } test_enum_num_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} '''); } test_extension_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterBound, 55, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_extension_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterBound, 67, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_extension_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} '''); } test_extension_num_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} '''); } test_extensionType_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterBound, 66, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_extensionType_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterBound, 78, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_extensionType_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} '''); } test_extensionType_num_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} '''); } test_mixin_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterBound, 40, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_mixin_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterBound, 52, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_mixin_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} '''); } test_mixin_num_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} '''); } test_topLevelFunction_nothing_num() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} augment void foo(); -''', - [error(diag.augmentationTypeParameterBound, 44, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_topLevelFunction_num_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} augment void foo(); -''', - [error(diag.augmentationTypeParameterBound, 56, 3)], - ); +// ^^^ +// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. +'''); } test_topLevelFunction_num_nothing() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} augment void foo(); '''); } test_topLevelFunction_num_num_viaTypeAlias() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef N = num; void foo() {} @@ -284,7 +270,7 @@ augment void foo(); } test_topLevelFunction_num_num_withImportPrefix() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:core'; import 'dart:core' as core; diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart index 4a67a0de6c3..e686de15ce9 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart @@ -2,7 +2,6 @@ // 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'; @@ -18,13 +17,12 @@ main() { @reflectiveTest class AugmentationTypeParameterCountTest extends PubPackageResolutionTest { test_class_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterCount, 27, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.classDeclaration('augment class A'); assertResolvedNodeText(node, r''' ClassDeclaration @@ -48,13 +46,12 @@ ClassDeclaration } test_class_1_0() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterCount, 28, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.classDeclaration('augment class A'); assertResolvedNodeText(node, r''' ClassDeclaration @@ -70,7 +67,7 @@ ClassDeclaration } test_class_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} '''); @@ -97,13 +94,12 @@ ClassDeclaration } test_class_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterCount, 33, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.classDeclaration('augment class A'); assertResolvedNodeText(node, r''' ClassDeclaration @@ -131,13 +127,12 @@ ClassDeclaration } test_class_1_3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterCount, 33, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.classDeclaration('augment class A'); assertResolvedNodeText(node, r''' ClassDeclaration @@ -169,13 +164,12 @@ ClassDeclaration } test_class_2_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterCount, 34, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.classDeclaration('augment class A'); assertResolvedNodeText(node, r''' ClassDeclaration @@ -199,17 +193,16 @@ ClassDeclaration } test_class_method_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } augment class A { augment void foo(); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. } -''', - [error(diag.augmentationTypeParameterCount, 65, 1)], - ); +'''); var node = findNode.methodDeclaration('augment void foo'); assertResolvedNodeText(node, r''' MethodDeclaration @@ -239,7 +232,7 @@ MethodDeclaration } test_class_method_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -276,17 +269,16 @@ MethodDeclaration } test_class_method_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } augment class A { augment void foo(); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. } -''', - [error(diag.augmentationTypeParameterCount, 71, 1)], - ); +'''); var node = findNode.methodDeclaration('augment void foo'); assertResolvedNodeText(node, r''' MethodDeclaration @@ -320,13 +312,12 @@ MethodDeclaration } test_enum_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterCount, 26, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.enumDeclaration('augment enum A'); assertResolvedNodeText(node, r''' EnumDeclaration @@ -350,13 +341,12 @@ EnumDeclaration } test_enum_1_0() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterCount, 27, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.enumDeclaration('augment enum A'); assertResolvedNodeText(node, r''' EnumDeclaration @@ -372,7 +362,7 @@ EnumDeclaration } test_enum_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} '''); @@ -399,13 +389,12 @@ EnumDeclaration } test_enum_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterCount, 32, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.enumDeclaration('augment enum A'); assertResolvedNodeText(node, r''' EnumDeclaration @@ -433,13 +422,12 @@ EnumDeclaration } test_enum_2_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterCount, 33, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.enumDeclaration('augment enum A'); assertResolvedNodeText(node, r''' EnumDeclaration @@ -463,13 +451,12 @@ EnumDeclaration } test_extension_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterCount, 42, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionDeclaration('augment extension A'); assertResolvedNodeText(node, r''' ExtensionDeclaration @@ -492,13 +479,12 @@ ExtensionDeclaration } test_extension_1_0() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterCount, 43, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionDeclaration('augment extension A'); assertResolvedNodeText(node, r''' ExtensionDeclaration @@ -513,7 +499,7 @@ ExtensionDeclaration } test_extension_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} '''); @@ -539,13 +525,12 @@ ExtensionDeclaration } test_extension_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterCount, 48, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionDeclaration('augment extension A'); assertResolvedNodeText(node, r''' ExtensionDeclaration @@ -572,13 +557,12 @@ ExtensionDeclaration } test_extension_2_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterCount, 49, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionDeclaration('augment extension A'); assertResolvedNodeText(node, r''' ExtensionDeclaration @@ -601,13 +585,12 @@ ExtensionDeclaration } test_extensionType_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterCount, 53, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionTypeDeclaration('augment extension type A'); assertResolvedNodeText(node, r''' ExtensionTypeDeclaration @@ -648,13 +631,12 @@ ExtensionTypeDeclaration } test_extensionType_1_0() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterCount, 54, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionTypeDeclaration('augment extension type A'); assertResolvedNodeText(node, r''' ExtensionTypeDeclaration @@ -687,7 +669,7 @@ ExtensionTypeDeclaration } test_extensionType_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} '''); @@ -731,13 +713,12 @@ ExtensionTypeDeclaration } test_extensionType_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterCount, 59, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionTypeDeclaration('augment extension type A'); assertResolvedNodeText(node, r''' ExtensionTypeDeclaration @@ -782,13 +763,12 @@ ExtensionTypeDeclaration } test_extensionType_2_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterCount, 60, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.extensionTypeDeclaration('augment extension type A'); assertResolvedNodeText(node, r''' ExtensionTypeDeclaration @@ -829,13 +809,12 @@ ExtensionTypeDeclaration } test_mixin_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterCount, 27, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.mixinDeclaration('augment mixin A'); assertResolvedNodeText(node, r''' MixinDeclaration @@ -858,13 +837,12 @@ MixinDeclaration } test_mixin_1_0() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterCount, 28, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.mixinDeclaration('augment mixin A'); assertResolvedNodeText(node, r''' MixinDeclaration @@ -879,7 +857,7 @@ MixinDeclaration } test_mixin_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} '''); @@ -905,13 +883,12 @@ MixinDeclaration } test_mixin_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterCount, 33, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.mixinDeclaration('augment mixin A'); assertResolvedNodeText(node, r''' MixinDeclaration @@ -938,13 +915,12 @@ MixinDeclaration } test_mixin_2_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterCount, 34, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.mixinDeclaration('augment mixin A'); assertResolvedNodeText(node, r''' MixinDeclaration @@ -967,13 +943,12 @@ MixinDeclaration } test_topLevelFunction_0_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() {} augment void f(); -''', - [error(diag.augmentationTypeParameterCount, 27, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.functionDeclaration('augment void f'); assertResolvedNodeText(node, r''' FunctionDeclaration @@ -1008,7 +983,7 @@ FunctionDeclaration } test_topLevelFunction_1_1() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() {} augment void f(); '''); @@ -1046,13 +1021,12 @@ FunctionDeclaration } test_topLevelFunction_1_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() {} augment void f(); -''', - [error(diag.augmentationTypeParameterCount, 33, 1)], - ); +// ^ +// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. +'''); var node = findNode.functionDeclaration('augment void f'); assertResolvedNodeText(node, r''' FunctionDeclaration diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart index 49786653d63..889ce5a113b 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart @@ -2,101 +2,93 @@ // 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(AugmentationTypeParameterNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AugmentationTypeParameterNameTest extends PubPackageResolutionTest { test_class_method_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} augment void foo(); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. } -''', - [error(diag.augmentationTypeParameterName, 48, 1)], - ); +'''); } test_class_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [error(diag.augmentationTypeParameterName, 30, 1)], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } test_class_TU_UT() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} -''', - [ - error(diag.augmentationTypeParameterName, 33, 1), - error(diag.augmentationTypeParameterName, 36, 1), - ], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } test_enum_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A {v} augment enum A {} -''', - [error(diag.augmentationTypeParameterName, 29, 1)], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } test_extension_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A {} -''', - [error(diag.augmentationTypeParameterName, 45, 1)], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } test_extensionType_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) {} -''', - [error(diag.augmentationTypeParameterName, 56, 1)], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } test_mixin_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A {} -''', - [error(diag.augmentationTypeParameterName, 30, 1)], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } test_topLevelFunction_T_U() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} augment void foo(); -''', - [error(diag.augmentationTypeParameterName, 34, 1)], - ); +// ^ +// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart index 98492950da2..923450609f2 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_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(AugmentationWithoutDeclarationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AugmentationWithoutDeclarationTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment class A {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_class_augments_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A {} @@ -33,78 +32,73 @@ augment class A {} } test_class_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment A.named(); +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_constructor_augments_instanceField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; } augment class A { augment A.foo(); +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 48, 7)], - ); +'''); } test_class_constructor_augments_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } augment class A { augment A.foo(); +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 49, 7)], - ); +'''); } test_class_instanceField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_instanceField_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); } augment class A { augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 44, 7)], - ); +'''); } test_class_instanceField_augments_instanceField() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; } @@ -116,142 +110,171 @@ augment class A { } test_class_instanceField_augments_staticField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int foo = 0; +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } augment class A { augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [ - error(diag.conflictingStaticAndInstance, 23, 3), - error(diag.augmentationWithoutDeclaration, 54, 7), - ], - ); +'''); } test_class_instanceField_augments_staticGetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static int get foo => 0;', - augmentation: 'int foo = 0;', - conflictAtAugmentation: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static int get foo => 0; +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +augment class A { + augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceField_augments_staticMethod() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static void foo() {}', - augmentation: 'int foo = 0;', - conflictAtAugmentation: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static void foo() {} +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +augment class A { + augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceField_augments_staticSetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static set foo(int _) {}', - augmentation: 'int foo = 0;', - conflictAtAugmentation: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static set foo(int _) {} +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +augment class A { + augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_instanceGetter_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); } augment class A { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 44, 7)], - ); +'''); } test_class_instanceGetter_augments_staticField() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static int foo = 0;', - augmentation: 'int get foo => 0;', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static int foo = 0; +} +augment class A { + augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceGetter_augments_staticGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get foo => 0; } augment class A { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 59, 7)], - ); +'''); } test_class_instanceGetter_augments_staticMethod() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static void foo() {}', - augmentation: 'int get foo => 0;', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static void foo() {} +} +augment class A { + augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceGetter_augments_staticSetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static set foo(int _) {}', - augmentation: 'int get foo => 0;', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static set foo(int _) {} +} +augment class A { + augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_instanceMethod_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); } augment class A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 44, 7)], - ); +'''); } test_class_instanceMethod_augments_instanceMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -263,325 +286,432 @@ augment class A { } test_class_instanceMethod_augments_staticField() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static int foo = 0;', - augmentation: 'void foo() {}', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static int foo = 0; +} +augment class A { + augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceMethod_augments_staticGetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static int get foo => 0;', - augmentation: 'void foo() {}', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static int get foo => 0; +} +augment class A { + augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceMethod_augments_staticMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} } augment class A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 55, 7)], - ); +'''); } test_class_instanceMethod_augments_staticSetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static set foo(int _) {}', - augmentation: 'void foo() {}', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static set foo(int _) {} +} +augment class A { + augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_instanceSetter_augments_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.foo(); } augment class A { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 44, 7)], - ); +'''); } test_class_instanceSetter_augments_staticField() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static int foo = 0;', - augmentation: 'set foo(int _) {}', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static int foo = 0; +} +augment class A { + augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceSetter_augments_staticGetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static int get foo => 0;', - augmentation: 'set foo(int _) {}', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static int get foo => 0; +} +augment class A { + augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceSetter_augments_staticMethod() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'static void foo() {}', - augmentation: 'set foo(int _) {}', - expectConflict: false, - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + static void foo() {} +} +augment class A { + augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +} +'''); } test_class_instanceSetter_augments_staticSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static set foo(int _) {} } augment class A { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 59, 7)], - ); +'''); } test_class_staticField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_staticField_augments_instanceField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo = 0; } augment class A { augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } -''', - [ - error(diag.augmentationWithoutDeclaration, 47, 7), - error(diag.conflictingStaticAndInstance, 66, 3), - ], - ); +'''); } test_class_staticField_augments_instanceGetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'int get foo => 0;', - augmentation: 'static int foo = 0;', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + int get foo => 0; +} +augment class A { + augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticField_augments_instanceMethod() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'void foo() {}', - augmentation: 'static int foo = 0;', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + void foo() {} +} +augment class A { + augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticField_augments_instanceSetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'set foo(int _) {}', - augmentation: 'static int foo = 0;', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + set foo(int _) {} +} +augment class A { + augment static int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_staticGetter_augments_instanceField() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'int foo = 0;', - augmentation: 'static int get foo => 0;', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + int foo = 0; +} +augment class A { + augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticGetter_augments_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get foo => 0; } augment class A { augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } -''', - [ - error(diag.augmentationWithoutDeclaration, 52, 7), - error(diag.conflictingStaticAndInstance, 75, 3), - ], - ); +'''); } test_class_staticGetter_augments_instanceMethod() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'void foo() {}', - augmentation: 'static int get foo => 0;', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + void foo() {} +} +augment class A { + augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticGetter_augments_instanceSetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'set foo(int _) {}', - augmentation: 'static int get foo => 0;', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + set foo(int _) {} +} +augment class A { + augment static int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment static void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_staticMethod_augments_instanceField() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'int foo = 0;', - augmentation: 'static void foo() {}', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + int foo = 0; +} +augment class A { + augment static void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticMethod_augments_instanceGetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'int get foo => 0;', - augmentation: 'static void foo() {}', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + int get foo => 0; +} +augment class A { + augment static void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticMethod_augments_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } augment class A { augment static void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } -''', - [ - error(diag.augmentationWithoutDeclaration, 48, 7), - error(diag.conflictingStaticAndInstance, 68, 3), - ], - ); +'''); } test_class_staticMethod_augments_instanceSetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'set foo(int _) {}', - augmentation: 'static void foo() {}', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + set foo(int _) {} +} +augment class A { + augment static void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A { augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_class_staticSetter_augments_instanceField() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'int foo = 0;', - augmentation: 'static set foo(int _) {}', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + int foo = 0; +} +augment class A { + augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticSetter_augments_instanceGetter() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'int get foo => 0;', - augmentation: 'static set foo(int _) {}', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + int get foo => 0; +} +augment class A { + augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticSetter_augments_instanceMethod() async { - await _assertClassMemberAugmentationWithoutDeclaration( - declaration: 'void foo() {}', - augmentation: 'static set foo(int _) {}', - ); + await resolveTestCodeWithDiagnostics(r''' +class A { + void foo() {} +} +augment class A { + augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. +} +'''); } test_class_staticSetter_augments_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { set foo(int _) {} } augment class A { augment static set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } -''', - [ - error(diag.augmentationWithoutDeclaration, 52, 7), - error(diag.conflictingStaticAndInstance, 71, 3), - ], - ); +'''); } test_enum() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment enum A {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_enum_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { v; const A(); @@ -589,18 +719,16 @@ enum A { augment enum A {; augment const A.named(); +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^^^ +// [diag.unusedElement] The declaration 'A.named' isn't referenced. } -''', - [ - error(diag.augmentationWithoutDeclaration, 50, 7), - error(diag.unusedElement, 66, 5), - ], - ); +'''); } test_enum_instanceField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { v; const A(); @@ -608,15 +736,14 @@ enum A { augment enum A {; augment final int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 50, 7)], - ); +'''); } test_enum_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { v; const A(); @@ -624,15 +751,14 @@ enum A { augment enum A {; augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 50, 7)], - ); +'''); } test_enum_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { v; const A(); @@ -640,15 +766,14 @@ enum A { augment enum A {; augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 50, 7)], - ); +'''); } test_enum_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum A { v; const A(); @@ -656,171 +781,155 @@ enum A { augment enum A {; augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 50, 7)], - ); +'''); } test_extension() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment extension A {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_extension_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 47, 7)], - ); +'''); } test_extension_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 47, 7)], - ); +'''); } test_extension_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension A on int {} augment extension A { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 47, 7)], - ); +'''); } test_extensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment extension type A(int it) {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_extensionType_constructor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) { augment A.named() : this(0); +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 66, 7)], - ); +'''); } test_extensionType_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 66, 7)], - ); +'''); } test_extensionType_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) { augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 66, 7)], - ); +'''); } test_extensionType_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} augment extension type A(int it) { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 66, 7)], - ); +'''); } test_mixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment mixin A {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_mixin_instanceField() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A { augment int foo = 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_mixin_instanceGetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A { augment int get foo => 0; +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_mixin_instanceMethod() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A { augment void foo() {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_mixin_instanceMethod_augments_instanceMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin A { void foo() {} } @@ -832,29 +941,26 @@ augment mixin A { } test_mixin_instanceSetter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A { augment set foo(int _) {} +//^^^^^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } -''', - [error(diag.augmentationWithoutDeclaration, 32, 7)], - ); +'''); } test_topLevel_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment void foo() {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_topLevel_function_augments_function() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void foo() {} augment void foo(); @@ -862,90 +968,47 @@ augment void foo(); } test_topLevel_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment int get foo => 0; -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_topLevel_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment set foo(int _) {} -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_topLevel_variable_multiple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment int foo = 0, bar = 0; -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_topLevel_variable_multiple_oneMissing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int bar = 0; augment int foo = 1, bar = 2; -''', - [error(diag.augmentationWithoutDeclaration, 14, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_topLevel_variable_single() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' augment int foo = 0; -''', - [error(diag.augmentationWithoutDeclaration, 0, 7)], - ); +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +'''); } test_topLevel_variable_single_augments_variable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' int foo = 0; augment int foo = 1; '''); } - - Future _assertClassMemberAugmentationWithoutDeclaration({ - required String declaration, - required String augmentation, - bool conflictAtAugmentation = true, - bool expectConflict = true, - }) async { - var code = - ''' -class A { - $declaration -} -augment class A { - augment $augmentation -} -'''; - - await assertErrorsInCode(code, [ - if (expectConflict) - error( - diag.conflictingStaticAndInstance, - conflictAtAugmentation - ? code.lastIndexOf('foo') - : code.indexOf('foo'), - 3, - ), - error( - diag.augmentationWithoutDeclaration, - code.indexOf('augment $augmentation'), - 7, - ), - ]); - } } diff --git a/pkg/analyzer/test/src/diagnostics/await_in_late_local_variable_initializer_test.dart b/pkg/analyzer/test/src/diagnostics/await_in_late_local_variable_initializer_test.dart index 6fa02210b5a..b0e42b74957 100644 --- a/pkg/analyzer/test/src/diagnostics/await_in_late_local_variable_initializer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/await_in_late_local_variable_initializer_test.dart @@ -2,50 +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:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(AwaitInLateLocalVariableInitializerTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AwaitInLateLocalVariableInitializerTest extends PubPackageResolutionTest { - static const _errorCode = diag.awaitInLateLocalVariableInitializer; - test_closure_late_await() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' main() { var v = () async { late var v2 = await 42; +// ^^^^^ +// [diag.awaitInLateLocalVariableInitializer] The 'await' expression can't be used in a 'late' local variable's initializer. print(v2); }; print(v); } -''', - [error(_errorCode, 48, 5)], - ); +'''); } test_late_await() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' main() async { late var v = await 42; +// ^^^^^ +// [diag.awaitInLateLocalVariableInitializer] The 'await' expression can't be used in a 'late' local variable's initializer. print(v); } -''', - [error(_errorCode, 30, 5)], - ); +'''); } test_late_await_inClosure_blockBody() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' main() async { late var v = () async { await 42; @@ -56,7 +53,7 @@ main() async { } test_late_await_inClosure_expressionBody() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' main() async { late var v = () async => await 42; print(v); @@ -65,7 +62,7 @@ main() async { } test_no_await() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' main() async { late var v = 42; print(v); @@ -74,7 +71,7 @@ main() async { } test_not_late() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' main() async { var v = await 42; print(v); diff --git a/pkg/analyzer/test/src/diagnostics/await_in_wrong_context_test.dart b/pkg/analyzer/test/src/diagnostics/await_in_wrong_context_test.dart index a9d267b359e..1b93d2b9697 100644 --- a/pkg/analyzer/test/src/diagnostics/await_in_wrong_context_test.dart +++ b/pkg/analyzer/test/src/diagnostics/await_in_wrong_context_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(AwaitInWrongContextTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AwaitInWrongContextTest extends PubPackageResolutionTest { test_sync() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x) { return await x; +// ^^^^^ +// [diag.awaitInWrongContext] The await expression can only be used in an async function. } -''', - [error(diag.awaitInWrongContext, 16, 5)], - ); +'''); } test_syncStar() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x) sync* { yield await x; +// ^^^^^ +// [diag.awaitInWrongContext] The await expression can only be used in an async function. } -''', - [error(diag.awaitInWrongContext, 21, 5)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/await_of_incompatible_type_test.dart b/pkg/analyzer/test/src/diagnostics/await_of_incompatible_type_test.dart index dfe0fe3914b..7f4fc5a8b13 100644 --- a/pkg/analyzer/test/src/diagnostics/await_of_incompatible_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/await_of_incompatible_type_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(AwaitOfExtensionTypeNotFutureTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AwaitOfExtensionTypeNotFutureTest extends PubPackageResolutionTest { test_extensionType_implementsFuture() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(Future it) implements Future {} void f(A a) async { @@ -26,20 +27,19 @@ void f(A a) async { } test_extensionType_notImplementsFuture() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} void f(A a) async { await a; +//^^^^^ +// [diag.awaitOfIncompatibleType] The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'. } -''', - [error(diag.awaitOfIncompatibleType, 51, 5)], - ); +'''); } test_typeParameter_bound_extensionType_implementsFuture() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(Future it) implements Future {} void f(T a) async { @@ -49,20 +49,19 @@ void f(T a) async { } test_typeParameter_bound_extensionType_notImplementsFuture() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(Future it) {} void f(T a) async { await a; +//^^^^^ +// [diag.awaitOfIncompatibleType] The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'. } -''', - [error(diag.awaitOfIncompatibleType, 72, 5)], - ); +'''); } test_typeParameter_promotedBound_extensionType_implementsFuture() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(Future it) implements Future {} void f(T a) async { @@ -74,17 +73,16 @@ void f(T a) async { } test_typeParameter_promotedBound_extensionType_notImplementsFuture() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(Future it) {} void f(T a) async { if (a is A) { await a; +// ^^^^^ +// [diag.awaitOfIncompatibleType] The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'. } } -''', - [error(diag.awaitOfIncompatibleType, 80, 5)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/base_class_implemented_outside_of_library_test.dart b/pkg/analyzer/test/src/diagnostics/base_class_implemented_outside_of_library_test.dart index 65889ea306e..a897a4be691 100644 --- a/pkg/analyzer/test/src/diagnostics/base_class_implemented_outside_of_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/base_class_implemented_outside_of_library_test.dart @@ -7,10 +7,12 @@ 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(BaseClassImplementedOutsideOfLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -18,7 +20,7 @@ main() { class BaseClassImplementedOutsideOfLibraryTest extends PubPackageResolutionTest { test_class_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base class Foo {} base class Bar implements Foo {} '''); @@ -29,13 +31,12 @@ base class Bar implements Foo {} base class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base class Bar implements Foo {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 45, 3)], - ); +// ^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_class_outside_sealed() async { @@ -111,14 +112,13 @@ class C implements B {} base class A {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; base class B extends A {} base class C implements B {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 67, 1)], - ); +// ^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'A' can't be implemented outside of its library because it's a base class. +'''); } test_class_outside_viaTypedef_inside() async { @@ -127,13 +127,12 @@ base class Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base class Bar implements FooTypedef {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 45, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_class_outside_viaTypedef_outside() async { @@ -141,18 +140,17 @@ base class Bar implements FooTypedef {} base class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; base class Bar implements FooTypedef {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 71, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_classTypeAlias_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base class A {} sealed class B extends A {} mixin M {} @@ -195,7 +193,7 @@ base class C = Object with M implements B; } test_enum_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base class Foo {} enum Bar implements Foo { bar } '''); @@ -206,13 +204,12 @@ enum Bar implements Foo { bar } base class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; enum Bar implements Foo { bar } -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 39, 3)], - ); +// ^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_enum_outside_viaTypedef_inside() async { @@ -221,13 +218,12 @@ base class Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; enum Bar implements FooTypedef { bar } -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 39, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_enum_outside_viaTypedef_outside() async { @@ -235,18 +231,17 @@ enum Bar implements FooTypedef { bar } base class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; enum Bar implements FooTypedef { bar } -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 65, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_mixin_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base class Foo {} base mixin Bar implements Foo {} '''); @@ -257,13 +252,12 @@ base mixin Bar implements Foo {} base class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base mixin Bar implements Foo {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 45, 3)], - ); +// ^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_mixin_outside_viaTypedef_inside() async { @@ -272,13 +266,12 @@ base class Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base mixin Bar implements FooTypedef {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 45, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } test_mixin_outside_viaTypedef_outside() async { @@ -286,13 +279,12 @@ base mixin Bar implements FooTypedef {} base class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; base mixin Bar implements FooTypedef {} -''', - [error(diag.baseClassImplementedOutsideOfLibrary, 71, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/base_mixin_implemented_outside_of_library_test.dart b/pkg/analyzer/test/src/diagnostics/base_mixin_implemented_outside_of_library_test.dart index 580c4823527..05a8af1d760 100644 --- a/pkg/analyzer/test/src/diagnostics/base_mixin_implemented_outside_of_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/base_mixin_implemented_outside_of_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(BaseMixinImplementedOutsideOfLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +19,7 @@ main() { class BaseMixinImplementedOutsideOfLibraryTest extends PubPackageResolutionTest { test_class_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base mixin Foo {} base class Bar implements Foo {} '''); @@ -28,13 +30,12 @@ base class Bar implements Foo {} base mixin Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base class Bar implements Foo {} -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 45, 3)], - ); +// ^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_class_outside_viaExtends() async { @@ -66,13 +67,12 @@ base mixin Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base class Bar implements FooTypedef {} -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 45, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_class_outside_viaTypedef_outside() async { @@ -80,18 +80,17 @@ base class Bar implements FooTypedef {} base mixin Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; base class Bar implements FooTypedef {} -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 71, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_enum_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base mixin Foo {} enum Bar implements Foo { bar } '''); @@ -102,13 +101,12 @@ enum Bar implements Foo { bar } base mixin Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; enum Bar implements Foo { bar } -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 39, 3)], - ); +// ^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_enum_outside_viaTypedef_inside() async { @@ -117,13 +115,12 @@ base mixin Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; enum Bar implements FooTypedef { bar } -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 39, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_enum_outside_viaTypedef_outside() async { @@ -131,18 +128,17 @@ enum Bar implements FooTypedef { bar } base mixin Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; enum Bar implements FooTypedef { bar } -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 65, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_mixin_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' base mixin Foo {} base mixin Bar implements Foo {} '''); @@ -153,13 +149,12 @@ base mixin Bar implements Foo {} base mixin Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base mixin Bar implements Foo {} -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 45, 3)], - ); +// ^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_mixin_outside_viaTypedef_inside() async { @@ -168,13 +163,12 @@ base mixin Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base mixin Bar implements FooTypedef {} -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 45, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } test_mixin_outside_viaTypedef_outside() async { @@ -182,13 +176,12 @@ base mixin Bar implements FooTypedef {} base mixin Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; base mixin Bar implements FooTypedef {} -''', - [error(diag.baseMixinImplementedOutsideOfLibrary, 71, 10)], - ); +// ^^^^^^^^^^ +// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/binary_operator_written_out_test.dart b/pkg/analyzer/test/src/diagnostics/binary_operator_written_out_test.dart index 360f62d3505..08a0af06004 100644 --- a/pkg/analyzer/test/src/diagnostics/binary_operator_written_out_test.dart +++ b/pkg/analyzer/test/src/diagnostics/binary_operator_written_out_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(BinaryOperatorWrittenOutTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BinaryOperatorWrittenOutTest extends PubPackageResolutionTest { test_using_and() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x, y) { return x and y; +// ^^^ +// [diag.binaryOperatorWrittenOut] Binary operator 'and' is written as '&' instead of the written out word. } -''', - [error(diag.binaryOperatorWrittenOut, 21, 3)], - ); +'''); } test_using_and_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(x, y) { return x & y; } @@ -35,18 +35,17 @@ f(x, y) { } test_using_or() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x, y) { return x or y; +// ^^ +// [diag.binaryOperatorWrittenOut] Binary operator 'or' is written as '|' instead of the written out word. } -''', - [error(diag.binaryOperatorWrittenOut, 21, 2)], - ); +'''); } test_using_or_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(x, y) { return x | y; } @@ -54,18 +53,17 @@ f(x, y) { } test_using_shl() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x) { return x shl 2; +// ^^^ +// [diag.binaryOperatorWrittenOut] Binary operator 'shl' is written as '<<' instead of the written out word. } -''', - [error(diag.binaryOperatorWrittenOut, 18, 3)], - ); +'''); } test_using_shl_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(x) { return x << 2; } @@ -73,18 +71,17 @@ f(x) { } test_using_shr() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x) { return x shr 2; +// ^^^ +// [diag.binaryOperatorWrittenOut] Binary operator 'shr' is written as '>>' instead of the written out word. } -''', - [error(diag.binaryOperatorWrittenOut, 18, 3)], - ); +'''); } test_using_shr_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(x) { return x >> 2; } @@ -92,18 +89,17 @@ f(x) { } test_using_xor() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(x, y) { return x xor y; +// ^^^ +// [diag.binaryOperatorWrittenOut] Binary operator 'xor' is written as '^' instead of the written out word. } -''', - [error(diag.binaryOperatorWrittenOut, 21, 3)], - ); +'''); } test_using_xor_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(x, y) { return x ^ y; } diff --git a/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_catch_error_test.dart b/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_catch_error_test.dart index fc7f7c33418..6c7cb6aecc8 100644 --- a/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_catch_error_test.dart +++ b/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_catch_error_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(BodyMayCompleteNormallyCatchErrorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BodyMayCompleteNormallyCatchErrorTest extends PubPackageResolutionTest { test_alwaysReturn() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { return 7; @@ -26,7 +27,7 @@ void f(Future future) { } test_noReturn_futureOrVoidReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(Future> future) { future.catchError((e, st) {}); @@ -35,40 +36,37 @@ void f(Future> future) { } test_noReturn_namedBeforePositional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError(test: (_) => false, (e, st) {}); +// ^ +// [diag.bodyMightCompleteNormallyCatchError] This 'onError' handler must return a value assignable to 'int', but ends without returning a value. } -''', - [error(diag.bodyMightCompleteNormallyCatchError, 77, 1)], - ); +'''); } test_noReturn_nonNullableReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) {}); +// ^ +// [diag.bodyMightCompleteNormallyCatchError] This 'onError' handler must return a value assignable to 'int', but ends without returning a value. } -''', - [error(diag.bodyMightCompleteNormallyCatchError, 57, 1)], - ); +'''); } test_noReturn_nullableReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) {}); +// ^ +// [diag.bodyMightCompleteNormallyCatchError] This 'onError' handler must return a value assignable to 'int?', but ends without returning a value. } -''', - [error(diag.bodyMightCompleteNormallyCatchError, 58, 1)], - ); +'''); } test_noReturn_nullReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) {}); } @@ -76,7 +74,7 @@ void f(Future future) { } test_noReturn_voidReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) {}); } diff --git a/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_nullable_test.dart b/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_nullable_test.dart index eb1cf010836..561ea1f3013 100644 --- a/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_nullable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_nullable_test.dart @@ -2,45 +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(BodyMightCompleteNormallyNullableTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BodyMightCompleteNormallyNullableTest extends PubPackageResolutionTest { test_function_async_block_futureOrIntQuestion() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; FutureOr f(Future f) async {} -''', - [error(diag.bodyMightCompleteNormallyNullable, 36, 1)], - ); +// ^ +// [diag.bodyMightCompleteNormallyNullable] This function has a nullable return type of 'FutureOr', but ends without returning a value. +'''); } test_function_async_block_futureOrVoid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; FutureOr f(Future f) async {} '''); } test_function_async_block_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(Future f) async {} '''); } test_function_switchStatement_exhaustive_extensionType() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a, b } extension type EE(E it) {} @@ -57,22 +57,21 @@ int f(EE e) { } test_function_sync_block_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' dynamic f() {} '''); } test_function_sync_block_intQuestion() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int? f() {} -''', - [error(diag.bodyMightCompleteNormallyNullable, 5, 1)], - ); +// ^ +// [diag.bodyMightCompleteNormallyNullable] This function has a nullable return type of 'int?', but ends without returning a value. +'''); } test_function_sync_block_intQuestion_definiteReturn() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' int? f() { return null; } @@ -80,13 +79,13 @@ int? f() { } test_function_sync_block_Null() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' Null f() {} '''); } test_function_sync_block_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f() {} '''); } diff --git a/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_test.dart b/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_test.dart index 15ed41a38c3..82c59775076 100644 --- a/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_test.dart +++ b/pkg/analyzer/test/src/diagnostics/body_might_complete_normally_test.dart @@ -6,11 +6,13 @@ 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(BodyMayCompleteNormallyTest); defineReflectiveTests(BodyMayCompleteNormallyTest_Language219); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -32,7 +34,7 @@ mixin BodyMayCompleteNormallyTestCases on PubPackageResolutionTest { bool get _arePatternsEnabled; test_enum_method_nonNullable_blockBody_switchStatement_notNullable_exhaustive() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a; @@ -74,74 +76,69 @@ enum E { } test_factoryConstructor_named_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A.named() {} +// ^^^^^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'A', is a potentially non-nullable type. } -''', - [error(diag.bodyMightCompleteNormally, 20, 7)], - ); +'''); } test_factoryConstructor_unnamed_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() {} +// ^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'A', is a potentially non-nullable type. } -''', - [error(diag.bodyMightCompleteNormally, 20, 1)], - ); +'''); } test_function_future_int_blockBody_async() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' Future foo() async {} -''', - [error(diag.bodyMightCompleteNormally, 12, 3)], - ); +// ^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr', is a potentially non-nullable type. +'''); } test_function_future_void_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' Future foo() {} -''', - [error(diag.bodyMightCompleteNormally, 13, 3)], - ); +// ^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'Future', is a potentially non-nullable type. +'''); } test_function_future_void_blockBody_async() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Future foo() async {} '''); } test_function_nonNullable_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int foo() {} -''', - [error(diag.bodyMightCompleteNormally, 4, 3)], - ); +// ^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type. +'''); } test_function_nonNullable_blockBody_generator_async() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Stream foo() async* {} '''); } test_function_nonNullable_blockBody_generator_sync() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Iterable foo() sync* {} '''); } test_function_nonNullable_blockBody_switchStatement_notNullable_exhaustive() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum Foo { a, b } int f(Foo foo) { @@ -156,7 +153,7 @@ int f(Foo foo) { } test_function_nonNullable_blockBody_switchStatement_notNullable_exhaustive_enhanced() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { a; @@ -176,7 +173,7 @@ int f(E e) { test_function_nonNullable_blockBody_switchStatement_notNullable_exhaustive_parenthesis() async { // TODO(johnniwinther): Re-enable this test for the patterns feature. if (_arePatternsEnabled) return; - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum Foo { a, b } int f(Foo foo) { @@ -239,7 +236,7 @@ int f(E e) { } test_function_nonNullable_blockBody_switchStatement_nullable_exhaustive_default() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum Foo { a, b } int f(Foo? foo) { @@ -256,7 +253,7 @@ int f(Foo? foo) { } test_function_nonNullable_blockBody_switchStatement_nullable_exhaustive_null() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum Foo { a, b } int f(Foo? foo) { @@ -297,7 +294,7 @@ int f(Foo? foo) { } test_function_nullable_blockBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' int foo() { return 0; } @@ -305,31 +302,29 @@ int foo() { } test_functionExpression_future_int_blockBody_async() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { Future Function() foo = () async {}; +// ^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr', is a potentially non-nullable type. foo; } -''', - [error(diag.bodyMightCompleteNormally, 51, 1)], - ); +'''); } test_functionExpression_future_void_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { Future Function() foo = () {}; +// ^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'Future', is a potentially non-nullable type. foo; } -''', - [error(diag.bodyMightCompleteNormally, 46, 1)], - ); +'''); } test_functionExpression_future_void_blockBody_async() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' main() { Future Function() foo = () async {}; foo; @@ -338,20 +333,19 @@ main() { } test_functionExpression_notNullable_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int Function() foo = () { +// ^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type. }; foo; } -''', - [error(diag.bodyMightCompleteNormally, 37, 1)], - ); +'''); } test_functionExpression_notNullable_blockBody_return() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' main() { int Function() foo = () { return 0; @@ -362,7 +356,7 @@ main() { } test_generativeConstructor_blockBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() {} } @@ -370,7 +364,7 @@ class A { } test_generativeConstructor_emptyBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(); } @@ -378,29 +372,27 @@ class A { } test_method_future_int_blockBody_async() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { Future foo() async {} +// ^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr', is a potentially non-nullable type. } -''', - [error(diag.bodyMightCompleteNormally, 24, 3)], - ); +'''); } test_method_future_void_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { Future foo() {} +// ^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'Future', is a potentially non-nullable type. } -''', - [error(diag.bodyMightCompleteNormally, 25, 3)], - ); +'''); } test_method_future_void_blockBody_async() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { Future foo() async {} } @@ -408,18 +400,17 @@ class A { } test_method_nonNullable_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo() {} +// ^^^ +// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type. } -''', - [error(diag.bodyMightCompleteNormally, 16, 3)], - ); +'''); } test_method_nonNullable_blockBody_generator_async() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { Stream foo() async* { yield 0; @@ -429,7 +420,7 @@ class A { } test_method_nonNullable_blockBody_generator_sync() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { Iterable foo() sync* { yield 0; @@ -439,7 +430,7 @@ class A { } test_method_nonNullable_blockBody_return() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo() { return 0; @@ -449,7 +440,7 @@ class A { } test_method_nonNullable_blockBody_throw() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo() { throw 0; @@ -459,7 +450,7 @@ class A { } test_method_nonNullable_emptyBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { int foo(); } @@ -467,7 +458,7 @@ abstract class A { } test_method_nonNullable_expressionBody() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo() => 0; } @@ -475,7 +466,7 @@ class A { } test_method_nonNullable_expressionBody_throw() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int foo() => throw 0; } @@ -483,7 +474,7 @@ class A { } test_method_nullable_blockBody_return() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? foo() { return 0; @@ -496,11 +487,9 @@ class A { // Even though this code has an illegal return type for a setter, do not // use the invalid return type to report BODY_MIGHT_COMPLETE_NORMALLY for // setters. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool set s(int value) {} -''', - [error(diag.nonVoidReturnForSetter, 0, 4)], - ); +// [diag.nonVoidReturnForSetter][column 1][length 4] The return type of the setter must be 'void' or absent. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/break_label_on_switch_member_test.dart b/pkg/analyzer/test/src/diagnostics/break_label_on_switch_member_test.dart index fbefbe51347..b516252f625 100644 --- a/pkg/analyzer/test/src/diagnostics/break_label_on_switch_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/break_label_on_switch_member_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(BreakLabelOnSwitchMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BreakLabelOnSwitchMemberTest extends PubPackageResolutionTest { test_it() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { switch (x) { L: case 0: break; case 1: break L; +// ^ +// [diag.breakLabelOnSwitchMember] A break label resolves to the 'case' or 'default' statement. } } -''', - [error(diag.breakLabelOnSwitchMember, 83, 1)], - ); +'''); } test_it_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(int x) { switch (x) { @@ -41,10 +40,10 @@ void f(int x) { break; case 1: break L; +// ^ +// [diag.breakLabelOnSwitchMember] A break label resolves to the 'case' or 'default' statement. } } -''', - [error(diag.breakLabelOnSwitchMember, 99, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart index 0ec9ef4ad66..bb7d278890b 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart @@ -2,64 +2,61 @@ // 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(BuiltInIdentifierAsExtensionNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BuiltInIdentifierAsExtensionNameTest extends PubPackageResolutionTest { test_as() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension as on Object {} -''', - [error(diag.builtInIdentifierAsExtensionName, 10, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'as' can't be used as an extension name. +'''); } test_Function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension Function on Object {} -''', - [error(diag.builtInIdentifierAsExtensionName, 10, 8)], - ); +// ^^^^^^^^ +// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'Function' can't be used as an extension name. +'''); } test_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension inout on Object {} -''', - [error(diag.builtInIdentifierAsExtensionName, 10, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'inout' can't be used as an extension name. +'''); } test_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 extension inout on Object {} '''); } test_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension out on Object {} -''', - [error(diag.builtInIdentifierAsExtensionName, 10, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'out' can't be used as an extension name. +'''); } test_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 extension out on Object {} '''); diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart index 9ad2d52658c..0f3a1844a16 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_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(BuiltInIdentifierAsExtensionTypeNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,50 +18,46 @@ main() { class BuiltInIdentifierAsExtensionTypeNameTest extends PubPackageResolutionTest { test_as() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type as(int it) {} -''', - [error(diag.builtInIdentifierAsExtensionTypeName, 15, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'as' can't be used as an extension type name. +'''); } test_Function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type Function(int it) {} -''', - [error(diag.builtInIdentifierAsExtensionTypeName, 15, 8)], - ); +// ^^^^^^^^ +// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'Function' can't be used as an extension type name. +'''); } test_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension type inout(int it) {} -''', - [error(diag.builtInIdentifierAsExtensionTypeName, 15, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'inout' can't be used as an extension type name. +'''); } test_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 extension type inout(int it) {} '''); } test_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension type out(int it) {} -''', - [error(diag.builtInIdentifierAsExtensionTypeName, 15, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'out' can't be used as an extension type name. +'''); } test_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 extension type out(int it) {} '''); diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart index 577cdb24698..ab07d1b57a8 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart @@ -2,84 +2,75 @@ // 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(BuiltInIdentifierAsPrefixNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BuiltInIdentifierAsPrefixNameTest extends PubPackageResolutionTest { test_abstract() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as abstract; -''', - [ - error(diag.unusedImport, 7, 12), - error(diag.builtInIdentifierAsPrefixName, 23, 8), - ], - ); +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. +// ^^^^^^^^ +// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'abstract' can't be used as a prefix name. +'''); } test_Function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as Function; -''', - [ - error(diag.unusedImport, 7, 12), - error(diag.builtInIdentifierAsPrefixName, 23, 8), - ], - ); +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. +// ^^^^^^^^ +// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'Function' can't be used as a prefix name. +'''); } test_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as inout; -''', - [ - error(diag.unusedImport, 7, 12), - error(diag.builtInIdentifierAsPrefixName, 23, 5), - ], - ); +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. +// ^^^^^ +// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'inout' can't be used as a prefix name. +'''); } test_inout_language310() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 import 'dart:async' as inout; -''', - [error(diag.unusedImport, 23, 12)], - ); +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. +'''); } test_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async' as out; -''', - [ - error(diag.unusedImport, 7, 12), - error(diag.builtInIdentifierAsPrefixName, 23, 3), - ], - ); +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. +// ^^^ +// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'out' can't be used as a prefix name. +'''); } test_out_language310() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 import 'dart:async' as out; -''', - [error(diag.unusedImport, 23, 12)], - ); +// ^^^^^^^^^^^^ +// [diag.unusedImport] Unused import: 'dart:async'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart index 836d94b0de8..17ddf8cc490 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart @@ -2,148 +2,139 @@ // 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(BuiltInIdentifierAsTypeNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BuiltInIdentifierAsTypeNameTest extends PubPackageResolutionTest { test_class_as() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class as {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'as' can't be used as a type name. +'''); } test_class_Function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class Function {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 8)], - ); +// ^^^^^^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'Function' can't be used as a type name. +'''); } test_class_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class inout {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name. +'''); } test_class_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 class inout {} '''); } test_class_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class out {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name. +'''); } test_class_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 class out {} '''); } test_enum_as() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' enum as { +// ^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'as' can't be used as a type name. v } -''', - [error(diag.builtInIdentifierAsTypeName, 5, 2)], - ); +'''); } test_enum_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' enum inout {v} -''', - [error(diag.builtInIdentifierAsTypeName, 5, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name. +'''); } test_enum_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 enum inout {v} '''); } test_enum_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' enum out {v} -''', - [error(diag.builtInIdentifierAsTypeName, 5, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name. +'''); } test_enum_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 enum out {v} '''); } test_mixin_as() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin as {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'as' can't be used as a type name. +'''); } test_mixin_Function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin Function {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 8)], - ); +// ^^^^^^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'Function' can't be used as a type name. +'''); } test_mixin_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin inout {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name. +'''); } test_mixin_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 mixin inout {} '''); } test_mixin_OK_on() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin on on A {} @@ -159,16 +150,15 @@ class D = Object with M2; } test_mixin_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin out {} -''', - [error(diag.builtInIdentifierAsTypeName, 6, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name. +'''); } test_mixin_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 mixin out {} '''); diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart index 5ba5035b278..c2d3d7e13b3 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_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(BuiltInIdentifierAsTypeParameterNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,106 +18,96 @@ main() { class BuiltInIdentifierAsTypeParameterNameTest extends PubPackageResolutionTest { test_class_as() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 8, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name. +'''); } test_class_Function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 8, 8)], - ); +// ^^^^^^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'Function' can't be used as a type parameter name. +'''); } test_class_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 8, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name. +'''); } test_class_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 class A {} '''); } test_class_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 8, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name. +'''); } test_class_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 class A {} '''); } test_extension_as() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension on List {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 11, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name. +'''); } test_extension_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension on List {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 11, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name. +'''); } test_extension_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension on List {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 11, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name. +'''); } test_function_as() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 7, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name. +'''); } test_function_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 7, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name. +'''); } test_function_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() {} -''', - [error(diag.builtInIdentifierAsTypeParameterName, 7, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart index c617d1ce8c4..a6a98aa8880 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_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(BuiltInIdentifierAsTypedefNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class BuiltInIdentifierAsTypedefNameTest extends PubPackageResolutionTest { test_classTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin B {} class as = A with B; -''', - [error(diag.builtInIdentifierAsTypedefName, 28, 2)], - ); +// ^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name. +'''); } test_classTypeAlias_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin B {} class inout = A with B; -''', - [error(diag.builtInIdentifierAsTypedefName, 28, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name. +'''); } test_classTypeAlias_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 class A {} mixin B {} @@ -47,18 +46,17 @@ class inout = A with B; } test_classTypeAlias_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin B {} class out = A with B; -''', - [error(diag.builtInIdentifierAsTypedefName, 28, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name. +'''); } test_classTypeAlias_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 class A {} mixin B {} @@ -67,126 +65,107 @@ class out = A with B; } test_typedef_classic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef void as(); -''', - [ - error(diag.expectedIdentifierButGotKeyword, 13, 2), - error(diag.builtInIdentifierAsTypedefName, 13, 2), - ], - ); +// ^^ +// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword. +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name. +'''); } test_typedef_classic_as() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef void as(); -''', - [ - error(diag.expectedIdentifierButGotKeyword, 13, 2), - error(diag.builtInIdentifierAsTypedefName, 13, 2), - ], - ); +// ^^ +// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword. +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name. +'''); } test_typedef_classic_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef void inout(); -''', - [error(diag.builtInIdentifierAsTypedefName, 13, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name. +'''); } test_typedef_classic_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 typedef void inout(); '''); } test_typedef_classic_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef void out(); -''', - [error(diag.builtInIdentifierAsTypedefName, 13, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name. +'''); } test_typedef_classic_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 typedef void out(); '''); } test_typedef_generic_as() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef as = void Function(); -''', - [ - error(diag.builtInIdentifierAsTypedefName, 8, 2), - error(diag.expectedIdentifierButGotKeyword, 8, 2), - ], - ); +// ^^ +// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword. +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name. +'''); } test_typedef_generic_inout() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef inout = void Function(); -''', - [error(diag.builtInIdentifierAsTypedefName, 8, 5)], - ); +// ^^^^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name. +'''); } test_typedef_generic_inout_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 typedef inout = void Function(); '''); } test_typedef_generic_out() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef out = void Function(); -''', - [error(diag.builtInIdentifierAsTypedefName, 8, 3)], - ); +// ^^^ +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name. +'''); } test_typedef_generic_out_language310() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.10 typedef out = void Function(); '''); } test_typedef_interfaceType_as() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef as = List; -''', - [ - error(diag.builtInIdentifierAsTypedefName, 8, 2), - error(diag.expectedIdentifierButGotKeyword, 8, 2), - ], - ); +// ^^ +// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword. +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name. +'''); } test_typedef_interfaceType_Function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef Function = List; -''', - [ - error(diag.builtInIdentifierAsTypedefName, 8, 8), - error(diag.expectedIdentifierButGotKeyword, 8, 8), - ], - ); +// ^^^^^^^^ +// [diag.expectedIdentifierButGotKeyword] 'Function' can't be used as an identifier because it's a keyword. +// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'Function' can't be used as a typedef name. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart index fcba439f6b1..cc64cea20e9 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart @@ -7,6 +7,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../../generated/test_support.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { @@ -17,28 +18,23 @@ main() { defineReflectiveTests(DuplicateDefinitionExtensionTypeTest); defineReflectiveTests(DuplicateDefinitionMixinTest); defineReflectiveTests(DuplicateDefinitionUnitTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class DuplicateDefinitionClassTest extends PubPackageResolutionTest { test_instance_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 31, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -67,29 +63,20 @@ class A { } test_instance_field_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. +// [context 2] The first definition of this name. int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 2] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 31, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - error( - diag.duplicateDefinition, - 46, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -125,64 +112,46 @@ class A { } test_instance_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 35, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 32, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 41, - 3, - contextMessages: [message(testFile, 22, 3)], - ), - ], - ); +'''); } test_instance_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { final int foo = 0; set foo(int x) {} @@ -191,7 +160,7 @@ class C { } test_instance_fieldLateFinalInitializer_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { late final int foo = 1; set foo(_) {} @@ -200,46 +169,34 @@ class C { } test_instance_fieldLateFinalNoInitializer_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { late final int foo; +// ^^^ +// [context 1] The first definition of this name. set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 38, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_instance_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 40, - 3, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_getter_getter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { int get foo => 0; } @@ -252,8 +209,7 @@ augment class C { @SkippedTest() // TODO(scheglov): implement augmentation test_instance_getter_getter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int get foo => 0; } @@ -261,59 +217,38 @@ class C { augment class C { int get foo => 0; } -''', - [ - error( - diag.duplicateDefinition, - 61, - 3, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } test_instance_getter_getter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? get b => null; +// ^ +// [context 1] The first definition of this name. int? get b => 0; +// ^ +// [diag.duplicateDefinition][context 1] The name 'b' is already defined. void set b(int? value) {} } -''', - [ - error( - diag.duplicateDefinition, - 43, - 1, - contextMessages: [message(testFile, 21, 1)], - ), - ], - ); +'''); } test_instance_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 37, - 3, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } test_instance_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { int get foo => 0; set foo(_) {} @@ -322,86 +257,62 @@ class C { } test_instance_getter_setter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? get b => null; +// ^ +// [context 1] The first definition of this name. void set b(int? value) {} int? get b => 0; +// ^ +// [diag.duplicateDefinition][context 1] The name 'b' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 71, - 1, - contextMessages: [message(testFile, 21, 1)], - ), - ], - ); +'''); } test_instance_getter_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? get b => null; void set b(int? value) {} +// ^ +// [context 1] The first definition of this name. void set b(int? value) {} +// ^ +// [diag.duplicateDefinition][context 1] The name 'b' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 71, - 1, - contextMessages: [message(testFile, 43, 1)], - ), - ], - ); +'''); } test_instance_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { void foo() {} +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 36, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_instance_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { void foo() {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 33, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_method_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -414,8 +325,7 @@ augment class A { @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -423,41 +333,25 @@ class A { augment class A { void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 54, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_instance_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { void foo() {} +// ^^^ +// [context 1] The first definition of this name. set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 32, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -465,21 +359,12 @@ class A { augment class A { set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 53, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_operator_operator_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +(int _) => 0; } @@ -492,8 +377,7 @@ augment class A { @SkippedTest() // TODO(scheglov): implement augmentation test_instance_operator_operator_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +(int _) => 0; } @@ -501,56 +385,35 @@ class A { augment class A { int operator +(int _) => 0; } -''', - [ - error( - diag.duplicateDefinition, - 76, - 1, - contextMessages: [message(testFile, 25, 1)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredNamed_final_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C({required final int foo}) { +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 43, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredPositional_final_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C(final int foo) { +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 32, - 3, - contextMessages: [message(testFile, 18, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredPositional_final_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C(final int foo) { set foo(int x) {} } @@ -558,7 +421,7 @@ class C(final int foo) { } test_instance_primaryConstructor_requiredPositional_notDeclaring_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C(int foo) { int get foo => 0; set foo(int x) {} @@ -567,52 +430,39 @@ class C(int foo) { } test_instance_primaryConstructor_requiredPositional_var_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C(var int foo) { +// ^^^ +// [context 1] The first definition of this name. set foo(int x) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 29, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredPositional_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(var int _); -''', - [error(diag.unusedFieldFromPrimaryConstructor, 16, 1)], - ); +// ^ +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. +'''); } test_instance_primaryConstructor_requiredPositional_wildcard_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(var int _, var int _); -''', - [ - error(diag.unusedFieldFromPrimaryConstructor, 16, 1), - error( - diag.duplicateDefinition, - 27, - 1, - contextMessages: [message(testFile, 16, 1)], - ), - error(diag.unusedFieldFromPrimaryConstructor, 27, 1), - ], - ); +// ^ +// [context 1] The first definition of this name. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. +'''); } test_instance_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { set foo(_) {} int get foo => 0; @@ -621,68 +471,49 @@ class C { } test_instance_setter_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void set b(int? value) {} int? get b => null; +// ^ +// [context 1] The first definition of this name. int? get b => 0; +// ^ +// [diag.duplicateDefinition][context 1] The name 'b' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 71, - 1, - contextMessages: [message(testFile, 49, 1)], - ), - ], - ); +'''); } test_instance_setter_getter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void set b(int? value) {} +// ^ +// [context 1] The first definition of this name. int? get b => null; void set b(int? value) {} +// ^ +// [diag.duplicateDefinition][context 1] The name 'b' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 71, - 1, - contextMessages: [message(testFile, 21, 1)], - ), - ], - ); +'''); } test_instance_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 33, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { set foo(_) {} } @@ -690,40 +521,25 @@ class A { augment class A { void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 54, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 42, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_setter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { void set foo(_) {} } @@ -735,29 +551,22 @@ augment class C { } test_instance_setter_setter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void set b(int? value) {} +// ^ +// [context 1] The first definition of this name. void set b(int? value) {} +// ^ +// [diag.duplicateDefinition][context 1] The name 'b' is already defined. int? get b => null; } -''', - [ - error( - diag.duplicateDefinition, - 49, - 1, - contextMessages: [message(testFile, 21, 1)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { void set foo(_) {} } @@ -765,96 +574,63 @@ class C { augment class C { void set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 63, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } test_static_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 45, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 49, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 46, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 55, - 3, - contextMessages: [message(testFile, 29, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { static final int foo = 0; static set foo(int x) {} @@ -863,7 +639,7 @@ class C { } test_static_fieldLateFinalInitializer_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { static late final int foo = 0; static set foo(int x) {} @@ -872,46 +648,34 @@ class C { } test_static_fieldLateFinalNoInitializer_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static late final int foo; +// ^^^ +// [context 1] The first definition of this name. static set foo(int x) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 52, - 3, - contextMessages: [message(testFile, 34, 3)], - ), - ], - ); +'''); } test_static_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 54, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_getter_getter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get foo => 0; } @@ -924,8 +688,7 @@ augment class A { @SkippedTest() // TODO(scheglov): implement augmentation test_static_getter_getter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get foo => 0; } @@ -933,39 +696,24 @@ class A { augment class A { static int get foo => 0; } -''', - [ - error( - diag.duplicateDefinition, - 75, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 51, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { static int get foo => 0; static set foo(_) {} @@ -974,46 +722,34 @@ class C { } test_static_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 50, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_static_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 47, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_method_method_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} } @@ -1026,8 +762,7 @@ augment class A { @SkippedTest() // TODO(scheglov): implement augmentation test_static_method_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo() {} } @@ -1035,39 +770,24 @@ class A { augment class A { static void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 68, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_static_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 46, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_static_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { static set foo(_) {} static int get foo => 0; @@ -1076,46 +796,34 @@ class C { } test_static_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 47, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { static void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 56, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_setter_setter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void set foo(_) {} } @@ -1128,8 +836,7 @@ augment class A { @SkippedTest() // TODO(scheglov): implement augmentation test_static_setter_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void set foo(_) {} } @@ -1137,121 +844,82 @@ class A { augment class A { static void set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 77, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } } @reflectiveTest class DuplicateDefinitionEnumTest extends PubPackageResolutionTest { test_constant() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { foo, foo +//^^^ +// [context 1] The first definition of this name. +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 16, - 3, - contextMessages: [message(testFile, 11, 3)], - ), - ], - ); +'''); } test_instance_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. final int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 47, - 3, - contextMessages: [message(testFile, 26, 3)], - ), - ], - ); +'''); } test_instance_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 45, - 3, - contextMessages: [message(testFile, 26, 3)], - ), - ], - ); +'''); } test_instance_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 42, - 3, - contextMessages: [message(testFile, 26, 3)], - ), - ], - ); +'''); } test_instance_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 45, - 3, - contextMessages: [message(testFile, 26, 3)], - ), - ], - ); +'''); } test_instance_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; final int foo = 0; @@ -1261,28 +929,22 @@ enum E { } test_instance_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 44, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_getter_getter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int get foo => 0; @@ -1296,8 +958,7 @@ augment enum E {; @SkippedTest() // TODO(scheglov): implement augmentation test_instance_getter_getter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int get foo => 0; @@ -1306,40 +967,25 @@ enum E { augment enum E {; int get foo => 0; } -''', - [ - error( - diag.duplicateDefinition, - 65, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_instance_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 41, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_instance_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; int get foo => 0; @@ -1349,48 +995,36 @@ enum E { } test_instance_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void foo() {} +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 40, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } test_instance_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void foo() {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 37, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_method_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void foo() {} @@ -1404,8 +1038,7 @@ augment enum E {; @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void foo() {} @@ -1414,78 +1047,51 @@ enum E { augment enum E {; void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 58, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } test_instance_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void foo() {} +// ^^^ +// [context 1] The first definition of this name. set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 36, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredNamed_final_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E({required final int foo}) { +// ^^^ +// [context 1] The first definition of this name. v(foo: 0); void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 55, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredPositional_final_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(final int foo) { +// ^^^ +// [context 1] The first definition of this name. v(0); void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 39, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredPositional_final_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E(final int foo) { v(0); set foo(int x) {} @@ -1494,7 +1100,7 @@ enum E(final int foo) { } test_instance_primaryConstructor_requiredPositional_notDeclaring_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E(int foo) { v(0); int get foo => 0; @@ -1504,58 +1110,45 @@ enum E(int foo) { } test_instance_primaryConstructor_requiredPositional_var_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(var int foo) { +// ^^^ +// [context 1] The first definition of this name. +// [diag.nonFinalFieldInEnum] Enums can only declare final fields. v(0); set foo(int x) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error(diag.nonFinalFieldInEnum, 15, 3), - error( - diag.duplicateDefinition, - 36, - 3, - contextMessages: [message(testFile, 15, 3)], - ), - ], - ); +'''); } test_instance_primaryConstructor_requiredPositional_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(final int _) { +// ^ +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. v(0); } -''', - [error(diag.unusedFieldFromPrimaryConstructor, 17, 1)], - ); +'''); } test_instance_primaryConstructor_requiredPositional_wildcard_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E(final int _, final int _) { +// ^ +// [context 1] The first definition of this name. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +// [diag.unusedFieldFromPrimaryConstructor] The value of the field '_' isn't used. v(0, 0); } -''', - [ - error(diag.unusedFieldFromPrimaryConstructor, 17, 1), - error( - diag.duplicateDefinition, - 30, - 1, - contextMessages: [message(testFile, 17, 1)], - ), - error(diag.unusedFieldFromPrimaryConstructor, 30, 1), - ], - ); +'''); } test_instance_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; set foo(_) {} @@ -1565,48 +1158,36 @@ enum E { } test_instance_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 37, - 3, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } test_instance_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 46, - 3, - contextMessages: [message(testFile, 25, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_setter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void set foo(_) {} @@ -1620,8 +1201,7 @@ augment enum E {; @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; void set foo(_) {} @@ -1630,77 +1210,50 @@ enum E { augment enum E {; void set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 67, - 3, - contextMessages: [message(testFile, 25, 3)], - ), - ], - ); +'''); } test_static_constant_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { foo; +//^^^ +// [context 1] The first definition of this name. static int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 29, - 3, - contextMessages: [message(testFile, 11, 3)], - ), - ], - ); +'''); } test_static_constant_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { foo; +//^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 33, - 3, - contextMessages: [message(testFile, 11, 3)], - ), - ], - ); +'''); } test_static_constant_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { foo; +//^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 30, - 3, - contextMessages: [message(testFile, 11, 3)], - ), - ], - ); +'''); } test_static_constant_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { foo; static set foo(_) {} @@ -1709,87 +1262,63 @@ enum E { } test_static_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 49, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 53, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 50, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 59, - 3, - contextMessages: [message(testFile, 33, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static final int foo = 0; @@ -1799,28 +1328,22 @@ enum E { } test_static_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 58, - 3, - contextMessages: [message(testFile, 31, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_getter_getter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int get foo => 0; @@ -1834,8 +1357,7 @@ augment enum E {; @SkippedTest() // TODO(scheglov): implement augmentation test_static_getter_getter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int get foo => 0; @@ -1844,40 +1366,25 @@ enum E { augment enum E {; static int get foo => 0; } -''', - [ - error( - diag.duplicateDefinition, - 79, - 3, - contextMessages: [message(testFile, 31, 3)], - ), - ], - ); +'''); } test_static_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 55, - 3, - contextMessages: [message(testFile, 31, 3)], - ), - ], - ); +'''); } test_static_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static int get foo => 0; @@ -1887,48 +1394,36 @@ enum E { } test_static_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 54, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } test_static_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 51, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_method_method_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void foo() {} @@ -1942,8 +1437,7 @@ augment enum E {; @SkippedTest() // TODO(scheglov): implement augmentation test_static_method_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void foo() {} @@ -1952,40 +1446,25 @@ enum E { augment enum E {; static void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 72, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } test_static_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 50, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } test_static_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static set foo(_) {} @@ -1995,48 +1474,36 @@ enum E { } test_static_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 51, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 60, - 3, - contextMessages: [message(testFile, 32, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_setter_setter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void set foo(_) {} @@ -2050,8 +1517,7 @@ augment enum E {; @SkippedTest() // TODO(scheglov): implement augmentation test_static_setter_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static void set foo(_) {} @@ -2060,23 +1526,14 @@ enum E { augment enum E {; static void set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 81, - 3, - contextMessages: [message(testFile, 32, 3)], - ), - ], - ); +'''); } } @reflectiveTest class DuplicateDefinitionExtensionTest extends PubPackageResolutionTest { test_extendedType_instance() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { int get foo => 0; set foo(_) {} @@ -2092,7 +1549,7 @@ extension E on A { } test_extendedType_static() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { static int get foo => 0; static set foo(_) {} @@ -2108,28 +1565,22 @@ extension E on A { } test_instance_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 60, - 3, - contextMessages: [message(testFile, 40, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_getter_getter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { int get foo => 0; } @@ -2142,8 +1593,7 @@ augment extension E { @SkippedTest() // TODO(scheglov): implement augmentation test_instance_getter_getter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { int get foo => 0; } @@ -2151,40 +1601,25 @@ extension E on int { augment extension E { int get foo => 0; } -''', - [ - error( - diag.duplicateDefinition, - 76, - 3, - contextMessages: [message(testFile, 31, 3)], - ), - ], - ); +'''); } test_instance_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 57, - 3, - contextMessages: [message(testFile, 40, 3)], - ), - ], - ); +'''); } test_instance_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { int get foo => 0; @@ -2194,48 +1629,36 @@ extension E on A { } test_instance_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { void foo() {} +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 56, - 3, - contextMessages: [message(testFile, 37, 3)], - ), - ], - ); +'''); } test_instance_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { void foo() {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 53, - 3, - contextMessages: [message(testFile, 37, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_method_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void foo() {} } @@ -2248,8 +1671,7 @@ augment extension E { @SkippedTest() // TODO(scheglov): implement augmentation test_instance_method_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void foo() {} } @@ -2257,40 +1679,25 @@ extension E on int { augment extension E { void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 69, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } test_instance_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { void foo() {} +// ^^^ +// [context 1] The first definition of this name. set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 52, - 3, - contextMessages: [message(testFile, 37, 3)], - ), - ], - ); +'''); } test_instance_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { set foo(_) {} @@ -2300,48 +1707,36 @@ extension E on A { } test_instance_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 53, - 3, - contextMessages: [message(testFile, 36, 3)], - ), - ], - ); +'''); } test_instance_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 62, - 3, - contextMessages: [message(testFile, 41, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_setter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void set foo(_) {} } @@ -2354,8 +1749,7 @@ augment extension E { @SkippedTest() // TODO(scheglov): implement augmentation test_instance_setter_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void set foo(_) {} } @@ -2363,100 +1757,67 @@ extension E on int { augment extension E { void set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 78, - 3, - contextMessages: [message(testFile, 32, 3)], - ), - ], - ); +'''); } test_static_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 65, - 3, - contextMessages: [message(testFile, 43, 3)], - ), - ], - ); +'''); } test_static_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 69, - 3, - contextMessages: [message(testFile, 43, 3)], - ), - ], - ); +'''); } test_static_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 66, - 3, - contextMessages: [message(testFile, 43, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 75, - 3, - contextMessages: [message(testFile, 49, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static final int foo = 0; @@ -2466,28 +1827,22 @@ extension E on A { } test_static_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 74, - 3, - contextMessages: [message(testFile, 47, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_getter_getter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static int get foo => 0; } @@ -2500,8 +1855,7 @@ augment extension E { @SkippedTest() // TODO(scheglov): implement augmentation test_static_getter_getter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static int get foo => 0; } @@ -2509,40 +1863,25 @@ extension E on int { augment extension E { static int get foo => 0; } -''', - [ - error( - diag.duplicateDefinition, - 90, - 3, - contextMessages: [message(testFile, 38, 3)], - ), - ], - ); +'''); } test_static_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 71, - 3, - contextMessages: [message(testFile, 47, 3)], - ), - ], - ); +'''); } test_static_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static int get foo => 0; @@ -2552,48 +1891,36 @@ extension E on A { } test_static_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 70, - 3, - contextMessages: [message(testFile, 44, 3)], - ), - ], - ); +'''); } test_static_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 67, - 3, - contextMessages: [message(testFile, 44, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_method_method_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static void foo() {} } @@ -2606,8 +1933,7 @@ augment extension E { @SkippedTest() // TODO(scheglov): implement augmentation test_static_method_method_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static void foo() {} } @@ -2615,40 +1941,25 @@ extension E on int { augment extension E { static void foo() {} } -''', - [ - error( - diag.duplicateDefinition, - 83, - 3, - contextMessages: [message(testFile, 35, 3)], - ), - ], - ); +'''); } test_static_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 66, - 3, - contextMessages: [message(testFile, 44, 3)], - ), - ], - ); +'''); } test_static_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static set foo(_) {} static int get foo => 0; @@ -2657,48 +1968,36 @@ mixin M { } test_static_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 67, - 3, - contextMessages: [message(testFile, 43, 3)], - ), - ], - ); +'''); } test_static_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { static void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 76, - 3, - contextMessages: [message(testFile, 48, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_static_setter_setter_augment() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static void set foo(_) {} } @@ -2711,8 +2010,7 @@ augment extension E { @SkippedTest() // TODO(scheglov): implement augmentation test_static_setter_setter_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static void set foo(_) {} } @@ -2720,79 +2018,52 @@ extension E on int { augment extension E { static void set foo(_) {} } -''', - [ - error( - diag.duplicateDefinition, - 92, - 3, - contextMessages: [message(testFile, 39, 3)], - ), - ], - ); +'''); } test_unitMembers_extension() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} extension E on A {} +// ^ +// [context 1] The first definition of this name. extension E on A {} -''', - [ - error( - diag.duplicateDefinition, - 41, - 1, - contextMessages: [message(testFile, 21, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'E' is already defined. +'''); } } @reflectiveTest class DuplicateDefinitionExtensionTypeTest extends PubPackageResolutionTest { test_instance_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 57, - 3, - contextMessages: [message(testFile, 37, 3)], - ), - ], - ); +'''); } test_instance_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 54, - 3, - contextMessages: [message(testFile, 37, 3)], - ), - ], - ); +'''); } test_instance_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { int get foo => 0; set foo(_) {} @@ -2801,100 +2072,70 @@ extension type E(int it) { } test_instance_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { void foo() {} +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 53, - 3, - contextMessages: [message(testFile, 34, 3)], - ), - ], - ); +'''); } test_instance_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { void foo() {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 50, - 3, - contextMessages: [message(testFile, 34, 3)], - ), - ], - ); +'''); } test_instance_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { void foo() {} +// ^^^ +// [context 1] The first definition of this name. set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 49, - 3, - contextMessages: [message(testFile, 34, 3)], - ), - ], - ); +'''); } test_instance_representation_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { +// ^^ +// [context 1] The first definition of this name. int get it => 0; +// ^^ +// [diag.duplicateDefinition][context 1] The name 'it' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 37, - 2, - contextMessages: [message(testFile, 21, 2)], - ), - ], - ); +'''); } test_instance_representation_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { +// ^^ +// [context 1] The first definition of this name. void it() {} +// ^^ +// [diag.duplicateDefinition][context 1] The name 'it' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 34, - 2, - contextMessages: [message(testFile, 21, 2)], - ), - ], - ); +'''); } test_instance_representation_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { set it(int _) {} } @@ -2902,7 +2143,7 @@ extension type E(int it) { } test_instance_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { set foo(_) {} int get foo => 0; @@ -2911,121 +2152,85 @@ extension type E(int it) { } test_instance_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 50, - 3, - contextMessages: [message(testFile, 33, 3)], - ), - ], - ); +'''); } test_instance_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 59, - 3, - contextMessages: [message(testFile, 38, 3)], - ), - ], - ); +'''); } test_static_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 62, - 3, - contextMessages: [message(testFile, 40, 3)], - ), - ], - ); +'''); } test_static_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 66, - 3, - contextMessages: [message(testFile, 40, 3)], - ), - ], - ); +'''); } test_static_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 63, - 3, - contextMessages: [message(testFile, 40, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 72, - 3, - contextMessages: [message(testFile, 46, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static final int foo = 0; static set foo(int x) {} @@ -3034,45 +2239,33 @@ extension type E(int it) { } test_static_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 71, - 3, - contextMessages: [message(testFile, 44, 3)], - ), - ], - ); +'''); } test_static_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 68, - 3, - contextMessages: [message(testFile, 44, 3)], - ), - ], - ); +'''); } test_static_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int get foo => 0; static set foo(_) {} @@ -3081,64 +2274,46 @@ extension type E(int it) { } test_static_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 67, - 3, - contextMessages: [message(testFile, 41, 3)], - ), - ], - ); +'''); } test_static_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 64, - 3, - contextMessages: [message(testFile, 41, 3)], - ), - ], - ); +'''); } test_static_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 63, - 3, - contextMessages: [message(testFile, 41, 3)], - ), - ], - ); +'''); } test_static_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static set foo(_) {} static int get foo => 0; @@ -3147,141 +2322,99 @@ extension type E(int it) { } test_static_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 64, - 3, - contextMessages: [message(testFile, 40, 3)], - ), - ], - ); +'''); } test_static_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 73, - 3, - contextMessages: [message(testFile, 45, 3)], - ), - ], - ); +'''); } test_unitMembers_extensionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension type E(int it) {} +// ^ +// [context 1] The first definition of this name. extension type E(int it) {} -''', - [ - error( - diag.duplicateDefinition, - 43, - 1, - contextMessages: [message(testFile, 15, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'E' is already defined. +'''); } } @reflectiveTest class DuplicateDefinitionMixinTest extends PubPackageResolutionTest { test_instance_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 31, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 35, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int foo = 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 32, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 41, - 3, - contextMessages: [message(testFile, 22, 3)], - ), - ], - ); +'''); } test_instance_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { final int foo = 0; set foo(int x) {} @@ -3290,45 +2423,33 @@ mixin M { } test_instance_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 40, - 3, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } test_instance_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 37, - 3, - contextMessages: [message(testFile, 20, 3)], - ), - ], - ); +'''); } test_instance_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { int get foo => 0; set foo(_) {} @@ -3337,41 +2458,29 @@ mixin M { } test_instance_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { void foo() {} +// ^^^ +// [context 1] The first definition of this name. int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 36, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_instance_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { void foo() {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 33, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -3432,26 +2541,20 @@ mixin A { } test_instance_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { void foo() {} +// ^^^ +// [context 1] The first definition of this name. set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 32, - 3, - contextMessages: [message(testFile, 17, 3)], - ), - ], - ); +'''); } test_instance_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { set foo(_) {} int get foo => 0; @@ -3460,121 +2563,85 @@ mixin M { } test_instance_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 33, - 3, - contextMessages: [message(testFile, 16, 3)], - ), - ], - ); +'''); } test_instance_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 42, - 3, - contextMessages: [message(testFile, 21, 3)], - ), - ], - ); +'''); } test_static_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int foo = 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 45, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 49, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_field_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 46, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static final int foo = 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 55, - 3, - contextMessages: [message(testFile, 29, 3)], - ), - ], - ); +'''); } test_static_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static final int foo = 0; static set foo(int x) {} @@ -3583,45 +2650,33 @@ mixin M { } test_static_getter_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 54, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_getter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int get foo => 0; +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 51, - 3, - contextMessages: [message(testFile, 27, 3)], - ), - ], - ); +'''); } test_static_getter_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static int get foo => 0; static set foo(_) {} @@ -3630,64 +2685,46 @@ mixin M { } test_static_method_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static int get foo => 0; +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 50, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_static_method_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 47, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_static_method_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static void foo() {} +// ^^^ +// [context 1] The first definition of this name. static set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 46, - 3, - contextMessages: [message(testFile, 24, 3)], - ), - ], - ); +'''); } test_static_setter_getter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static set foo(_) {} static int get foo => 0; @@ -3696,118 +2733,90 @@ mixin M { } test_static_setter_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void foo() {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 47, - 3, - contextMessages: [message(testFile, 23, 3)], - ), - ], - ); +'''); } test_static_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin M { static void set foo(_) {} +// ^^^ +// [context 1] The first definition of this name. static void set foo(_) {} +// ^^^ +// [diag.duplicateDefinition][context 1] The name 'foo' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 56, - 3, - contextMessages: [message(testFile, 28, 3)], - ), - ], - ); +'''); } } @reflectiveTest class DuplicateDefinitionTest extends PubPackageResolutionTest { test_block_localFunction_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { void _() {} +//^^^^^^^^^^^ +// [diag.deadCode] Dead code. int _(int _) => 42; +//^^^^^^^^^^^^^^^^^^^ +// [diag.deadCode] Dead code. String _(int _) => "42"; +//^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.deadCode, 13, 11), - error(diag.deadCode, 27, 19), - error(diag.deadCode, 49, 24), - ], - ); +'''); } test_block_localFunction_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) void f() { void _() {} +// ^ +// [context 1] The first definition of this name. +// [context 2] The first definition of this name. +// [diag.unusedElement] The declaration '_' isn't referenced. int _(int _) => 42; +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +// [diag.unusedElement] The declaration '_' isn't referenced. String _(int _) => "42"; +// ^ +// [diag.duplicateDefinition][context 2] The name '_' is already defined. +// [diag.unusedElement] The declaration '_' isn't referenced. } -''', - [ - error(diag.unusedElement, 62, 1), - error( - diag.duplicateDefinition, - 75, - 1, - contextMessages: [message(testFile, 62, 1)], - ), - error(diag.unusedElement, 75, 1), - error( - diag.duplicateDefinition, - 100, - 1, - contextMessages: [message(testFile, 62, 1)], - ), - error(diag.unusedElement, 100, 1), - ], - ); +'''); } test_block_localVariable_localVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var a = 0; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var a = 1; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 17, 1), - error(diag.unusedLocalVariable, 30, 1), - error( - diag.duplicateDefinition, - 30, - 1, - contextMessages: [message(testFile, 17, 1)], - ), - ], - ); +'''); } test_block_localVariable_localVariable_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var _ = 0; var _ = 1; @@ -3816,50 +2825,38 @@ void f() { } test_block_localVariable_localVariable_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) void f() { var _ = 0; +// ^ +// [context 1] The first definition of this name. var _ = 1; +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 74, - 1, - contextMessages: [message(testFile, 61, 1)], - ), - ], - ); +'''); } test_block_localVariable_patternVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var a = 0; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var (a) = 1; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 17, 1), - error( - diag.duplicateDefinition, - 31, - 1, - contextMessages: [message(testFile, 17, 1)], - ), - error(diag.unusedLocalVariable, 31, 1), - ], - ); +'''); } test_block_localVariable_patternVariable_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var _ = 0; var (_) = 1; @@ -3868,7 +2865,7 @@ void f() { } test_block_localVariable_patternVariable_wildcard_preWildcards() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) @@ -3880,127 +2877,96 @@ void f() { } test_block_patternVariable_localVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var (a) = 1; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var a = 0; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 18, 1), - error( - diag.duplicateDefinition, - 32, - 1, - contextMessages: [message(testFile, 18, 1)], - ), - error(diag.unusedLocalVariable, 32, 1), - ], - ); +'''); } test_block_patternVariable_patternVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var (a) = 0; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var (a) = 1; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.unusedLocalVariable, 18, 1), - error( - diag.duplicateDefinition, - 33, - 1, - contextMessages: [message(testFile, 18, 1)], - ), - error(diag.unusedLocalVariable, 33, 1), - ], - ); +'''); } test_catch() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' main() { try {} catch (e, e) {} -}''', - [ - error(diag.unusedCatchStack, 28, 1), - error( - diag.duplicateDefinition, - 28, - 1, - contextMessages: [message(testFile, 25, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'e' is already defined. +// [diag.unusedCatchStack] The stack trace variable 'e' isn't used and can be removed. +}'''); } test_catch_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() { try {} catch (_, _) {} }'''); } test_catch_wildcard_preWildCards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) f() { try {} catch (_, _) {} -}''', - [ - error( - diag.duplicateDefinition, - 69, - 1, - contextMessages: [message(testFile, 66, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +}'''); } test_emptyName() async { // Note: This code has two FunctionElements '() {}' with an empty name; this // tests that the empty string is not put into the scope (more than once). - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' Map _globalMap = { +// ^^^^^^^^^^ +// [diag.unusedElement] The declaration '_globalMap' isn't referenced. 'a' : () {}, 'b' : () {} }; -''', - [error(diag.unusedElement, 4, 10)], - ); +'''); } test_for_initializers() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { for (int i = 0, i = 0; i < 5;) {} +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'i' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used. } -''', - [ - error( - diag.duplicateDefinition, - 24, - 1, - contextMessages: [message(testFile, 17, 1)], - ), - error(diag.unusedLocalVariable, 24, 1), - ], - ); +'''); } test_for_initializers_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() { for (int _ = 0, _ = 0; ;) {} } @@ -4008,188 +2974,150 @@ f() { } test_for_initializers_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) f() { for (int _ = 0, _ = 0; ;) {} +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 68, - 1, - contextMessages: [message(testFile, 61, 1)], - ), - ], - ); +'''); } test_getter_single() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' bool get a => true; '''); } test_parameters_constructor_field_first() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? a; A(this.a, int a); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 36, - 1, - contextMessages: [message(testFile, 29, 1)], - ), - ], - ); +'''); } test_parameters_constructor_field_first_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. A(this._, int _); } -''', - [error(diag.unusedField, 17, 1)], - ); +'''); } test_parameters_constructor_field_first_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) class A { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. A(this._, int _); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } -''', - [ - error(diag.unusedField, 61, 1), - error( - diag.duplicateDefinition, - 80, - 1, - contextMessages: [message(testFile, 73, 1)], - ), - ], - ); +'''); } test_parameters_constructor_field_second() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? a; A(int a, this.a); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 36, - 1, - contextMessages: [message(testFile, 28, 1)], - ), - ], - ); +'''); } test_parameters_constructor_field_second_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. A(int _, this._); } -''', - [error(diag.unusedField, 17, 1)], - ); +'''); } test_parameters_constructor_field_second_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) class A { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. A(int _, this._); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } -''', - [ - error(diag.unusedField, 61, 1), - error( - diag.duplicateDefinition, - 80, - 1, - contextMessages: [message(testFile, 72, 1)], - ), - ], - ); +'''); } test_parameters_constructor_super_first_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. A(this._); } class B extends A { B(super._, super._); +// ^ +// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter. } -''', - [ - error(diag.unusedField, 17, 1), - error(diag.superFormalParameterWithoutAssociatedPositional, 74, 1), - ], - ); +'''); } test_parameters_constructor_super_first_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) class A { int? _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. A(this._); } class B extends A { B(super._, super._); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter. } -''', - [ - error(diag.unusedField, 61, 1), - error( - diag.duplicateDefinition, - 118, - 1, - contextMessages: [message(testFile, 109, 1)], - ), - error(diag.superFormalParameterWithoutAssociatedPositional, 118, 1), - ], - ); +'''); } test_parameters_constructor_this_super_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { final int x, y; A(this.x, [this.y = 0]); @@ -4197,170 +3125,129 @@ class A { class C extends A { final int _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. C(this._, super._, [super._]); } -''', - [error(diag.unusedField, 90, 1)], - ); +'''); } test_parameters_functionTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef void F(int a, double a); -''', - [ - error( - diag.duplicateDefinition, - 29, - 1, - contextMessages: [message(testFile, 19, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +'''); } test_parameters_functionTypeAlias_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef void F(int _, double _); '''); } test_parameters_functionTypeAlias_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) typedef void F(int _, double _); -''', - [ - error( - diag.duplicateDefinition, - 73, - 1, - contextMessages: [message(testFile, 63, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_parameters_genericFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function(int a, double a); -''', - [ - error( - diag.duplicateDefinition, - 40, - 1, - contextMessages: [message(testFile, 30, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +'''); } test_parameters_genericFunction_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function(int _, double _); '''); } test_parameters_genericFunction_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) typedef F = void Function(int _, double _); -''', - [ - error( - diag.duplicateDefinition, - 84, - 1, - contextMessages: [message(testFile, 74, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_parameters_localFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' main() { f(int a, double a) { +//^ +// [diag.unusedElement] The declaration 'f' isn't referenced. +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. }; } -''', - [ - error(diag.unusedElement, 11, 1), - error( - diag.duplicateDefinition, - 27, - 1, - contextMessages: [message(testFile, 17, 1)], - ), - ], - ); +'''); } test_parameters_localFunction_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() { g(int _, double _) {}; +//^ +// [diag.unusedElement] The declaration 'g' isn't referenced. } -''', - [error(diag.unusedElement, 8, 1)], - ); +'''); } test_parameters_localFunction_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) f() { g(int _, double _) {}; +//^ +// [diag.unusedElement] The declaration 'g' isn't referenced. +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } -''', - [ - error(diag.unusedElement, 52, 1), - error( - diag.duplicateDefinition, - 68, - 1, - contextMessages: [message(testFile, 58, 1)], - ), - ], - ); +'''); } test_parameters_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { m(int a, double a) { +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. } } -''', - [ - error( - diag.duplicateDefinition, - 28, - 1, - contextMessages: [message(testFile, 18, 1)], - ), - ], - ); +'''); } test_parameters_method_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { m(int _, double _) { } @@ -4369,249 +3256,185 @@ class A { } test_parameters_method_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) class A { m(int _, double _) { +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } } -''', - [ - error( - diag.duplicateDefinition, - 72, - 1, - contextMessages: [message(testFile, 62, 1)], - ), - ], - ); +'''); } test_parameters_primaryConstructor_field_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(int a, this.a) { +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. int a; } -''', - [ - error( - diag.duplicateDefinition, - 20, - 1, - contextMessages: [message(testFile, 12, 1)], - ), - ], - ); +'''); } test_parameters_primaryConstructor_field_simple_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(int _, this._) { int _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. } -''', - [error(diag.unusedField, 31, 1)], - ); +'''); } test_parameters_primaryConstructor_simple_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(this.a, int a) { +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. int a; } -''', - [ - error( - diag.duplicateDefinition, - 20, - 1, - contextMessages: [message(testFile, 13, 1)], - ), - ], - ); +'''); } test_parameters_primaryConstructor_simple_field_wildcard() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(this._, int _) { int _; +// ^ +// [diag.unusedField] The value of the field '_' isn't used. } -''', - [error(diag.unusedField, 31, 1)], - ); +'''); } test_parameters_primaryConstructor_simple_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(int a, int a) {} -''', - [ - error( - diag.duplicateDefinition, - 19, - 1, - contextMessages: [message(testFile, 12, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +'''); } test_parameters_primaryConstructor_super_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(this.a, this.b) { int a; int b; } class B(super.a, super.a) extends A {} -''', - [ - error( - diag.duplicateDefinition, - 69, - 1, - contextMessages: [message(testFile, 60, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +'''); } test_parameters_primaryConstructor_this_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A(this.a, this.b) { int a; int b; } class C(this.x, super.x) extends A { +// ^ +// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters. +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'x' is already defined. final int x; } -''', - [ - error(diag.implicitSuperInitializerMissingArguments, 52, 1), - error( - diag.duplicateDefinition, - 68, - 1, - contextMessages: [message(testFile, 59, 1)], - ), - ], - ); +'''); } test_parameters_topLevelFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, double a) {} -''', - [ - error( - diag.duplicateDefinition, - 16, - 1, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +'''); } test_parameters_topLevelFunction_synthetic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(,[]) {} -''', - [ - error(diag.missingIdentifier, 2, 1), - error(diag.missingIdentifier, 4, 1), - ], - ); +//^ +// [diag.missingIdentifier] Expected an identifier. +// ^ +// [diag.missingIdentifier] Expected an identifier. +'''); } test_parameters_topLevelFunction_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int _, double _) {} '''); } test_parameters_topLevelFunction_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) f(int _, double _) {} -''', - [ - error( - diag.duplicateDefinition, - 60, - 1, - contextMessages: [message(testFile, 50, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_switchCase_localVariable_localVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f() { switch (0) { case 0: var a; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var a; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } } -''', - [ - error(diag.unusedLocalVariable, 64, 1), - error( - diag.duplicateDefinition, - 77, - 1, - contextMessages: [message(testFile, 64, 1)], - ), - error(diag.unusedLocalVariable, 77, 1), - ], - ); +'''); } test_switchDefault_localVariable_localVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { switch (0) { default: var a; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var a; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } } -''', - [ - error(diag.unusedLocalVariable, 49, 1), - error( - diag.duplicateDefinition, - 62, - 1, - contextMessages: [message(testFile, 49, 1)], - ), - error(diag.unusedLocalVariable, 62, 1), - ], - ); +'''); } test_switchDefault_localVariable_localVariable_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) @@ -4619,23 +3442,18 @@ void f() { switch (0) { default: var _; +// ^ +// [context 1] The first definition of this name. var _; +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } } -''', - [ - error( - diag.duplicateDefinition, - 106, - 1, - contextMessages: [message(testFile, 93, 1)], - ), - ], - ); +'''); } test_switchDefault_localVariable_localVariable_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { switch (0) { default: @@ -4647,31 +3465,25 @@ void f() { } test_switchPatternCase_localVariable_localVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { switch (0) { case 0: var a; +// ^ +// [context 1] The first definition of this name. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. var a; +// ^ +// [diag.duplicateDefinition][context 1] The name 'a' is already defined. +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } } -''', - [ - error(diag.unusedLocalVariable, 48, 1), - error( - diag.duplicateDefinition, - 61, - 1, - contextMessages: [message(testFile, 48, 1)], - ), - error(diag.unusedLocalVariable, 61, 1), - ], - ); +'''); } test_switchPatternCase_localVariable_localVariable_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { switch (0) { case 0: @@ -4683,8 +3495,7 @@ void f() { } test_switchPatternCase_localVariable_localVariable_wildcard_preWildCards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) @@ -4692,125 +3503,90 @@ void f() { switch (0) { case 0: var _; +// ^ +// [context 1] The first definition of this name. var _; +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } } -''', - [ - error( - diag.duplicateDefinition, - 105, - 1, - contextMessages: [message(testFile, 92, 1)], - ), - ], - ); +'''); } test_topLevel_field_field() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var f = 1; +// ^ +// [context 1] The first definition of this name. var f = 2; -''', - [ - error( - diag.duplicateDefinition, - 15, - 1, - contextMessages: [message(testFile, 4, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'f' is already defined. +'''); } test_topLevel_field_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int f = 1; +// ^ +// [context 1] The first definition of this name. int get f => 7; -''', - [ - error( - diag.duplicateDefinition, - 19, - 1, - contextMessages: [message(testFile, 4, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'f' is already defined. +'''); } test_topLevel_field_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int f = 1; +// ^ +// [context 1] The first definition of this name. set f(int value) {} -''', - [ - error( - diag.duplicateDefinition, - 15, - 1, - contextMessages: [message(testFile, 4, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'f=' is already defined. +'''); } test_topLevel_fieldConst_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' const f = 0; set f(_) {} '''); } test_topLevel_fieldFinal_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' final f = 1; set f(int value) {} '''); } test_topLevel_fieldLateFinalInitializer_setter() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' late final f = 1; set f(int value) {} '''); } test_topLevel_fieldLateFinalNoInitializer_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' late final f; +// ^ +// [context 1] The first definition of this name. set f(int value) {} -''', - [ - error( - diag.duplicateDefinition, - 18, - 1, - contextMessages: [message(testFile, 11, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'f=' is already defined. +'''); } test_topLevel_setter_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' set f(int value) {} +// ^ +// [context 1] The first definition of this name. set f(int value) {} -''', - [ - error( - diag.duplicateDefinition, - 24, - 1, - contextMessages: [message(testFile, 4, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'f=' is already defined. +'''); } test_topLevel_setter_setter_inPart() async { @@ -4819,7 +3595,7 @@ part of 'test.dart'; set f(int value) {} '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' part 'a.dart'; set f(int value) {} '''); @@ -4835,230 +3611,164 @@ set f(int value) {} } test_typeParameters_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} -''', - [ - error( - diag.duplicateDefinition, - 11, - 1, - contextMessages: [message(testFile, 8, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. +'''); } test_typeParameters_class_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A<_, _> {} '''); } test_typeParameters_class_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) class A<_, _> {} -''', - [ - error( - diag.duplicateDefinition, - 55, - 1, - contextMessages: [message(testFile, 52, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_typeParameters_functionTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef void F(); -''', - [ - error( - diag.duplicateDefinition, - 18, - 1, - contextMessages: [message(testFile, 15, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. +'''); } test_typeParameters_functionTypeAlias_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef void F<_, _>(); '''); } test_typeParameters_functionTypeAlias_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) typedef void F<_, _>(); -''', - [ - error( - diag.duplicateDefinition, - 62, - 1, - contextMessages: [message(testFile, 59, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_typeParameters_genericFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function(); -''', - [ - error( - diag.duplicateDefinition, - 29, - 1, - contextMessages: [message(testFile, 26, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. +'''); } test_typeParameters_genericFunction_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function<_, _>(); '''); } test_typeParameters_genericFunction_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) typedef F = void Function<_, _>(); -''', - [ - error( - diag.duplicateDefinition, - 73, - 1, - contextMessages: [message(testFile, 70, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_typeParameters_genericTypedef_functionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function(); -''', - [ - error( - diag.duplicateDefinition, - 13, - 1, - contextMessages: [message(testFile, 10, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. +'''); } test_typeParameters_genericTypedef_functionType_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F<_, _> = void Function(); '''); } test_typeParameters_genericTypedef_functionType_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) typedef F<_, _> = void Function(); -''', - [ - error( - diag.duplicateDefinition, - 57, - 1, - contextMessages: [message(testFile, 54, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_typeParameters_genericTypedef_interfaceType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = Map; -''', - [ - error( - diag.duplicateDefinition, - 13, - 1, - contextMessages: [message(testFile, 10, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. +'''); } test_typeParameters_genericTypedef_interfaceType_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef F<_, _> = Map; '''); } test_typeParameters_genericTypedef_interfaceType_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) typedef F<_, _> = Map; -''', - [ - error( - diag.duplicateDefinition, - 57, - 1, - contextMessages: [message(testFile, 54, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } test_typeParameters_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void m() {} +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 22, - 1, - contextMessages: [message(testFile, 19, 1)], - ), - ], - ); +'''); } test_typeParameters_method_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void m<_, _>() {} } @@ -5066,86 +3776,62 @@ class A { } test_typeParameters_method_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) class A { void m<_, _>() {} +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. } -''', - [ - error( - diag.duplicateDefinition, - 66, - 1, - contextMessages: [message(testFile, 63, 1)], - ), - ], - ); +'''); } test_typeParameters_topLevelFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() {} -''', - [ - error( - diag.duplicateDefinition, - 10, - 1, - contextMessages: [message(testFile, 7, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name 'T' is already defined. +'''); } test_typeParameters_topLevelFunction_wildcard() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f<_, _>() {} '''); } test_typeParameters_topLevelFunction_wildcard_preWildcards() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 3.4 // (pre wildcard-variables) void f<_, _>() {} -''', - [ - error( - diag.duplicateDefinition, - 54, - 1, - contextMessages: [message(testFile, 51, 1)], - ), - ], - ); +// ^ +// [context 1] The first definition of this name. +// ^ +// [diag.duplicateDefinition][context 1] The name '_' is already defined. +'''); } } @reflectiveTest class DuplicateDefinitionUnitTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} +// ^ +// [context 1] The first definition of this name. class B {} class A {} -''', - [ - error( - diag.duplicateDefinition, - 28, - 1, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'A' is already defined. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -5236,21 +3922,15 @@ class A {} } test_extension() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension A on int {} +// ^ +// [context 1] The first definition of this name. extension B on int {} extension A on int {} -''', - [ - error( - diag.duplicateDefinition, - 54, - 1, - contextMessages: [message(testFile, 10, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'A' is already defined. +'''); } test_extension_library_part() async { @@ -5282,21 +3962,15 @@ extension A on int {} } test_extensionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension type A(int it) {} +// ^ +// [context 1] The first definition of this name. extension type B(int it) {} extension type A(int it) {} -''', - [ - error( - diag.duplicateDefinition, - 71, - 1, - contextMessages: [message(testFile, 15, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'A' is already defined. +'''); } test_extensionType_library_part() async { @@ -5328,21 +4002,15 @@ extension type A(int it) {} } test_mixin() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' mixin A {} +// ^ +// [context 1] The first definition of this name. mixin B {} mixin A {} -''', - [ - error( - diag.duplicateDefinition, - 28, - 1, - contextMessages: [message(testFile, 6, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'A' is already defined. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation @@ -5395,20 +4063,14 @@ mixin A {} } test_typedef_interfaceType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' typedef A = List; +// ^ +// [context 1] The first definition of this name. typedef A = List; -''', - [ - error( - diag.duplicateDefinition, - 31, - 1, - contextMessages: [message(testFile, 8, 1)], - ), - ], - ); +// ^ +// [diag.duplicateDefinition][context 1] The name 'A' is already defined. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation