From 7b4ca03c82eab1f7d266cacc2b5b4902763649d8 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Fri, 15 May 2026 09:33:46 -0700 Subject: [PATCH] CQ. Migrate resolution tests to resolveTestCodeWithDiagnostics. AB. Change-Id: I7aaed1e340ab7a3086f1b5ca78019b811e06c56e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503720 Commit-Queue: Konstantin Shcheglov Reviewed-by: Paul Berry --- .../resolution/adjacent_strings_test.dart | 4 +- .../dart/resolution/as_expression_test.dart | 25 +- .../src/dart/resolution/assignment_test.dart | 793 ++++++++---------- .../src/dart/resolution/ast_rewrite_test.dart | 197 ++--- .../resolution/augmented_expression_test.dart | 321 ------- .../resolution/await_expression_test.dart | 54 +- .../resolution/binary_expression_test.dart | 234 +++--- .../test/src/dart/resolution/test_all.dart | 2 - 8 files changed, 564 insertions(+), 1066 deletions(-) delete mode 100644 pkg/analyzer/test/src/dart/resolution/augmented_expression_test.dart diff --git a/pkg/analyzer/test/src/dart/resolution/adjacent_strings_test.dart b/pkg/analyzer/test/src/dart/resolution/adjacent_strings_test.dart index 99215904a5e..fe9d63a02f7 100644 --- a/pkg/analyzer/test/src/dart/resolution/adjacent_strings_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/adjacent_strings_test.dart @@ -5,17 +5,19 @@ import 'package:test_reflective_loader/test_reflective_loader.dart'; import 'context_collection_resolution.dart'; +import 'node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(AdjacentStringsResolutionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AdjacentStringsResolutionTest extends PubPackageResolutionTest { test_it() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f() { 'aaa' 'bbb' 'ccc'; } diff --git a/pkg/analyzer/test/src/dart/resolution/as_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/as_expression_test.dart index bc0d19fa62f..ad62c9e006b 100644 --- a/pkg/analyzer/test/src/dart/resolution/as_expression_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/as_expression_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 'context_collection_resolution.dart'; +import 'node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(AsExpressionResolutionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AsExpressionResolutionTest extends PubPackageResolutionTest { test_expression_constVariable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' const num a = 1.2; const int b = a as int; -''', - [error(diag.constEvalThrowsException, 33, 8)], - ); +// ^^^^^^^^ +// [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. +'''); var node = findNode.asExpression('as int'); assertResolvedNodeText(node, r''' @@ -41,7 +41,7 @@ AsExpression } test_expression_localVariable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f() { num v = 42; v as int; @@ -65,16 +65,15 @@ AsExpression } test_expression_super() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void f() { super as T; +// ^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. } } -''', - [error(diag.missingAssignableSelector, 30, 5)], - ); +'''); var node = findNode.singleAsExpression; assertResolvedNodeText(node, r''' @@ -92,7 +91,7 @@ AsExpression } test_expression_switchExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(Object? x) { (switch (x) { _ => 0, diff --git a/pkg/analyzer/test/src/dart/resolution/assignment_test.dart b/pkg/analyzer/test/src/dart/resolution/assignment_test.dart index 9708a152e7d..063d338b48d 100644 --- a/pkg/analyzer/test/src/dart/resolution/assignment_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/assignment_test.dart @@ -19,7 +19,7 @@ main() { @reflectiveTest class AssignmentExpressionResolutionTest extends PubPackageResolutionTest { test_compound_plus_int_context_int() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int a) { a += f(); @@ -57,7 +57,7 @@ AssignmentExpression } test_compound_plus_int_context_int_complex() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(List a) { a[0] += f(); @@ -110,7 +110,7 @@ AssignmentExpression } test_compound_plus_int_context_int_promoted() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(num a) { if (a is int) { @@ -150,7 +150,7 @@ AssignmentExpression } test_compound_plus_int_context_int_promoted_with_subsequent_demotion() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(num a, bool b) { if (a is int) { @@ -209,7 +209,7 @@ SimpleIdentifier } test_dynamicIdentifier_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic a) { a += 0; } @@ -237,7 +237,7 @@ AssignmentExpression } test_dynamicIdentifier_identifier_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic a) { a.foo += 0; } @@ -273,7 +273,7 @@ AssignmentExpression } test_dynamicIdentifier_identifier_identifier_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic a) { a.foo.bar += 0; } @@ -316,7 +316,7 @@ AssignmentExpression } test_ifNull_lubUsedEvenIfItDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' // @dart=3.3 f(Object? o1, Object? o2, List listNum) { if (o1 is Iterable? && o2 is Iterable) { @@ -351,7 +351,7 @@ AssignmentExpression var v = 0; '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' deferred as prefix; void f() { @@ -389,7 +389,7 @@ AssignmentExpression } test_indexExpression_cascade_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator[](int index) => 0; operator[]=(int index, num _) {} @@ -429,7 +429,7 @@ AssignmentExpression } test_indexExpression_dynamicTarget_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic a) { a[0] += 1; } @@ -466,7 +466,7 @@ AssignmentExpression } test_indexExpression_instance_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator[](int index) => 0; operator[]=(int index, num _) {} @@ -509,7 +509,7 @@ AssignmentExpression } test_indexExpression_instance_compound_double_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { num operator[](int index) => 0; operator[]=(int index, num _) {} @@ -552,7 +552,7 @@ AssignmentExpression } test_indexExpression_instance_ifNull() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? operator[](int? index) => 0; operator[]=(int? index, num? _) {} @@ -595,7 +595,7 @@ AssignmentExpression } test_indexExpression_instance_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { operator[]=(int index, num _) {} } @@ -637,7 +637,7 @@ AssignmentExpression } test_indexExpression_nullShorting_assignable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { B get b; } @@ -688,8 +688,7 @@ AssignmentExpression } test_indexExpression_nullShorting_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { B get b; } @@ -698,10 +697,10 @@ abstract class B { } test(A? a, String s) { a?.b[s] = null; +// ^^^^ +// [diag.invalidAssignment] A value of type 'Null' can't be assigned to a variable of type 'int'. } -''', - [error(diag.invalidAssignment, 121, 4)], - ); +'''); var node = findNode.assignment('= null'); assertResolvedNodeText(node, r''' @@ -742,7 +741,7 @@ AssignmentExpression } test_indexExpression_super_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator[](int index) => 0; operator[]=(int index, num _) {} @@ -786,7 +785,7 @@ AssignmentExpression } test_indexExpression_this_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator[](int index) => 0; operator[]=(int index, num _) {} @@ -828,17 +827,15 @@ AssignmentExpression } test_indexExpression_unresolved1_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int c) { a[b] = c; +//^ +// [diag.undefinedIdentifier] Undefined name 'a'. +// ^ +// [diag.undefinedIdentifier] Undefined name 'b'. } -''', - [ - error(diag.undefinedIdentifier, 18, 1), - error(diag.undefinedIdentifier, 20, 1), - ], - ); +'''); var assignment = findNode.assignment('a[b] = c'); @@ -874,17 +871,15 @@ AssignmentExpression } test_indexExpression_unresolved2_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, int c) { a[b] = c; +// ^^^ +// [diag.undefinedOperator] The operator '[]=' isn't defined for the type 'int'. +// ^ +// [diag.undefinedIdentifier] Undefined name 'b'. } -''', - [ - error(diag.undefinedOperator, 26, 3), - error(diag.undefinedIdentifier, 27, 1), - ], - ); +'''); var assignment = findNode.assignment('a[b] = c'); @@ -920,18 +915,17 @@ AssignmentExpression } test_indexExpression_unresolved3_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { operator[]=(int index, num _) {} } void f(A a, int c) { a[b] = c; +// ^ +// [diag.undefinedIdentifier] Undefined name 'b'. } -''', - [error(diag.undefinedIdentifier, 73, 1)], - ); +'''); var assignment = findNode.assignment('a[b] = c'); @@ -967,31 +961,28 @@ AssignmentExpression } test_indexExpression_unresolved_missing_type_parameter_name() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { void b< extends int>(); +// ^^^^^^^ +// [diag.missingIdentifier] Expected an identifier. } void f(A a) { a.b[0] = 0; +// ^^^ +// [diag.undefinedOperator] The operator '[]=' isn't defined for the type 'void Function< extends int>()'. } -''', - [ - error(diag.missingIdentifier, 30, 7), - error(diag.undefinedOperator, 67, 3), - ], - ); +'''); } test_indexExpression_unresolvedTarget_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { a[0] += 1; +//^ +// [diag.undefinedIdentifier] Undefined name 'a'. } -''', - [error(diag.undefinedIdentifier, 13, 1)], - ); +'''); var node = findNode.singleAssignmentExpression; assertResolvedNodeText(node, r''' @@ -1024,19 +1015,16 @@ AssignmentExpression } test_left_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void f() { super = 0; +// ^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } } -''', - [ - error(diag.missingAssignableSelector, 27, 5), - error(diag.illegalAssignmentToNonAssignable, 27, 5), - ], - ); +'''); var node = findNode.singleAssignmentExpression; assertResolvedNodeText(node, r''' @@ -1059,17 +1047,14 @@ AssignmentExpression } test_notLValue_binaryExpression_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, int b, double c) { a + b += c; +//^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 35, 5), - error(diag.missingAssignableSelector, 35, 5), - ], - ); +'''); var assignment = findNode.assignment('= c'); @@ -1105,17 +1090,14 @@ AssignmentExpression } test_notLValue_parenthesized_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, int b, double c) { (a + b) += c; +//^^^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 35, 7), - error(diag.missingAssignableSelector, 35, 7), - ], - ); +'''); var assignment = findNode.assignment('= c'); @@ -1155,17 +1137,15 @@ AssignmentExpression } test_notLValue_parenthesized_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, double b) { (a + 0) = b; +// ^ +// [diag.patternTypeMismatchInIrrefutableContext] The matched value of type 'double' isn't assignable to the required type 'int'. +// ^ +// [diag.expectedToken] Expected to find ')'. } -''', - [ - error(diag.patternTypeMismatchInIrrefutableContext, 29, 1), - error(diag.expectedToken, 31, 1), - ], - ); +'''); var node = findNode.singlePatternAssignment; assertResolvedNodeText(node, r''' @@ -1189,18 +1169,15 @@ PatternAssignment } test_notLValue_parenthesized_simple_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 void f(int a, double b) { (a + 0) = b; +//^^^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 44, 7), - error(diag.missingAssignableSelector, 44, 7), - ], - ); +'''); var node = findNode.assignment('= b'); assertResolvedNodeText(node, r''' @@ -1238,17 +1215,14 @@ AssignmentExpression } test_notLValue_postfixIncrement_compound() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(num x, int y) { x++ += y; +//^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 25, 3), - error(diag.missingAssignableSelector, 25, 3), - ], - ); +'''); var assignment = findNode.assignment('= y'); @@ -1282,17 +1256,14 @@ AssignmentExpression } test_notLValue_postfixIncrement_compound_ifNull() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(num x, int y) { x++ ??= y; +//^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 25, 3), - error(diag.missingAssignableSelector, 25, 3), - ], - ); +'''); var assignment = findNode.assignment('= y'); @@ -1326,17 +1297,14 @@ AssignmentExpression } test_notLValue_postfixIncrement_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(num x, int y) { x++ = y; +//^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 25, 3), - error(diag.missingAssignableSelector, 25, 3), - ], - ); +'''); var assignment = findNode.assignment('= y'); @@ -1370,17 +1338,14 @@ AssignmentExpression } test_notLValue_prefixIncrement_compound() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(num x, int y) { ++x += y; +//^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 25, 3), - error(diag.missingAssignableSelector, 25, 3), - ], - ); +'''); var assignment = findNode.assignment('= y'); @@ -1414,17 +1379,14 @@ AssignmentExpression } test_notLValue_prefixIncrement_compound_ifNull() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(num x, int y) { ++x ??= y; +//^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 25, 3), - error(diag.missingAssignableSelector, 25, 3), - ], - ); +'''); var assignment = findNode.assignment('= y'); @@ -1458,17 +1420,14 @@ AssignmentExpression } test_notLValue_prefixIncrement_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(num x, int y) { ++x = y; +//^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. +// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression. } -''', - [ - error(diag.illegalAssignmentToNonAssignable, 25, 3), - error(diag.missingAssignableSelector, 25, 3), - ], - ); +'''); var assignment = findNode.assignment('= y'); @@ -1504,16 +1463,15 @@ AssignmentExpression test_notLValue_typeLiteral_class_ambiguous_simple() async { newFile('$testPackageLibPath/a.dart', 'class C {}'); newFile('$testPackageLibPath/b.dart', 'class C {}'); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; import 'b.dart'; void f() { C = 0; +//^ +// [diag.ambiguousImport] The name 'C' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'. } -''', - [error(diag.ambiguousImport, 47, 1)], - ); +'''); var assignment = findNode.assignment('C = 0'); @@ -1540,16 +1498,15 @@ AssignmentExpression } test_notLValue_typeLiteral_class_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C {} void f() { C = 0; +//^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 25, 1)], - ); +'''); var assignment = findNode.assignment('C = 0'); @@ -1574,7 +1531,7 @@ AssignmentExpression } test_nullAware_context() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int? a) { a ??= f(); @@ -1612,7 +1569,7 @@ AssignmentExpression } test_prefixedIdentifier_instance_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; set x(num _) {} @@ -1654,7 +1611,7 @@ AssignmentExpression } test_prefixedIdentifier_instance_ifNull() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? get x => 0; set x(num? _) {} @@ -1696,7 +1653,7 @@ AssignmentExpression } test_prefixedIdentifier_instance_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set x(num _) {} } @@ -1737,18 +1694,17 @@ AssignmentExpression } test_prefixedIdentifier_instanceGetter_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; } void f(A a) { a.x = 2; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. } -''', - [error(diag.assignmentToFinalNoSetter, 49, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -2220,7 +2176,7 @@ AssignmentExpression } test_prefixedIdentifier_static_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static set x(num _) {} } @@ -2261,18 +2217,17 @@ AssignmentExpression } test_prefixedIdentifier_staticGetter_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get x => 0; } void f() { A.x = 2; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'. } -''', - [error(diag.assignmentToFinalNoSetter, 53, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -2309,7 +2264,7 @@ AssignmentExpression int get x => 0; set x(num _) {} '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as p; void f() { @@ -2348,7 +2303,7 @@ AssignmentExpression } test_prefixedIdentifier_typeAlias_static_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static int get x => 0; static set x(int _) {} @@ -2392,14 +2347,13 @@ AssignmentExpression } test_prefixedIdentifier_unresolved1_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int c) { a.b = c; +//^ +// [diag.undefinedIdentifier] Undefined name 'a'. } -''', - [error(diag.undefinedIdentifier, 18, 1)], - ); +'''); var assignment = findNode.assignment('a.b = c'); @@ -2433,14 +2387,14 @@ AssignmentExpression } test_prefixedIdentifier_unresolved2_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, int c) { a.b += c; +// ^ +// [diag.undefinedGetter] The getter 'b' isn't defined for the type 'int'. +// [diag.undefinedSetter] The setter 'b' isn't defined for the type 'int'. } -''', - [error(diag.undefinedGetter, 27, 1), error(diag.undefinedSetter, 27, 1)], - ); +'''); var assignment = findNode.assignment('a.b += c'); @@ -2474,7 +2428,7 @@ AssignmentExpression } test_propertyAccess_cascade_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; set x(num _) {} @@ -2511,7 +2465,7 @@ AssignmentExpression } test_propertyAccess_forwardingStub() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int x = 0; } @@ -2562,7 +2516,7 @@ AssignmentExpression } test_propertyAccess_instance_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; set x(num _) {} @@ -2607,7 +2561,7 @@ AssignmentExpression } test_propertyAccess_instance_fromMixins_compound() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' mixin M1 { int get x => 0; set x(num _) {} @@ -2660,7 +2614,7 @@ AssignmentExpression } test_propertyAccess_instance_ifNull() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int? get x => 0; set x(num? _) {} @@ -2705,7 +2659,7 @@ AssignmentExpression } test_propertyAccess_instance_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set x(num _) {} } @@ -2749,7 +2703,7 @@ AssignmentExpression } test_propertyAccess_nullShorting_assignable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { B get b; } @@ -2797,8 +2751,7 @@ AssignmentExpression } test_propertyAccess_nullShorting_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { B get b; } @@ -2807,10 +2760,10 @@ abstract class B { } test(A? a) { a?.b.setter = null; +// ^^^^ +// [diag.invalidAssignment] A value of type 'Null' can't be assigned to a variable of type 'int'. } -''', - [error(diag.invalidAssignment, 103, 4)], - ); +'''); var node = findNode.assignment('= null'); assertResolvedNodeText(node, r''' @@ -2967,14 +2920,14 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_FFFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(({int bar}) r) { r.foo += 0; +// ^^^ +// [diag.undefinedGetter] The getter 'foo' isn't defined for the type '({int bar})'. +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({int bar})'. } -''', - [error(diag.undefinedGetter, 28, 3), error(diag.undefinedSetter, 28, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3009,14 +2962,13 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_FFFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(({int bar}) r) { r.foo = 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({int bar})'. } -''', - [error(diag.undefinedSetter, 28, 3)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3051,18 +3003,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_FFFT_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int bar}) { set foo(int _) {} } void f(({int bar}) r) { r.foo += 0; +// ^^^ +// [diag.undefinedGetter] The getter 'foo' isn't defined for the type '({int bar})'. } -''', - [error(diag.undefinedGetter, 80, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3097,7 +3048,7 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_FFFT_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int bar}) { set foo(int _) {} } @@ -3140,18 +3091,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_FTFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int bar}) { int get foo => 0; } void f(({int bar}) r) { r.foo += 0; +// ^^^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'foo' in class 'E'. } -''', - [error(diag.assignmentToFinalNoSetter, 80, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3186,18 +3136,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_FTFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int bar}) { int get foo => 0; } void f(({int bar}) r) { r.foo = 0; +// ^^^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'foo' in class 'E'. } -''', - [error(diag.assignmentToFinalNoSetter, 80, 3)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3232,7 +3181,7 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_FTFT_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int bar}) { int get foo => 0; set foo(int _) {} @@ -3276,7 +3225,7 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_FTFT_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int bar}) { int get foo => 0; set foo(int _) {} @@ -3320,14 +3269,13 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_TFFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(({int foo, String bar}) r) { r.foo += 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 40, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3362,14 +3310,13 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_TFFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(({int foo, String bar}) r) { r.foo = 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 40, 3)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3404,18 +3351,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_TFFT_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int foo, String bar}) { set foo(int _) {} } void f(({int foo, String bar}) r) { r.foo += 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 104, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3450,18 +3396,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_TFFT_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int foo, String bar}) { set foo(int _) {} } void f(({int foo, String bar}) r) { r.foo = 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 104, 3)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3496,18 +3441,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_TTFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int foo, String bar}) { int get foo => 0; } void f(({int foo, String bar}) r) { r.foo += 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 104, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3542,18 +3486,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_named_TTFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int foo, String bar}) { int get foo => 0; } void f(({int foo, String bar}) r) { r.foo = 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 104, 3)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3588,8 +3531,7 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_TTFT_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int foo, String bar}) { int get foo => 0; set foo(int _) {} @@ -3597,10 +3539,10 @@ extension E on ({int foo, String bar}) { void f(({int foo, String bar}) r) { r.foo += 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 124, 3)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3635,8 +3577,7 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_named_TTFT_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on ({int foo, String bar}) { int get foo => 0; set foo(int _) {} @@ -3644,10 +3585,10 @@ extension E on ({int foo, String bar}) { void f(({int foo, String bar}) r) { r.foo = 0; +// ^^^ +// [diag.undefinedSetter] The setter 'foo' isn't defined for the type '({String bar, int foo})'. } -''', - [error(diag.undefinedSetter, 124, 3)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3682,14 +3623,14 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_positional_FFFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f((int, String) r) { r.$4 += 0; +// ^^ +// [diag.undefinedGetter] The getter '$4' isn't defined for the type '(int, String)'. +// [diag.undefinedSetter] The setter '$4' isn't defined for the type '(int, String)'. } -''', - [error(diag.undefinedGetter, 30, 2), error(diag.undefinedSetter, 30, 2)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3724,14 +3665,13 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_positional_FFFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f((int, String) r) { r.$4 = 0; +// ^^ +// [diag.undefinedSetter] The setter '$4' isn't defined for the type '(int, String)'. } -''', - [error(diag.undefinedSetter, 30, 2)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3766,18 +3706,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_positional_FTFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on (int, String) { int get $3 => 0; } void f((int, String) r) { r.$3 += 0; +// ^^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named '$3' in class 'E'. } -''', - [error(diag.assignmentToFinalNoSetter, 83, 2)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3812,18 +3751,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_positional_FTFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on (int, String) { int get $3 => 0; } void f((int, String) r) { r.$3 = 0; +// ^^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named '$3' in class 'E'. } -''', - [error(diag.assignmentToFinalNoSetter, 83, 2)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3858,14 +3796,13 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_positional_TFFF_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f((int, String) r) { r.$1 += 0; +// ^^ +// [diag.undefinedSetter] The setter '$1' isn't defined for the type '(int, String)'. } -''', - [error(diag.undefinedSetter, 30, 2)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3900,14 +3837,13 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: false test_propertyAccess_recordTypeField_positional_TFFF_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f((int, String) r) { r.$1 = 0; +// ^^ +// [diag.undefinedSetter] The setter '$1' isn't defined for the type '(int, String)'. } -''', - [error(diag.undefinedSetter, 30, 2)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -3942,18 +3878,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_positional_TFFT_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on (int, String) { set $1(int _) {} } void f((int, String) r) { r.$1 += 0; +// ^^ +// [diag.undefinedSetter] The setter '$1' isn't defined for the type '(int, String)'. } -''', - [error(diag.undefinedSetter, 83, 2)], - ); +'''); var node = findNode.assignment('+= 0'); assertResolvedNodeText(node, r''' @@ -3988,18 +3923,17 @@ AssignmentExpression /// Has record setter: false /// Has extension setter: true test_propertyAccess_recordTypeField_positional_TFFT_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on (int, String) { set $1(int _) {} } void f((int, String) r) { r.$1 = 0; +// ^^ +// [diag.undefinedSetter] The setter '$1' isn't defined for the type '(int, String)'. } -''', - [error(diag.undefinedSetter, 83, 2)], - ); +'''); var node = findNode.assignment('= 0'); assertResolvedNodeText(node, r''' @@ -4030,7 +3964,7 @@ AssignmentExpression } test_propertyAccess_super_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { set x(num _) {} int get x => 0; @@ -4075,7 +4009,7 @@ AssignmentExpression } test_propertyAccess_this_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int get x => 0; set x(num _) {} @@ -4115,14 +4049,13 @@ AssignmentExpression } test_propertyAccess_unresolved1_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int c) { (a).b = c; +// ^ +// [diag.undefinedIdentifier] Undefined name 'a'. } -''', - [error(diag.undefinedIdentifier, 19, 1)], - ); +'''); var assignment = findNode.assignment('(a).b = c'); @@ -4159,14 +4092,13 @@ AssignmentExpression } test_propertyAccess_unresolved2_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a, int c) { (a).b = c; +// ^ +// [diag.undefinedSetter] The setter 'b' isn't defined for the type 'int'. } -''', - [error(diag.undefinedSetter, 29, 1)], - ); +'''); var assignment = findNode.assignment('(a).b = c'); @@ -4203,16 +4135,15 @@ AssignmentExpression } test_right_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void f(Object a) { a = super; +// ^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. } } -''', - [error(diag.missingAssignableSelector, 39, 5)], - ); +'''); var node = findNode.singleAssignmentExpression; assertResolvedNodeText(node, r''' @@ -4235,7 +4166,7 @@ AssignmentExpression } test_simpleIdentifier_fieldInstance_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { num x = 0; @@ -4268,7 +4199,7 @@ AssignmentExpression } test_simpleIdentifier_fieldStatic_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { static num x = 0; @@ -4301,18 +4232,17 @@ AssignmentExpression } test_simpleIdentifier_getterInstance_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { num get x => 0; void f() { x = 2; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'C'. } } -''', - [error(diag.assignmentToFinalNoSetter, 46, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4337,18 +4267,17 @@ AssignmentExpression } test_simpleIdentifier_getterStatic_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C { static num get x => 0; void f() { x = 2; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'C'. } } -''', - [error(diag.assignmentToFinalNoSetter, 53, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4373,16 +4302,15 @@ AssignmentExpression } test_simpleIdentifier_getterTopLevel_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' int get x => 0; void f() { x = 2; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [error(diag.assignmentToFinal, 30, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4407,8 +4335,7 @@ AssignmentExpression } test_simpleIdentifier_importPrefix_hasSuperSetter_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:math' as x; class A { @@ -4418,11 +4345,11 @@ class A { class B extends A { void f() { x = 2; +// ^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'x' refers to an import prefix, so it must be followed by '.'. } } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 85, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4447,16 +4374,15 @@ AssignmentExpression } test_simpleIdentifier_importPrefix_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' import 'dart:math' as x; main() { x = 2; +//^ +// [diag.prefixIdentifierNotFollowedByDot] The name 'x' refers to an import prefix, so it must be followed by '.'. } -''', - [error(diag.prefixIdentifierNotFollowedByDot, 37, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4481,7 +4407,7 @@ AssignmentExpression } test_simpleIdentifier_localVariable_compound() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable num x = 0; @@ -4512,7 +4438,7 @@ AssignmentExpression } test_simpleIdentifier_localVariable_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_local_variable num x = 0; @@ -4543,16 +4469,15 @@ AssignmentExpression } test_simpleIdentifier_localVariableConst_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f() { // ignore:unused_local_variable const num x = 1; x = 2; +//^ +// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization. } -''', - [error(diag.assignmentToConst, 66, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4577,16 +4502,15 @@ AssignmentExpression } test_simpleIdentifier_localVariableFinal_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f() { // ignore:unused_local_variable final num x = 1; x = 2; +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 66, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4611,7 +4535,7 @@ AssignmentExpression } test_simpleIdentifier_parameter_compound_ifNull() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' void f(num? x) { x ??= 0; } @@ -4640,18 +4564,17 @@ AssignmentExpression } test_simpleIdentifier_parameter_compound_ifNull2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} class B extends A {} class C extends A {} void f(B? x) { x ??= C(); +// ^^^ +// [diag.invalidAssignment] A value of type 'C' can't be assigned to a variable of type 'B?'. } -''', - [error(diag.invalidAssignment, 77, 3)], - ); +'''); var assignment = findNode.assignment('x ??='); @@ -4684,14 +4607,13 @@ AssignmentExpression } test_simpleIdentifier_parameter_compound_ifNull_notAssignableType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f(double? a, int b) { a ??= b; +// ^ +// [diag.invalidAssignment] A value of type 'int' can't be assigned to a variable of type 'double?'. } -''', - [error(diag.invalidAssignment, 35, 1)], - ); +'''); var assignment = findNode.assignment('a ??='); @@ -4717,22 +4639,22 @@ AssignmentExpression } test_simpleIdentifier_parameter_compound_refineType_int_double() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { x += 1.2; +// ^^^ +// [diag.invalidAssignment] A value of type 'double' can't be assigned to a variable of type 'int'. x -= 1.2; +// ^^^ +// [diag.invalidAssignment] A value of type 'double' can't be assigned to a variable of type 'int'. x *= 1.2; +// ^^^ +// [diag.invalidAssignment] A value of type 'double' can't be assigned to a variable of type 'int'. x %= 1.2; +// ^^^ +// [diag.invalidAssignment] A value of type 'double' can't be assigned to a variable of type 'int'. } -''', - [ - error(diag.invalidAssignment, 23, 3), - error(diag.invalidAssignment, 35, 3), - error(diag.invalidAssignment, 47, 3), - error(diag.invalidAssignment, 59, 3), - ], - ); +'''); assertType(findNode.assignment('+='), 'double'); assertType(findNode.assignment('-='), 'double'); assertType(findNode.assignment('*='), 'double'); @@ -4740,7 +4662,7 @@ void f(int x) { } test_simpleIdentifier_parameter_compound_refineType_int_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { x += 1; x -= 1; @@ -4757,7 +4679,7 @@ void f(int x) { } test_simpleIdentifier_parameter_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(num x) { x = 2; } @@ -4786,7 +4708,7 @@ AssignmentExpression } test_simpleIdentifier_parameter_simple_context() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object x) { if (x is double) { x = 1; @@ -4817,14 +4739,13 @@ AssignmentExpression } test_simpleIdentifier_parameter_simple_notAssignableType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int x) { x = true; +// ^^^^ +// [diag.invalidAssignment] A value of type 'bool' can't be assigned to a variable of type 'int'. } -''', - [error(diag.invalidAssignment, 22, 4)], - ); +'''); var assignment = findNode.assignment('x = true'); @@ -4849,15 +4770,14 @@ AssignmentExpression } test_simpleIdentifier_parameterFinal_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' // @dart = 3.10 void f(final int x) { x = 2; +//^ +// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once. } -''', - [error(diag.assignmentToFinalLocal, 40, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -4882,25 +4802,23 @@ AssignmentExpression } test_simpleIdentifier_staticGetter_superSetter_simple() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { set x(num _) {} } class B extends A { static int get x => 1; +// ^ +// [diag.conflictingStaticAndInstance] Class 'B' can't define static member 'x' and have instance member 'A.x' with the same name. void f() { x = 2; +// ^ +// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'B'. } } -''', - [ - error(diag.conflictingStaticAndInstance, 68, 1), - error(diag.assignmentToFinalNoSetter, 94, 1), - ], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -5223,7 +5141,7 @@ AssignmentExpression } test_simpleIdentifier_topGetter_topSetter_compound() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' int get x => 0; set x(num _) {} @@ -5255,10 +5173,11 @@ AssignmentExpression } test_simpleIdentifier_topGetter_topSetter_compound_ifNull2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' void f() { x ??= C(); +// ^^^ +// [diag.invalidAssignment] A value of type 'C' can't be assigned to a variable of type 'B?'. } class A {} @@ -5267,9 +5186,7 @@ class C extends A {} B? get x => B(); set x(B? _) {} -''', - [error(diag.invalidAssignment, 19, 3)], - ); +'''); var assignment = findNode.assignment('x ??='); @@ -5302,7 +5219,7 @@ AssignmentExpression } test_simpleIdentifier_topGetter_topSetter_fromClass_compound() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' int get x => 0; set x(num _) {} @@ -5336,7 +5253,7 @@ AssignmentExpression } test_simpleIdentifier_topLevelVariable_simple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' num x = 0; void f() { @@ -5367,16 +5284,15 @@ AssignmentExpression } test_simpleIdentifier_topLevelVariable_simple_notAssignableType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int x = 0; void f() { x = true; +// ^^^^ +// [diag.invalidAssignment] A value of type 'bool' can't be assigned to a variable of type 'int'. } -''', - [error(diag.invalidAssignment, 29, 4)], - ); +'''); var assignment = findNode.assignment('x = true'); @@ -5401,16 +5317,15 @@ AssignmentExpression } test_simpleIdentifier_topLevelVariableFinal_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' final num x = 0; void f() { x = 2; +//^ +// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final. } -''', - [error(diag.assignmentToFinal, 31, 1)], - ); +'''); var assignment = findNode.assignment('x = 2'); @@ -5435,14 +5350,13 @@ AssignmentExpression } test_simpleIdentifier_typeLiteral_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int += 3; +//^^^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 13, 3)], - ); +'''); var assignment = findNode.assignment('int += 3'); @@ -5467,14 +5381,13 @@ AssignmentExpression } test_simpleIdentifier_typeLiteral_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int = 0; +//^^^ +// [diag.assignmentToType] Types can't be assigned a value. } -''', - [error(diag.assignmentToType, 13, 3)], - ); +'''); var assignment = findNode.assignment('int = 0'); @@ -5499,14 +5412,13 @@ AssignmentExpression } test_simpleIdentifier_unresolved_compound() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { x += 1; +//^ +// [diag.undefinedIdentifier] Undefined name 'x'. } -''', - [error(diag.undefinedIdentifier, 13, 1)], - ); +'''); var assignment = findNode.assignment('x += 1'); @@ -5531,14 +5443,13 @@ AssignmentExpression } test_simpleIdentifier_unresolved_simple() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int a) { x = a; +//^ +// [diag.undefinedIdentifier] Undefined name 'x'. } -''', - [error(diag.undefinedIdentifier, 18, 1)], - ); +'''); var assignment = findNode.assignment('x = a'); @@ -5567,7 +5478,7 @@ AssignmentExpression @reflectiveTest class InferenceUpdate3Test extends PubPackageResolutionTest { test_ifNull_contextIsConvertedToATypeUsingGreatestClosure() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B1 extends A {} class B2 extends A {} @@ -5608,7 +5519,7 @@ f(Object? o, C2 c2) { } test_ifNull_contextNotUsedIfLhsDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f(Object? o1, Object? o2, int? i) { if (o1 is int? && o2 is double?) { o1 = (o2 ??= i); @@ -5640,7 +5551,7 @@ f(Object? o1, Object? o2, int? i) { } test_ifNull_contextUsedInsteadOfLubIfLubDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B1 extends A {} class B2 extends A {} diff --git a/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart b/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart index 767f901452c..05990782b3c 100644 --- a/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import 'context_collection_resolution.dart'; +import 'node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(AstRewriteImplicitCallReferenceTest); defineReflectiveTests(AstRewriteMethodInvocationTest); defineReflectiveTests(AstRewritePrefixedIdentifierTest); + defineReflectiveTests(UpdateNodeTextExpectations); // TODO(srawlins): Add AstRewriteInstanceCreationExpressionTest test, likely // moving many test cases from ConstructorReferenceResolutionTest, @@ -26,7 +27,7 @@ main() { @reflectiveTest class AstRewriteImplicitCallReferenceTest extends PubPackageResolutionTest { test_assignment_indexExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -78,7 +79,7 @@ ImplicitCallReference } test_conditional_else() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} abstract class C extends A { void call(); @@ -110,7 +111,7 @@ ConditionalExpression } test_conditional_then() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} abstract class C extends A { void call(); @@ -142,7 +143,7 @@ ConditionalExpression } test_explicitTypeArguments() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C { T call(T t) => t; } @@ -176,20 +177,18 @@ ImplicitCallReference } test_ifNull_lhs() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A {} abstract class C extends A { void call(); } void Function() f(A a, bool b, C c, dynamic d) => b ? d : c ?? a; -''', - [ - error(diag.deadCode, 127, 4), - error(diag.deadNullAwareExpression, 130, 1), - ], - ); +// ^^^^ +// [diag.deadCode] Dead code. +// ^ +// [diag.deadNullAwareExpression] The left operand can't be null, so the right operand is never executed. +'''); // `c` is on the LHS of an if-null expression, so implicit call tearoff // logic should not apply to it. // Therefore the type of `c ?? a` should be `A`. @@ -213,7 +212,7 @@ BinaryExpression } test_ifNull_rhs() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -246,7 +245,7 @@ ImplicitCallReference } test_listLiteral_element() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -269,7 +268,7 @@ ImplicitCallReference } test_listLiteral_forElement() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -294,7 +293,7 @@ ImplicitCallReference } test_listLiteral_ifElement() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -319,7 +318,7 @@ ImplicitCallReference } test_listLiteral_ifElement_else() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -345,7 +344,7 @@ ImplicitCallReference } test_parenthesized_cascade_target() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(); void m(); @@ -384,7 +383,7 @@ ImplicitCallReference } test_prefixedIdentifier() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { C get c; void call(int t) => t; @@ -416,7 +415,7 @@ ImplicitCallReference } test_propertyAccess() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { C get c; void call(int t) => t; @@ -455,7 +454,7 @@ ImplicitCallReference } test_setOrMapLiteral_element() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -478,7 +477,7 @@ ImplicitCallReference } test_setOrMapLiteral_mapLiteralEntry_key() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -501,7 +500,7 @@ ImplicitCallReference } test_setOrMapLiteral_mapLiteralEntry_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -524,7 +523,7 @@ ImplicitCallReference } test_simpleIdentifier() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class C { void call(int t) => t; } @@ -547,7 +546,7 @@ ImplicitCallReference } test_simpleIdentifier_typeAlias() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { void call() {} } @@ -569,7 +568,7 @@ ImplicitCallReference } test_simpleIdentifier_typeVariable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { void call() {} } @@ -589,7 +588,7 @@ ImplicitCallReference } test_simpleIdentifier_typeVariable2() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A { void call() {} } @@ -609,15 +608,14 @@ ImplicitCallReference } test_simpleIdentifier_typeVariable2_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void call() {} } Function f(Y y) => y; -''', - [error(diag.returnOfInvalidTypeFromFunction, 75, 1)], - ); +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'Y' can't be returned from the function 'f' because it has a return type of 'Function'. +'''); // Verify that no ImplicitCallReference was inserted. var node = findNode.expressionFunctionBody('y;').expression; @@ -630,15 +628,14 @@ SimpleIdentifier } test_simpleIdentifier_typeVariable_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A { void call() {} } Function f(X? x) => x; -''', - [error(diag.returnOfInvalidTypeFromFunction, 62, 1)], - ); +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'X?' can't be returned from the function 'f' because it has a return type of 'Function'. +'''); // Verify that no ImplicitCallReference was inserted. var node = findNode.expressionFunctionBody('x;').expression; @@ -657,7 +654,7 @@ class AstRewriteMethodInvocationTest extends PubPackageResolutionTest mixin AstRewriteMethodInvocationTestCases on PubPackageResolutionTest { test_targetNull_cascade() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void foo() {} } @@ -684,7 +681,7 @@ MethodInvocation } test_targetNull_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int a); } @@ -732,7 +729,7 @@ InstanceCreationExpression } test_targetNull_extension() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} extension E on A { @@ -743,7 +740,6 @@ f(A a) { E(a).foo(); } '''); - var node = findNode.extensionOverride('E(a)'); assertResolvedNodeText(node, r''' ExtensionOverride @@ -774,14 +770,13 @@ ExtensionOverride } test_targetNull_function() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void A(int a) {} f() { A(0); } '''); - var node = findNode.methodInvocation('A(0);'); assertResolvedNodeText(node, r''' MethodInvocation @@ -820,7 +815,7 @@ MethodInvocation } test_targetNull_typeAlias_interfaceType() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(int _); } @@ -831,7 +826,6 @@ void f() { X(0); } '''); - var node = findNode.instanceCreation('X(0);'); assertResolvedNodeText(node, r''' InstanceCreationExpression @@ -870,17 +864,15 @@ InstanceCreationExpression } test_targetNull_typeAlias_Never() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef X = Never; void f() { X(0); +//^ +// [diag.invocationOfNonFunction] 'X' isn't a function. } -''', - [error(diag.invocationOfNonFunction, 33, 1)], - ); - +'''); // Not rewritten. findNode.methodInvocation('X(0)'); } @@ -892,14 +884,13 @@ class A { } '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f() { prefix.A.named(0); } '''); - var node = findNode.instanceCreation('A.named(0);'); assertResolvedNodeText(node, r''' InstanceCreationExpression @@ -943,24 +934,15 @@ class A { } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f() { prefix.A.named(0); +// ^^^^^ +// [diag.wrongNumberOfTypeArgumentsConstructor] The constructor 'prefix.A.named' doesn't have type parameters. } -''', - [ - error( - diag.wrongNumberOfTypeArgumentsConstructor, - 50, - 5, - messageContains: ["The constructor 'prefix.A.named'"], - ), - ], - ); - +'''); var node = findNode.instanceCreation('named(0);'); assertResolvedNodeText(node, r''' InstanceCreationExpression @@ -1012,24 +994,15 @@ class A { } '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f() { prefix.A.new(0); +// ^^^^^ +// [diag.wrongNumberOfTypeArgumentsConstructor] The constructor 'prefix.A.new' doesn't have type parameters. } -''', - [ - error( - diag.wrongNumberOfTypeArgumentsConstructor, - 48, - 5, - messageContains: ["The constructor 'prefix.A.new'"], - ), - ], - ); - +'''); var node = findNode.instanceCreation('new(0);'); assertResolvedNodeText(node, r''' InstanceCreationExpression @@ -1083,14 +1056,13 @@ class A { } '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f() { prefix.foo.bar(0); } '''); - var node = findNode.methodInvocation('bar(0);'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1133,14 +1105,13 @@ class A { typedef X = A; '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; void f() { prefix.X.named(0); } '''); - var node = findNode.instanceCreation('X.named(0);'); assertResolvedNodeText(node, r''' InstanceCreationExpression @@ -1178,7 +1149,7 @@ InstanceCreationExpression } test_targetSimpleIdentifier_class_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named(T a); } @@ -1221,25 +1192,17 @@ InstanceCreationExpression } test_targetSimpleIdentifier_class_constructor_typeArguments() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named(int a); } f() { A.named(0); +// ^^^^^^^^^^^^^ +// [diag.wrongNumberOfTypeArgumentsConstructor] The constructor 'A.named' doesn't have type parameters. } -''', - [ - error( - diag.wrongNumberOfTypeArgumentsConstructor, - 52, - 13, - messageContains: ["The constructor 'A.named'"], - ), - ], - ); +'''); // TODO(scheglov): Move type arguments var node = findNode.instanceCreation('named(0);'); @@ -1287,25 +1250,17 @@ InstanceCreationExpression } test_targetSimpleIdentifier_class_constructor_typeArguments_new() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.new(int a); } f() { A.new(0); +// ^^^^^^^^^^^^^ +// [diag.wrongNumberOfTypeArgumentsConstructor] The constructor 'A.new' doesn't have type parameters. } -''', - [ - error( - diag.wrongNumberOfTypeArgumentsConstructor, - 48, - 13, - messageContains: ["The constructor 'A.new'"], - ), - ], - ); +'''); // TODO(scheglov): Move type arguments var node = findNode.instanceCreation('new(0);'); @@ -1353,7 +1308,7 @@ InstanceCreationExpression } test_targetSimpleIdentifier_class_staticMethod() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static void foo(int a) {} } @@ -1362,7 +1317,6 @@ f() { A.foo(0); } '''); - var node = findNode.methodInvocation('foo(0);'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1395,14 +1349,13 @@ class A { } '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f() { prefix.A(0); } '''); - var node = findNode.instanceCreation('A(0);'); assertResolvedNodeText(node, r''' InstanceCreationExpression @@ -1453,14 +1406,13 @@ extension E on A { } '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f(prefix.A a) { prefix.E(a).foo(); } '''); - var node = findNode.extensionOverride('E(a)'); assertResolvedNodeText(node, r''' ExtensionOverride @@ -1499,7 +1451,7 @@ ExtensionOverride void A(int a) {} '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart' as prefix; f() { @@ -1550,7 +1502,7 @@ MethodInvocation } test_targetSimpleIdentifier_typeAlias_interfaceType_constructor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.named(T a); } @@ -1598,16 +1550,15 @@ InstanceCreationExpression @reflectiveTest class AstRewritePrefixedIdentifierTest extends PubPackageResolutionTest { test_constructorReference_inAssignment_onLeftSide() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class C {} void f() { C.new = 1; +// ^^^ +// [diag.undefinedSetter] The setter 'new' isn't defined for the type 'C'. } -''', - [error(diag.undefinedSetter, 27, 3)], - ); +'''); var identifier = findNode.prefixed('C.new'); // The left side of the assignment is resolved by @@ -1619,7 +1570,7 @@ void f() { } test_constructorReference_inAssignment_onRightSide() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class C {} Function? f; diff --git a/pkg/analyzer/test/src/dart/resolution/augmented_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/augmented_expression_test.dart deleted file mode 100644 index a24d1e91b3c..00000000000 --- a/pkg/analyzer/test/src/dart/resolution/augmented_expression_test.dart +++ /dev/null @@ -1,321 +0,0 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'context_collection_resolution.dart'; - -main() { - defineReflectiveSuite(() { - // TODO(scheglov): implement augmentation - // defineReflectiveTests(AugmentedExpressionResolutionTest); - }); -} - -@reflectiveTest -class AugmentedExpressionResolutionTest extends PubPackageResolutionTest { - test_class_field() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -class A { - num foo = 0; -} -'''); - - await assertNoErrorsInCode(''' -part of 'a.dart'; - -augment class A { - augment num foo = augmented; -} -'''); - - var node = findNode.singleVariableDeclaration.initializer!; - assertResolvedNodeText(node, r''' -AugmentedExpression - augmentedKeyword: augmented - element: package:test/a.dart::::@class::A::@field::foo - fragment: package:test/a.dart::::@class::A::@field::foo - staticType: int -'''); - } - - test_class_getter() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -class A { - int get foo => 0; -} -'''); - - await assertNoErrorsInCode(''' -part of 'a.dart'; - -augment class A { - augment int get foo { - return augmented; - } -} -'''); - - var node = findNode.singleReturnStatement; - assertResolvedNodeText(node, r''' -ReturnStatement - returnKeyword: return - expression: AugmentedExpression - augmentedKeyword: augmented - element: package:test/a.dart::::@class::A::@getter::foo - fragment: package:test/a.dart::::@class::A::@getter::foo - staticType: int - semicolon: ; -'''); - } - - test_class_setter() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -class A { - set foo(int _) {} -} -'''); - - await assertNoErrorsInCode(''' -part of 'a.dart'; - -augment class A { - augment set foo(int _) { - augmented = 0; - } -} -'''); - - var node = findNode.singleBlock; - // TODO(scheglov): implement augmentation - assertResolvedNodeText(node, r''' -Block - leftBracket: { - statements - ExpressionStatement - expression: AssignmentExpression - leftHandSide: AugmentedExpression - augmentedKeyword: augmented - element: package:test/a.dart::::@class::A::@setter::foo - fragment: package:test/a.dart::::@class::A::@setter::foo - staticType: null - operator: = - rightHandSide: IntegerLiteral - literal: 0 - parameter: package:test/a.dart::::@class::A::@setter::foo::@parameter::_ - staticType: int - readElement: - readElement2: - readType: null - writeElement: package:test/a.dart::@fragment::package:test/test.dart::@classAugmentation::A::@setterAugmentation::foo - writeElement2: package:test/a.dart::::@class::A::@setter::foo#element - writeType: int - staticElement: - element: - staticType: int - semicolon: ; - rightBracket: } -'''); - } - - test_class_setter_inGetter() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -class A { - int foo = 0; -} -'''); - - await assertErrorsInCode( - ''' -part of 'a.dart'; - -augment class A { - augment int get foo { - augmented = 0; - return 0; - } -} -''', - [error(diag.augmentedExpressionIsNotSetter, 65, 9)], - ); - - var node = findNode.singleAssignmentExpression; - assertResolvedNodeText(node, r''' -AssignmentExpression - leftHandSide: AugmentedExpression - augmentedKeyword: augmented - element: - fragment: - staticType: null - operator: = - rightHandSide: IntegerLiteral - literal: 0 - parameter: - staticType: int - readElement: - readElement2: - readType: null - writeElement: - writeElement2: - writeType: InvalidType - staticElement: - element: - staticType: int -'''); - } - - test_class_setter_inMethod() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -class A { - void foo() {} -} -'''); - - await assertErrorsInCode( - ''' -part of 'a.dart'; - -augment class A { - augment void foo() { - augmented = 0; - } -} -''', - [error(diag.augmentedExpressionIsNotSetter, 64, 9)], - ); - - var node = findNode.singleAssignmentExpression; - assertResolvedNodeText(node, r''' -AssignmentExpression - leftHandSide: AugmentedExpression - augmentedKeyword: augmented - element: - fragment: - staticType: null - operator: = - rightHandSide: IntegerLiteral - literal: 0 - parameter: - staticType: int - readElement: - readElement2: - readType: null - writeElement: - writeElement2: - writeType: InvalidType - staticElement: - element: - staticType: int -'''); - } - - test_topLevel_getter() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -int get foo => 0; -'''); - - await assertNoErrorsInCode(''' -part of 'a.dart'; - -augment int get foo { - return augmented; -} -'''); - - var node = findNode.singleReturnStatement; - assertResolvedNodeText(node, r''' -ReturnStatement - returnKeyword: return - expression: AugmentedExpression - augmentedKeyword: augmented - element: package:test/a.dart::::@getter::foo - fragment: package:test/a.dart::::@getter::foo - staticType: int - semicolon: ; -'''); - } - - test_topLevel_setter() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -set foo(int _) {} -'''); - - await assertNoErrorsInCode(''' -part of 'a.dart'; - -augment set foo(int _) { - augmented = 0; -} -'''); - - var node = findNode.singleBlock; - // TODO(scheglov): implement augmentation - assertResolvedNodeText(node, r''' -Block - leftBracket: { - statements - ExpressionStatement - expression: AssignmentExpression - leftHandSide: AugmentedExpression - augmentedKeyword: augmented - element: package:test/a.dart::::@setter::foo - fragment: package:test/a.dart::::@setter::foo - staticType: null - operator: = - rightHandSide: IntegerLiteral - literal: 0 - parameter: package:test/a.dart::::@setter::foo::@parameter::_ - staticType: int - readElement: - readElement2: - readType: null - writeElement: package:test/a.dart::@fragment::package:test/test.dart::@setterAugmentation::foo - writeElement2: package:test/a.dart::::@setter::foo#element - writeType: int - staticElement: - element: - staticType: int - semicolon: ; - rightBracket: } -'''); - } - - test_topLevel_variable() async { - newFile('$testPackageLibPath/a.dart', r''' -part 'test.dart'; - -num foo = 0; -'''); - - await assertNoErrorsInCode(''' -part of 'a.dart'; - -augment num foo = augmented; -'''); - - var node = findNode.singleVariableDeclaration.initializer!; - assertResolvedNodeText(node, r''' -AugmentedExpression - augmentedKeyword: augmented - element: package:test/a.dart::::@topLevelVariable::foo - fragment: package:test/a.dart::::@topLevelVariable::foo - staticType: int -'''); - } -} diff --git a/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart index 1b36e6c7352..2a6b672cc37 100644 --- a/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart @@ -2,75 +2,70 @@ // 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 'context_collection_resolution.dart'; +import 'node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(AwaitExpressionResolutionTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class AwaitExpressionResolutionTest extends PubPackageResolutionTest { test_future() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(Future a) async { await a; } '''); - assertType(findNode.awaitExpression('await a'), 'int'); } test_futureOr() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; f(FutureOr a) async { await a; } '''); - assertType(findNode.awaitExpression('await a'), 'int'); } test_futureOrQ() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; f(FutureOr? a) async { await a; } '''); - assertType(findNode.awaitExpression('await a'), 'int?'); } test_futureQ() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(Future? a) async { await a; } '''); - assertType(findNode.awaitExpression('await a'), 'int?'); } test_super() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void f() async { await super; +// ^^^^^ +// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'. } } -''', - [error(diag.missingAssignableSelector, 39, 5)], - ); - +'''); var node = findNode.singleAwaitExpression; assertResolvedNodeText(node, r''' AwaitExpression @@ -83,7 +78,7 @@ AwaitExpression } test_super_property() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { void f() async { await super.hashCode; @@ -110,14 +105,13 @@ AwaitExpression } test_unresolved_identifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() async { await unresolved; +// ^^^^^^^^^^ +// [diag.undefinedIdentifier] Undefined name 'unresolved'. } -''', - [error(diag.undefinedIdentifier, 25, 10)], - ); +'''); var node = findNode.singleAwaitExpression; assertResolvedNodeText(node, r''' @@ -132,16 +126,15 @@ AwaitExpression } test_unresolved_prefixedIdentifier() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:math' as prefix; void f() async { await prefix.unresolved; +// ^^^^^^^^^^ +// [diag.undefinedPrefixedName] The name 'unresolved' is being referenced through the prefix 'prefix', but it isn't defined in any of the libraries imported using that prefix. } -''', - [error(diag.undefinedPrefixedName, 63, 10)], - ); +'''); var node = findNode.singleAwaitExpression; assertResolvedNodeText(node, r''' @@ -164,14 +157,13 @@ AwaitExpression } test_unresolved_propertyAccess() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() async { await 0.isEven.unresolved; +// ^^^^^^^^^^ +// [diag.undefinedGetter] The getter 'unresolved' isn't defined for the type 'bool'. } -''', - [error(diag.undefinedGetter, 34, 10)], - ); +'''); var node = findNode.singleAwaitExpression; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart index ffcf978746a..327bfb9d625 100644 --- a/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart @@ -20,7 +20,7 @@ main() { class BinaryExpressionResolutionTest extends PubPackageResolutionTest with BinaryExpressionResolutionTestCases { test_eqEq_alwaysBool() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type MyBool(bool it) implements bool {} class A { @@ -31,7 +31,6 @@ void f(A a) { a == 0; } '''); - var node = findNode.binary('a == 0'); assertResolvedNodeText(node, r''' BinaryExpression @@ -51,14 +50,13 @@ BinaryExpression } test_eqEq_switchExpression_left() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { (switch (x) { _ => 1, } == 0); } '''); - var node = findNode.binary('== 0'); assertResolvedNodeText(node, r''' BinaryExpression @@ -95,14 +93,13 @@ BinaryExpression } test_eqEq_switchExpression_right() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { 0 == switch (x) { _ => 1, }; } '''); - var node = findNode.binary('0 =='); assertResolvedNodeText(node, r''' BinaryExpression @@ -139,7 +136,7 @@ BinaryExpression } test_expression_recordType_hasOperator() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f((String,) a) { a + 0; } @@ -148,7 +145,6 @@ extension on (String,) { int operator +(int other) => 0; } '''); - var node = findNode.binary('+ 0'); assertResolvedNodeText(node, r''' BinaryExpression @@ -168,15 +164,13 @@ BinaryExpression } test_expression_recordType_noOperator() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f((String,) a) { a + 0; +// ^ +// [diag.undefinedOperator] The operator '+' isn't defined for the type '(String,)'. } -''', - [error(diag.undefinedOperator, 26, 1)], - ); - +'''); var node = findNode.binary('+ 0'); assertResolvedNodeText(node, r''' BinaryExpression @@ -196,7 +190,7 @@ BinaryExpression } test_gtGtGt() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A operator >>>(int amount) => this; } @@ -205,7 +199,6 @@ void f(A a) { a >>> 3; } '''); - var node = findNode.singleBinaryExpression; assertResolvedNodeText(node, r''' BinaryExpression @@ -225,7 +218,7 @@ BinaryExpression } test_ifNull_left_nullableContext() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' T f(T t) => t; int g() => f(null) ?? 0; @@ -264,7 +257,7 @@ BinaryExpression } test_ifNull_lubUsedEvenIfItDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' // @dart=3.3 class A {} class B1 extends A {} @@ -298,7 +291,7 @@ BinaryExpression } test_ifNull_nullableInt_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? x, int y) { x ?? y; } @@ -323,7 +316,7 @@ BinaryExpression } test_ifNull_nullableInt_nullableDouble() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? x, double? y) { x ?? y; } @@ -348,7 +341,7 @@ BinaryExpression } test_ifNull_nullableInt_nullableInt() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? x) { x ?? x; } @@ -373,7 +366,7 @@ BinaryExpression } test_plus_extensionType_int() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' extension type Int(int i) implements int { Int operator +(int other) { return Int(i + other); @@ -405,7 +398,7 @@ BinaryExpression } test_plus_int_never() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f(int a, Never b) { a + b; } @@ -430,14 +423,15 @@ BinaryExpression } test_plus_never_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f(Never a, int b) { a + b; +//^ +// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value. +// ^^^ +// [diag.deadCode] Dead code. } -''', - [error(diag.receiverOfTypeNever, 22, 1), error(diag.deadCode, 24, 3)], - ); +'''); assertResolvedNodeText(findNode.binary('a + b'), r''' BinaryExpression @@ -458,7 +452,7 @@ BinaryExpression } test_plus_switchExpression_left() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { (switch (x) { _ => 1, @@ -502,7 +496,7 @@ BinaryExpression } test_plus_switchExpression_right() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object? x) { 0 + switch (x) { _ => 1, @@ -546,18 +540,17 @@ BinaryExpression } test_star_syntheticOperand_both() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { final v = * ; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. +// ^ +// [diag.missingIdentifier] Expected an identifier. +// ^ +// [diag.missingIdentifier] Expected an identifier. } -''', - [ - error(diag.unusedLocalVariable, 19, 1), - error(diag.missingIdentifier, 23, 1), - error(diag.missingIdentifier, 25, 1), - ], - ); +'''); var node = findNode.singleBinaryExpression; assertResolvedNodeText(node, r''' @@ -579,17 +572,15 @@ BinaryExpression } test_star_syntheticOperand_left() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { final v = * 2; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. +// ^ +// [diag.missingIdentifier] Expected an identifier. } -''', - [ - error(diag.unusedLocalVariable, 19, 1), - error(diag.missingIdentifier, 23, 1), - ], - ); +'''); var node = findNode.singleBinaryExpression; assertResolvedNodeText(node, r''' @@ -610,17 +601,15 @@ BinaryExpression } test_star_syntheticOperand_right() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { final v = 2 * ; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. +// ^ +// [diag.missingIdentifier] Expected an identifier. } -''', - [ - error(diag.unusedLocalVariable, 19, 1), - error(diag.missingIdentifier, 27, 1), - ], - ); +'''); var node = findNode.singleBinaryExpression; assertResolvedNodeText(node, r''' @@ -641,7 +630,7 @@ BinaryExpression } test_superQualifier_plus() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +(int other) => 0; } @@ -673,7 +662,7 @@ BinaryExpression } test_thisExpression_plus() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator +(int other) => 0; @@ -1197,17 +1186,15 @@ MethodInvocation } test_plus_double_context_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(double a) { h(a + f()); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'double' can't be assigned to the parameter type 'int'. } h(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 45, 7)], - ); - +'''); var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1227,13 +1214,12 @@ MethodInvocation } test_plus_double_context_none() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(double a) { a + f(); } '''); - var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1253,12 +1239,11 @@ MethodInvocation } test_plus_double_dynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(double a, dynamic b) { a + b; } '''); - assertResolvedNodeText(findNode.binary('a + b'), r''' BinaryExpression leftOperand: SimpleIdentifier @@ -1278,14 +1263,13 @@ BinaryExpression } test_plus_int_context_double() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int a) { h(a + f()); } h(double x) {} '''); - var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1305,14 +1289,13 @@ MethodInvocation } test_plus_int_context_int() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int a) { h(a + f()); } h(int x) {} '''); - var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1332,14 +1315,13 @@ MethodInvocation } test_plus_int_context_int_target_rewritten() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int Function() a) { h(a() + f()); } h(int x) {} '''); - var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1359,20 +1341,18 @@ MethodInvocation } test_plus_int_context_int_via_extension_explicit() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' extension E on int { String operator+(num x) => ''; } T f() => throw Error(); g(int a) { h(E(a) + f()); +// ^^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } h(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 98, 10)], - ); - +'''); var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1392,13 +1372,12 @@ MethodInvocation } test_plus_int_context_none() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int a) { a + f(); } '''); - var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' MethodInvocation @@ -1418,12 +1397,11 @@ MethodInvocation } test_plus_int_double() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, double b) { a + b; } '''); - assertResolvedNodeText(findNode.binary('a + b'), r''' BinaryExpression leftOperand: SimpleIdentifier @@ -1443,12 +1421,11 @@ BinaryExpression } test_plus_int_dynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, dynamic b) { a + b; } '''); - assertResolvedNodeText(findNode.binary('a + b'), r''' BinaryExpression leftOperand: SimpleIdentifier @@ -1468,12 +1445,11 @@ BinaryExpression } test_plus_int_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, int b) { a + b; } '''); - assertResolvedNodeText(findNode.binary('a + b'), r''' BinaryExpression leftOperand: SimpleIdentifier @@ -1493,12 +1469,11 @@ BinaryExpression } test_plus_int_int_target_rewritten() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' f(int Function() a, int b) { a() + b; } '''); - assertResolvedNodeText(findNode.binary('a() + b'), r''' BinaryExpression leftOperand: FunctionExpressionInvocation @@ -1525,7 +1500,7 @@ BinaryExpression } test_plus_int_int_via_extension_explicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' extension E on int { String operator+(int other) => ''; } @@ -1533,7 +1508,6 @@ f(int a, int b) { E(a) + b; } '''); - assertResolvedNodeText(findNode.binary('E(a) + b'), r''' BinaryExpression leftOperand: ExtensionOverride @@ -1563,12 +1537,11 @@ BinaryExpression } test_plus_int_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, num b) { a + b; } '''); - assertResolvedNodeText(findNode.binary('a + b'), r''' BinaryExpression leftOperand: SimpleIdentifier @@ -1588,7 +1561,7 @@ BinaryExpression } test_plus_int_typeVariable_via_extension() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class Foo {} extension FooExtension on F { @@ -1597,7 +1570,6 @@ extension FooExtension on F { F get gg => this + 1; } '''); - assertResolvedNodeText(findNode.binary('this + 1'), r''' BinaryExpression leftOperand: ThisExpression @@ -1617,15 +1589,13 @@ BinaryExpression } test_plus_invalidType_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { x + 0; +//^ +// [diag.undefinedIdentifier] Undefined name 'x'. } -''', - [error(diag.undefinedIdentifier, 13, 1)], - ); - +'''); var node = findNode.binary('x + 0'); assertResolvedNodeText(node, r''' BinaryExpression @@ -1645,16 +1615,15 @@ BinaryExpression } test_plus_num_context_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(num a) { h(a + f()); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'num' can't be assigned to the parameter type 'int'. } h(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 42, 7)], - ); +'''); var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' @@ -1675,19 +1644,18 @@ MethodInvocation } test_plus_other_context_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' abstract class A { num operator+(String x); } T f() => throw Error(); g(A a) { h(a + f()); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'num' can't be assigned to the parameter type 'int'. } h(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 88, 7)], - ); +'''); var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' @@ -1708,8 +1676,7 @@ MethodInvocation } test_plus_other_context_int_via_extension_explicit() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} extension E on A { String operator+(num x) => ''; @@ -1717,11 +1684,11 @@ extension E on A { T f() => throw Error(); g(A a) { h(E(a) + f()); +// ^^^^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } h(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 105, 10)], - ); +'''); var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' @@ -1742,8 +1709,7 @@ MethodInvocation } test_plus_other_context_int_via_extension_implicit() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' class A {} extension E on A { String operator+(num x) => ''; @@ -1751,11 +1717,11 @@ extension E on A { T f() => throw Error(); g(A a) { h(a + f()); +// ^^^^^^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'. } h(int x) {} -''', - [error(diag.argumentTypeNotAssignable, 105, 7)], - ); +'''); var node = findNode.methodInvocation('f()'); assertResolvedNodeText(node, r''' @@ -1776,7 +1742,7 @@ MethodInvocation } test_plus_other_double() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' abstract class A { String operator+(double other); } @@ -1804,7 +1770,7 @@ BinaryExpression } test_plus_other_int_via_extension_explicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} extension E on A { String operator+(int other) => ''; @@ -1843,7 +1809,7 @@ BinaryExpression } test_plus_other_int_via_extension_implicit() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} extension E on A { String operator+(int other) => ''; @@ -1872,7 +1838,7 @@ BinaryExpression } test_receiverTypeParameter_bound_dynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(T a) { a + 0; } @@ -1896,7 +1862,7 @@ BinaryExpression } test_receiverTypeParameter_bound_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(T a) { a + 0; } @@ -1920,7 +1886,7 @@ BinaryExpression } test_slash() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, int b) { a / b; } @@ -1945,7 +1911,7 @@ BinaryExpression } test_star_int_context_int() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' T f() => throw Error(); g(int a) { h(a * f()); @@ -1972,7 +1938,7 @@ MethodInvocation } test_star_int_double() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, double b) { a * b; } @@ -1997,7 +1963,7 @@ BinaryExpression } test_star_int_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f(int a, int b) { a * b; } @@ -2025,7 +1991,7 @@ BinaryExpression @reflectiveTest class InferenceUpdate3Test extends PubPackageResolutionTest { test_ifNull_contextIsConvertedToATypeUsingGreatestClosure() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B1 extends A {} class B2 extends A {} @@ -2058,7 +2024,7 @@ f(C1? c1, C2 c2) { } test_ifNull_contextNotUsedIfLhsDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B1 extends A {} class B2 extends A {} @@ -2090,7 +2056,7 @@ f(B2? b2, C1 c1, Object? o) { } test_ifNull_contextNotUsedIfRhsDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B1 extends A {} class B2 extends A {} @@ -2122,7 +2088,7 @@ f(C1? c1, B2 b2, Object? o) { } test_ifNull_contextUsedInsteadOfLubIfLubDoesNotSatisfyContext() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' class A {} class B1 extends A {} class B2 extends A {} diff --git a/pkg/analyzer/test/src/dart/resolution/test_all.dart b/pkg/analyzer/test/src/dart/resolution/test_all.dart index 8ba4e7d68f2..720b730c000 100644 --- a/pkg/analyzer/test/src/dart/resolution/test_all.dart +++ b/pkg/analyzer/test/src/dart/resolution/test_all.dart @@ -8,7 +8,6 @@ import 'adjacent_strings_test.dart' as adjacent_strings; import 'as_expression_test.dart' as as_expression; import 'assignment_test.dart' as assignment; import 'ast_rewrite_test.dart' as ast_rewrite; -import 'augmented_expression_test.dart' as augmented_expression; import 'await_expression_test.dart' as await_expression; import 'binary_expression_test.dart' as binary_expression; import 'cascade_expression_resolution_test.dart' @@ -129,7 +128,6 @@ main() { as_expression.main(); assignment.main(); ast_rewrite.main(); - augmented_expression.main(); await_expression.main(); binary_expression.main(); cascade_expression_resolution_test.main();