CQ. Migrate resolution tests to resolveTestCodeWithDiagnostics. CD.

Change-Id: I621af89bafde3fc8b3e492482cfe33ece11ad844
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503702
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2026-05-18 08:27:45 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 948e52a768
commit 8a7276fb4d
15 changed files with 1168 additions and 1459 deletions
@@ -17,7 +17,7 @@ main() {
@reflectiveTest
class CascadeExpressionResolutionTest extends PubPackageResolutionTest {
test_nullAware_indexGet_promotableField() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final D? _d;
C(this._d);
@@ -46,7 +46,7 @@ SimpleIdentifier
}
test_nullAware_indexGet_promotableLocal() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
D? get d;
}
@@ -75,7 +75,7 @@ SimpleIdentifier
}
test_nullAware_indexSet_promotableLocal() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
D get d;
void f(int i);
@@ -103,7 +103,7 @@ SimpleIdentifier
}
test_nullAware_methodInvocation_promotableField() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final D? _d;
C(this._d);
@@ -131,7 +131,7 @@ SimpleIdentifier
}
test_nullAware_methodInvocation_promotableLocal() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
D? get d;
}
@@ -158,7 +158,7 @@ SimpleIdentifier
}
test_nullAware_propertyGet_promotableField() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final D? _d;
C(this._d);
@@ -187,7 +187,7 @@ SimpleIdentifier
}
test_nullAware_propertyGet_promotableLocal() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
D? get d;
}
@@ -216,7 +216,7 @@ SimpleIdentifier
}
test_nullAware_propertySet_promotableLocal() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
int? x;
void f(int i);
@@ -2,28 +2,28 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(CastPatternResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class CastPatternResolutionTest extends PubPackageResolutionTest {
test_ifCase() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
if (x case var y as int) {}
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
}
''',
[error(diag.unusedLocalVariable, 29, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
CastPattern
@@ -44,7 +44,7 @@ CastPattern
}
test_switchCase() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
const a = 0;
switch (x) {
@@ -72,14 +72,13 @@ CastPattern
}
test_variableDeclaration() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
var (a as int) = x;
// ^
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
}
''',
[error(diag.unusedLocalVariable, 19, 1)],
);
''');
var node = findNode.singlePatternVariableDeclaration;
assertResolvedNodeText(node, r'''
PatternVariableDeclaration
@@ -2,21 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ClassTypeAliasResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class ClassTypeAliasResolutionTest extends PubPackageResolutionTest {
// solo_test_X() async {
// await assertNoErrorsInCode(r'''
// await resolveTestCodeWithDiagnostics(r'''
// ''');
//
// final node = findNode.singleListLiteral;
@@ -25,7 +26,7 @@ class ClassTypeAliasResolutionTest extends PubPackageResolutionTest {
// }
test_element() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {}
mixin class B {}
class C {}
@@ -63,45 +64,42 @@ ClassTypeAlias
}
test_element_typeFunction_extends() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
mixin class A {}
class X = Function with A;
''',
[error(diag.finalClassExtendedOutsideOfLibrary, 27, 8)],
);
// ^^^^^^^^
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Function' can't be extended outside of its library because it's a final class.
''');
var x = findElement2.class_('X');
assertType(x.supertype, 'Object');
}
test_element_typeFunction_implements() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
mixin class A {}
class B {}
class X = Object with A implements A, Function, B;
''',
[error(diag.finalClassImplementedOutsideOfLibrary, 66, 8)],
);
// ^^^^^^^^
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Function' can't be implemented outside of its library because it's a final class.
''');
var x = findElement2.class_('X');
assertElementTypes(x.interfaces, ['A', 'B']);
}
test_element_typeFunction_with() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
mixin class A {}
mixin class B {}
class X = Object with A, Function, B;
''',
[error(diag.classUsedAsMixin, 59, 8)],
);
// ^^^^^^^^
// [diag.classUsedAsMixin] The class 'Function' can't be used as a mixin because it's neither a mixin class nor a mixin.
''');
var x = findElement2.class_('X');
assertElementTypes(x.mixins, ['A', 'B']);
}
test_implicitConstructors_const() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
}
@@ -115,8 +113,7 @@ const x = const C();
}
test_implicitConstructors_const_field() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
}
@@ -128,16 +125,14 @@ mixin M {
class C = A with M;
const x = const C();
''',
[
error(diag.constWithNonConst, 83, 5),
error(diag.constInitializedWithNonConstantValue, 83, 5),
],
);
// ^^^^^
// [diag.constWithNonConst] The constructor being called isn't a const constructor.
// [diag.constInitializedWithNonConstantValue] Const variables must be initialized with a constant value.
''');
}
test_implicitConstructors_const_getter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
}
@@ -153,7 +148,7 @@ const x = const C();
}
test_implicitConstructors_const_setter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
}
File diff suppressed because it is too large Load Diff
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -24,7 +23,7 @@ class CommentResolutionTest_PrefixedIdentifier
// TODO(srawlins): improve coverage regarding constructors, operators, the
// 'new' keyword, and members on an extension on a type variable
// (`extension <T> on T`).
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
A.named();
}
@@ -51,7 +50,7 @@ CommentReference
}
test_class_constructor_unnamedViaNew() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
A();
}
@@ -78,7 +77,7 @@ CommentReference
}
test_class_instanceGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
int get foo => 0;
}
@@ -105,7 +104,7 @@ CommentReference
}
test_class_instanceGetter_onTypedef() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
int get foo => 0;
}
@@ -133,7 +132,7 @@ CommentReference
}
test_class_instanceMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
void foo() {}
}
@@ -160,7 +159,7 @@ CommentReference
}
test_class_instanceSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
set foo(int _) {}
}
@@ -187,7 +186,7 @@ CommentReference
}
test_class_invalid_ambiguousExtension() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
/// [foo]
class A {}
@@ -210,7 +209,7 @@ CommentReference
}
test_class_invalid_unresolved() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
/// [foo]
class A {}
''');
@@ -225,7 +224,7 @@ CommentReference
}
test_class_staticGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
static int get foo => 0;
}
@@ -252,7 +251,7 @@ CommentReference
}
test_class_staticGetter_onTypedef() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
static int get foo => 0;
}
@@ -281,7 +280,7 @@ CommentReference
}
test_class_staticMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
static void foo() {}
}
@@ -308,7 +307,7 @@ CommentReference
}
test_class_staticSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
static set foo(int _) {}
}
@@ -340,7 +339,7 @@ class A {
A.named();
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -371,7 +370,7 @@ class A {
A();
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -402,7 +401,7 @@ class A {
int get foo => 0;
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -433,7 +432,7 @@ class A {
void foo() {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -464,7 +463,7 @@ class A {
static int get foo => 0;
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -495,7 +494,7 @@ class A {
static void foo() {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -526,7 +525,7 @@ class A {
static set foo(int _) {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -557,7 +556,7 @@ extension E on int {
int get foo => 0;
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -588,7 +587,7 @@ extension E on int {
void foo() {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -619,7 +618,7 @@ extension E on int {
set foo(int _) {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -650,7 +649,7 @@ extension E on int {
static int get foo => 0;
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -681,7 +680,7 @@ extension E on int {
static void foo() {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -712,7 +711,7 @@ extension E on int {
static set foo(int _) {}
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -738,7 +737,7 @@ CommentReference
}
test_extension_instanceGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E on int {
int get foo => 0;
}
@@ -765,7 +764,7 @@ CommentReference
}
test_extension_instanceMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E on int {
void foo() {}
}
@@ -792,7 +791,7 @@ CommentReference
}
test_extension_instanceSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E on int {
set foo(int _) {}
}
@@ -819,7 +818,7 @@ CommentReference
}
test_extension_staticGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E on int {
static int get foo => 0;
}
@@ -846,7 +845,7 @@ CommentReference
}
test_extension_staticMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E on int {
static void foo() {}
}
@@ -873,7 +872,7 @@ CommentReference
}
test_extension_staticSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E on int {
static set foo(int _) {}
}
@@ -903,7 +902,7 @@ CommentReference
@reflectiveTest
class CommentResolutionTest_PropertyAccess extends PubPackageResolutionTest {
test_class_constructor_named() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
A.named();
@@ -939,7 +938,7 @@ CommentReference
}
test_class_constructor_unnamedViaNew() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
A();
@@ -974,7 +973,7 @@ CommentReference
}
test_class_instanceGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
int get foo => 0;
@@ -1009,7 +1008,7 @@ CommentReference
}
test_class_instanceGetter_onTypedef() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
int get foo => 0;
@@ -1045,7 +1044,7 @@ CommentReference
}
test_class_instanceMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
void foo() {}
@@ -1080,7 +1079,7 @@ CommentReference
}
test_class_instanceSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
set foo(int value) {}
@@ -1115,7 +1114,7 @@ CommentReference
}
test_class_staticGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
static int get foo => 0;
@@ -1150,7 +1149,7 @@ CommentReference
}
test_class_staticGetter_onTypedef() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
static int get foo => 0;
@@ -1186,7 +1185,7 @@ CommentReference
}
test_class_staticMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
static void foo() {}
@@ -1221,7 +1220,7 @@ CommentReference
}
test_class_staticSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
class A {
static set foo(int value) {}
@@ -1256,7 +1255,7 @@ CommentReference
}
test_extension_instanceGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
extension E on int {
int get foo => 0;
@@ -1291,7 +1290,7 @@ CommentReference
}
test_extension_instanceMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
extension E on int {
void foo() {}
@@ -1326,7 +1325,7 @@ CommentReference
}
test_extension_instanceSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
extension E on int {
set foo(int value) {}
@@ -1361,7 +1360,7 @@ CommentReference
}
test_extension_staticGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
extension E on int {
static int get foo => 0;
@@ -1396,7 +1395,7 @@ CommentReference
}
test_extension_staticMethod() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
extension E on int {
static void foo() {}
@@ -1431,7 +1430,7 @@ CommentReference
}
test_extension_staticSetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import '' as self;
extension E on int {
static set foo(int value) {}
@@ -1469,7 +1468,7 @@ CommentReference
@reflectiveTest
class CommentResolutionTest_SimpleIdentifier extends PubPackageResolutionTest {
test_associatedSetterAndGetter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
int get foo => 0;
set foo(int value) {}
@@ -1488,7 +1487,7 @@ CommentReference
}
test_associatedSetterAndGetter_setterInScope() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension E1 on int {
int get foo => 0;
}
@@ -1509,7 +1508,7 @@ CommentReference
}
test_beforeClass() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// [foo]
class A {
foo() {}
@@ -1526,7 +1525,7 @@ CommentReference
}
test_beforeConstructor_fieldParameter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
final int p;
@@ -1545,7 +1544,7 @@ CommentReference
}
test_beforeConstructor_normalParameter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
/// [p]
A(int p);
@@ -1561,7 +1560,7 @@ CommentReference
}
test_beforeConstructor_superParameter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
A(int p);
}
@@ -1582,7 +1581,7 @@ CommentReference
}
test_beforeEnum() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// This is the [Samurai] kind.
enum Samurai {
/// Use [int].
@@ -1617,7 +1616,7 @@ CommentReference
}
test_beforeFunction_blockBody() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// [p]
foo(int p) {}
''');
@@ -1632,7 +1631,7 @@ SimpleIdentifier
}
test_beforeFunction_expressionBody() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// [p]
foo(int p) => null;
''');
@@ -1647,7 +1646,7 @@ CommentReference
}
test_beforeFunctionTypeAlias() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// [p]
typedef Foo(int p);
''');
@@ -1662,7 +1661,7 @@ CommentReference
}
test_beforeGenericTypeAlias() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// Can resolve [T], [S], and [p].
typedef Foo<T> = Function<S>(int p);
''');
@@ -1693,7 +1692,7 @@ CommentReference
}
test_beforeGetter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// [int]
get g => null;
''');
@@ -1708,7 +1707,7 @@ SimpleIdentifier
}
test_beforeMethod() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class A {
/// [p1]
ma(int p1);
@@ -1779,7 +1778,7 @@ int get foo => 0;
set foo(int value) {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -1802,7 +1801,7 @@ extension E1 on int {
int get foo => 0;
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -1828,7 +1827,7 @@ class C {}
newFile('$testPackageLibPath/two.dart', r'''
export 'one.dart';
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'two.dart';
library;
@@ -1852,19 +1851,17 @@ class A {
A.named();
}
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
/// [new A] or [new A.named]
// ^^^
// [diag.deprecatedNewInCommentReference] Using the 'new' keyword in a comment reference is deprecated.
// ^^^
// [diag.deprecatedNewInCommentReference] Using the 'new' keyword in a comment reference is deprecated.
main() {}
''',
[
error(diag.deprecatedNewInCommentReference, 42, 3),
error(diag.deprecatedNewInCommentReference, 53, 3),
],
);
''');
assertResolvedNodeText(findNode.commentReference('A]'), r'''
CommentReference
@@ -1897,7 +1894,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
void foo() {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -1921,7 +1918,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
void foo() {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -1942,7 +1939,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
class A {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
class C {
@@ -1964,7 +1961,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
class A {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
///
/// Text [A].
@@ -1984,7 +1981,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
void foo() {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -2005,7 +2002,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
class A {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
/// Text [A].
@@ -2025,7 +2022,7 @@ CommentReference
newFile('$testPackageLibPath/foo.dart', r'''
void foo() {}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// @docImport 'foo.dart';
library;
@@ -2043,21 +2040,19 @@ CommentReference
}
test_newKeyword() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A();
A.named();
}
/// [new A] or [new A.named]
// ^^^
// [diag.deprecatedNewInCommentReference] Using the 'new' keyword in a comment reference is deprecated.
// ^^^
// [diag.deprecatedNewInCommentReference] Using the 'new' keyword in a comment reference is deprecated.
main() {}
''',
[
error(diag.deprecatedNewInCommentReference, 38, 3),
error(diag.deprecatedNewInCommentReference, 49, 3),
],
);
''');
assertResolvedNodeText(findNode.commentReference('A]'), r'''
CommentReference
@@ -2088,7 +2083,7 @@ CommentReference
test_onFieldFormalParameter() async {
// TODO(scheglov): add tests for references to nested formal parameters
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
final int f;
A({
@@ -2109,7 +2104,7 @@ CommentReference
}
test_onFunctionTypedFormalParameter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(
/// [int]
void g(int a),
@@ -2128,7 +2123,7 @@ CommentReference
test_onFunctionTypedFormalParameter_self() async {
// TODO(scheglov): add tests for references to nested formal parameters
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
/// [bar]
void f(int bar()) {}
''');
@@ -2143,7 +2138,7 @@ CommentReference
}
test_onSimpleFormalParameter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(
/// [int]
int x,
@@ -2162,7 +2157,7 @@ CommentReference
test_onSuperFormalParameter() async {
// TODO(scheglov): add tests for references to nested formal parameters
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
A({required int f});
}
@@ -2186,7 +2181,7 @@ CommentReference
}
test_setter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
/// [x] in A
mA() {}
@@ -2217,7 +2212,7 @@ CommentReference
}
test_unqualifiedReferenceToNonLocalStaticMember() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
static void foo() {}
}
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -19,16 +18,15 @@ main() {
@reflectiveTest
class ConditionalExpressionResolutionTest extends PubPackageResolutionTest {
test_condition_super() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
void f() {
super ? 0 : 1;
// ^^^^^
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
}
}
''',
[error(diag.nonBoolCondition, 27, 5)],
);
''');
var node = findNode.singleConditionalExpression;
assertResolvedNodeText(node, r'''
@@ -75,16 +73,15 @@ MethodInvocation
}
test_else_super() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
void f(bool c) {
c ? 0 : super;
// ^^^^^
// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'.
}
}
''',
[error(diag.missingAssignableSelector, 41, 5)],
);
''');
var node = findNode.singleConditionalExpression;
assertResolvedNodeText(node, r'''
@@ -106,7 +103,7 @@ ConditionalExpression
}
test_ifNull_lubUsedEvenIfItDoesNotSatisfyContext() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
// @dart=3.3
class A {}
class B1 extends A {}
@@ -142,19 +139,18 @@ ConditionalExpression
}
test_issue49692() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
T f<T>(T t, bool b) {
if (t is int) {
final u = b ? t : null;
return u;
// ^
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int?' can't be returned from the function 'f' because it has a return type of 'T'.
} else {
return t;
}
}
''',
[error(diag.returnOfInvalidTypeFromFunction, 79, 1)],
);
''');
var node = findNode.conditionalExpression('b ?');
assertResolvedNodeText(node, r'''
@@ -177,7 +173,7 @@ ConditionalExpression
}
test_recordType_differentShape() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
void f(bool b, (int, String) r1, ({int a}) r2) {
b ? r1 : r2;
}
@@ -205,7 +201,7 @@ ConditionalExpression
}
test_recordType_sameShape_named() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
void f(bool b, ({int a}) r1, ({double a}) r2) {
b ? r1 : r2;
}
@@ -233,16 +229,15 @@ ConditionalExpression
}
test_then_super() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
void f(bool c) {
c ? super : 0;
// ^^^^^
// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'.
}
}
''',
[error(diag.missingAssignableSelector, 37, 5)],
);
''');
var node = findNode.singleConditionalExpression;
assertResolvedNodeText(node, r'''
@@ -264,7 +259,7 @@ ConditionalExpression
}
test_type_int_double() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
void f(bool b) {
b ? 0 : 1.2;
}
@@ -290,7 +285,7 @@ ConditionalExpression
}
test_type_int_null() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
void f(bool b) {
b ? 42 : null;
}
@@ -329,7 +324,7 @@ void f(bool a, int b, int c) {
@reflectiveTest
class InferenceUpdate3Test extends PubPackageResolutionTest {
test_contextIsConvertedToATypeUsingGreatestClosure() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {}
class B1<T> extends A {}
class B2<T> extends A {}
@@ -367,7 +362,7 @@ f(bool b, C1<int> c1, C2<double> c2) {
}
test_contextNotUsedIfLhsDoesNotSatisfyContext() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {}
class B1 extends A {}
class B2 extends A {}
@@ -404,7 +399,7 @@ f(bool b, B2 b2, C1 c1, Object? o) {
}
test_contextNotUsedIfRhsDoesNotSatisfyContext() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {}
class B1 extends A {}
class B2 extends A {}
@@ -441,7 +436,7 @@ f(bool b, C1 c1, B2 b2, Object? o) {
}
test_contextUsedInsteadOfLubIfLubDoesNotSatisfyContext() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {}
class B1 extends A {}
class B2 extends A {}
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -18,7 +17,7 @@ main() {
@reflectiveTest
class ConstantPatternResolutionTest extends PubPackageResolutionTest {
test_expression_class_field() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
static const foo = 0;
}
@@ -48,7 +47,7 @@ ConstantPattern
}
test_expression_instanceCreation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
}
@@ -78,7 +77,7 @@ ConstantPattern
}
test_expression_integerLiteral() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
if (x case 0) {}
}
@@ -94,7 +93,7 @@ ConstantPattern
}
test_expression_integerLiteral_contextType_double() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(double x) {
switch (x) {
case 0:
@@ -113,7 +112,7 @@ ConstantPattern
}
test_expression_listLiteral() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
if (x case const [0]) {}
}
@@ -135,7 +134,7 @@ ConstantPattern
}
test_expression_mapLiteral() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
if (x case const {0: 1}) {}
}
@@ -169,7 +168,7 @@ class A {
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart' as prefix;
void f(x) {
@@ -208,7 +207,7 @@ ConstantPattern
const foo = 0;
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart' as prefix;
void f(x) {
@@ -236,7 +235,7 @@ ConstantPattern
}
test_expression_setLiteral() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
if (x case const {0, 1}) {}
}
@@ -262,7 +261,7 @@ ConstantPattern
}
test_expression_topLevelVariable() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
const foo = 0;
void f(x) {
@@ -281,7 +280,7 @@ ConstantPattern
}
test_expression_typeLiteral_notPrefixed_dynamicElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(Object? x) {
if (x case dynamic) {}
}
@@ -300,7 +299,7 @@ ConstantPattern
}
test_expression_typeLiteral_notPrefixed_interfaceElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(Object? x) {
if (x case int) {}
}
@@ -319,7 +318,7 @@ ConstantPattern
}
test_expression_typeLiteral_notPrefixed_nested() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(Object? x) {
if (x case [0, int]) {}
}
@@ -349,7 +348,7 @@ ListPattern
}
test_expression_typeLiteral_notPrefixed_neverElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(Object? x) {
if (x case Never) {}
}
@@ -368,7 +367,7 @@ ConstantPattern
}
test_expression_typeLiteral_notPrefixed_typeAliasElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
typedef A = int;
void f(Object? x) {
@@ -390,14 +389,13 @@ ConstantPattern
}
test_expression_typeLiteral_notPrefixed_typeParameterElement() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f<T>(Object? x) {
if (x case T) {}
// ^
// [diag.constTypeParameter] Type parameters can't be used in a constant expression.
}
''',
[error(diag.constTypeParameter, 36, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
ConstantPattern
@@ -412,7 +410,7 @@ ConstantPattern
}
test_expression_typeLiteral_prefixed_dynamicElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'dart:core' as core;
void f(core.Object? x) {
@@ -437,7 +435,7 @@ ConstantPattern
}
test_expression_typeLiteral_prefixed_interfaceElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'dart:core' as core;
void f(core.Object? x) {
@@ -462,7 +460,7 @@ ConstantPattern
}
test_expression_typeLiteral_prefixed_neverElement() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'dart:core' as core;
void f(core.Object? x) {
@@ -491,7 +489,7 @@ ConstantPattern
typedef A = int;
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart' as prefix;
void f(Object? x) {
@@ -518,7 +516,7 @@ ConstantPattern
}
test_location_ifCase() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
if (x case 0) {}
}
@@ -534,7 +532,7 @@ ConstantPattern
}
test_location_switchCase() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
switch (x) {
case 0:
@@ -4,15 +4,16 @@
import 'package:analyzer/src/dart/constant/value.dart';
import 'package:analyzer/src/dart/element/element.dart';
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(ConstantResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -24,13 +25,12 @@ class A {
const A({int p});
}
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
const a = const A();
''',
[error(diag.constConstructorParamTypeMismatch, 27, 9)],
);
// ^^^^^^^^^
// [diag.constConstructorParamTypeMismatch] A value of type 'Null' can't be assigned to a parameter of type 'int' in a const constructor.
''');
var aLib = findElement2.import('package:test/a.dart').importedLibrary!;
var aConstructor = aLib.getClass('A')!.constructors.single;
@@ -43,7 +43,7 @@ const a = const A();
}
test_constFactoryRedirection_super() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class I {
const factory I(int f) = B;
}
@@ -68,83 +68,78 @@ main() {}
}
test_constList_withNullAwareElement() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
foo() {
return const [?A()];
// ^
// [diag.invalidNullAwareElement] The element can't be null, so the null-aware operator '?' is unnecessary.
}
}
''',
[error(diag.invalidNullAwareElement, 51, 1)],
);
''');
assertType(findNode.listLiteral('const ['), 'List<A>');
}
test_constMap_withNullAwareKey() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
foo() {
return const {?A(): 0};
// ^
// [diag.invalidNullAwareMapEntryKey] The map entry key can't be null, so the null-aware operator '?' is unnecessary.
}
}
''',
[error(diag.invalidNullAwareMapEntryKey, 51, 1)],
);
''');
assertType(findNode.setOrMapLiteral('const {'), 'Map<A, int>');
}
test_constMap_withNullAwareValue() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
foo() {
return const {0: ?A()};
// ^
// [diag.invalidNullAwareMapEntryValue] The map entry value can't be null, so the null-aware operator '?' is unnecessary.
}
}
''',
[error(diag.invalidNullAwareMapEntryValue, 54, 1)],
);
''');
assertType(findNode.setOrMapLiteral('const {'), 'Map<int, A>');
}
test_constNotInitialized() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class B {
const B(_);
}
class C extends B {
static const a;
// ^
// [diag.constNotInitialized] The constant 'a' must be initialized.
const C() : super(a);
}
''',
[error(diag.constNotInitialized, 62, 1)],
);
''');
}
test_constSet_withNullAwareElement() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
const A();
foo() {
return const {?A()};
// ^
// [diag.invalidNullAwareElement] The element can't be null, so the null-aware operator '?' is unnecessary.
}
}
''',
[error(diag.invalidNullAwareElement, 51, 1)],
);
''');
assertType(findNode.setOrMapLiteral('const {'), 'Set<A>');
}
test_context_eliminateTypeVariables() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A<T> {
const A({List<T> a = const []});
}
@@ -153,7 +148,7 @@ class A<T> {
}
test_context_eliminateTypeVariables_functionType() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A<T, U> {
const A({List<T Function(U)> a = const []});
}
@@ -173,7 +168,7 @@ class C<T> {
const C();
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
const v = a;
@@ -266,7 +261,7 @@ class A {
}
''');
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
class B extends A {
@@ -284,7 +279,7 @@ class B extends A {
}
test_local_prefixedIdentifier_staticField_extension() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
const a = E.f;
extension E on int {
@@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConstructorFieldInitializerResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -17,7 +18,7 @@ main() {
class ConstructorFieldInitializerResolutionTest
extends PubPackageResolutionTest {
test_fieldOfAugmentation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
int get foo;
}
@@ -46,7 +47,7 @@ ConstructorFieldInitializer
}
test_formalParameter() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
final int f;
A(int a) : f = a;
@@ -181,16 +182,15 @@ ConstructorFieldInitializer
}
test_invalid_declarationAndInitializer() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
final x = 0;
const A() : x = a;
// ^
// [diag.fieldInitializedInInitializerAndDeclaration] Fields can't be initialized in the constructor if they are final and were already initialized at their declaration.
}
const a = 0;
''',
[error(diag.fieldInitializedInInitializerAndDeclaration, 39, 1)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -208,16 +208,15 @@ ConstructorFieldInitializer
}
test_invalid_notField_class() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
const A() : X = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'X' isn't a field in the enclosing class.
}
const a = 0;
class X {}
''',
[error(diag.initializerForNonExistentField, 24, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -235,16 +234,15 @@ ConstructorFieldInitializer
}
test_invalid_notField_getter() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
int get x => 0;
}
const a = 0;
''',
[error(diag.initializerForNonExistentField, 18, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -262,19 +260,17 @@ ConstructorFieldInitializer
}
test_invalid_notField_importPrefix() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
import 'dart:async' as x;
// ^^^^^^^^^^^^
// [diag.unusedImport] Unused import: 'dart:async'.
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
}
const a = 0;
''',
[
error(diag.unusedImport, 7, 12),
error(diag.initializerForNonExistentField, 44, 5),
],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -292,16 +288,15 @@ ConstructorFieldInitializer
}
test_invalid_notField_method() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
void x() {}
}
const a = 0;
''',
[error(diag.initializerForNonExistentField, 18, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -319,16 +314,15 @@ ConstructorFieldInitializer
}
test_invalid_notField_setter() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
set x(int _) {}
}
const a = 0;
''',
[error(diag.initializerForNonExistentField, 18, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -346,16 +340,15 @@ ConstructorFieldInitializer
}
test_invalid_notField_topLevelFunction() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
}
const a = 0;
void x() {}
''',
[error(diag.initializerForNonExistentField, 18, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -373,16 +366,15 @@ ConstructorFieldInitializer
}
test_invalid_notField_topLevelVariable() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
}
const a = 0;
var x = 0;
''',
[error(diag.initializerForNonExistentField, 18, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -400,15 +392,14 @@ ConstructorFieldInitializer
}
test_invalid_notField_typeParameter() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A() : T = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'T' isn't a field in the enclosing class.
}
const a = 0;
''',
[error(diag.initializerForNonExistentField, 21, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -426,15 +417,14 @@ ConstructorFieldInitializer
}
test_invalid_notField_unresolved() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A() : x = a;
// ^^^^^
// [diag.initializerForNonExistentField] 'x' isn't a field in the enclosing class.
}
const a = 0;
''',
[error(diag.initializerForNonExistentField, 18, 5)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -2,10 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
@@ -14,13 +14,14 @@ main() {
defineReflectiveTests(
ConstructorReferenceResolutionTest_WithoutConstructorTearoffs,
);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class ConstructorReferenceResolutionTest extends PubPackageResolutionTest {
test_abstractClass_factory() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
abstract class A {
factory A() => A2();
}
@@ -51,18 +52,17 @@ ConstructorReference
}
test_abstractClass_generative() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
abstract class A {
A();
}
foo() {
A.new;
//^^^^^
// [diag.tearoffOfGenerativeConstructorOfAbstractClass] A generative constructor of an abstract class can't be torn off.
}
''',
[error(diag.tearoffOfGenerativeConstructorOfAbstractClass, 39, 5)],
);
''');
var node = findNode.constructorReference('A.new;');
assertResolvedNodeText(node, r'''
@@ -83,8 +83,7 @@ ConstructorReference
}
test_abstractClass_redirecting() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
abstract class A {
A(): this.two();
@@ -93,10 +92,10 @@ abstract class A {
foo() {
A.new;
//^^^^^
// [diag.tearoffOfGenerativeConstructorOfAbstractClass] A generative constructor of an abstract class can't be torn off.
}
''',
[error(diag.tearoffOfGenerativeConstructorOfAbstractClass, 63, 5)],
);
''');
var node = findNode.constructorReference('A.new;');
assertResolvedNodeText(node, r'''
@@ -117,25 +116,18 @@ ConstructorReference
}
test_class_generic_inferFromContext_badTypeArgument() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T extends num> {
A.foo();
}
A<String> Function() bar() {
// [context 1][column 1][length 9] The inverted type 'A<String>' is also not regular-bounded, so the type is not well-bounded.
//^^^^^^
// [diag.typeArgumentNotMatchingBounds][context 1] 'String' doesn't conform to the bound 'num' of the type parameter 'T'.
return A.foo;
}
''',
[
error(
diag.typeArgumentNotMatchingBounds,
41,
6,
contextMessages: [message(testFile, 39, 9)],
),
],
);
''');
var node = findNode.constructorReference('A.foo;');
assertResolvedNodeText(node, r'''
@@ -158,7 +150,7 @@ ConstructorReference
}
test_class_generic_named_inferTypeFromContext() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
@@ -189,7 +181,7 @@ ConstructorReference
}
test_class_generic_named_uninstantiated() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
@@ -218,7 +210,7 @@ ConstructorReference
}
test_class_generic_named_uninstantiated_bound() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T extends num> {
A.foo();
}
@@ -247,7 +239,7 @@ ConstructorReference
}
test_class_nonGeneric_const() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
const A();
}
@@ -274,7 +266,7 @@ ConstructorReference
}
test_class_nonGeneric_named() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
A.foo();
}
@@ -303,7 +295,7 @@ ConstructorReference
}
test_class_nonGeneric_unnamed() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A {
A();
}
@@ -338,7 +330,7 @@ class A {
}
typedef TA = A;
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
bar() {
a.TA.foo;
@@ -374,7 +366,7 @@ class A {
}
typedef TA = A;
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
bar() {
a.TA.new;
@@ -409,7 +401,7 @@ class A {
A.foo();
}
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
bar() {
a.A.foo;
@@ -444,7 +436,7 @@ class A {
A();
}
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
bar() {
a.A.new;
@@ -474,7 +466,7 @@ ConstructorReference
}
test_typeAlias_generic_const() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
const A();
}
@@ -502,7 +494,7 @@ ConstructorReference
}
test_typeAlias_generic_named_uninstantiated() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T, U> {
A.foo();
}
@@ -532,7 +524,7 @@ ConstructorReference
}
test_typeAlias_instantiated_const() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
const A();
}
@@ -564,7 +556,7 @@ ConstructorReference
}
test_typeAlias_instantiated_named() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
@@ -602,7 +594,7 @@ ConstructorReference
class ConstructorReferenceResolutionTest_TypeArgs
extends PubPackageResolutionTest {
test_alias_generic_const() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T, U> {
const A.foo();
}
@@ -646,7 +638,7 @@ ConstructorReference
}
test_alias_generic_const_differingNumberOfTypeParameters() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T, U> {
A.foo() {}
}
@@ -686,7 +678,7 @@ ConstructorReference
}
test_alias_generic_named() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T, U> {
A.foo();
}
@@ -732,7 +724,7 @@ ConstructorReference
}
test_alias_generic_uninstantiated_const() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T, U> {
const A.foo();
}
@@ -760,7 +752,7 @@ ConstructorReference
}
test_alias_generic_unnamed() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A();
}
@@ -802,8 +794,7 @@ ConstructorReference
}
test_alias_generic_with_inferred_type_parameter() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class C<T> {
final T x;
C(this.x);
@@ -811,14 +802,14 @@ class C<T> {
typedef Direct<T> = C<T>;
void main() {
var x = const <C<int> Function(int)>[Direct.new];
// ^
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
}
''',
[error(diag.unusedLocalVariable, 87, 1)],
);
''');
}
test_alias_genericWithBound_unnamed() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A();
}
@@ -860,8 +851,7 @@ ConstructorReference
}
test_alias_genericWithBound_unnamed_badBound() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A();
}
@@ -869,10 +859,10 @@ typedef TA<T extends num> = A<T>;
void bar() {
TA<String>.new;
// ^^^^^^
// [diag.typeArgumentNotMatchingBounds] 'String' doesn't conform to the bound 'num' of the type parameter 'T'.
}
''',
[error(diag.typeArgumentNotMatchingBounds, 75, 6)],
);
''');
var node = findNode.constructorReference('TA<String>.new;');
assertResolvedNodeText(node, r'''
@@ -905,7 +895,7 @@ ConstructorReference
}
test_class_generic_const() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
const A();
}
@@ -944,7 +934,7 @@ ConstructorReference
}
test_class_generic_named() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
@@ -985,69 +975,59 @@ ConstructorReference
}
test_class_generic_named_cascade() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
void bar() {
A<int>..foo;
// ^
// [diag.undefinedOperator] The operator '<' isn't defined for the type 'Type'.
// ^
// [diag.equalityCannotBeEqualityOperand] A comparison expression can't be an operand of another comparison expression.
// ^^
// [diag.missingIdentifier] Expected an identifier.
}
''',
[
error(diag.undefinedOperator, 43, 1),
error(diag.equalityCannotBeEqualityOperand, 47, 1),
error(diag.missingIdentifier, 48, 2),
],
);
''');
// The parser produces nonsense here because the `<` disambiguates as a
// relational operator, so no need to assert anything about analysis
// results.
}
test_class_generic_named_nullAware() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
void bar() {
A<int>?.foo;
// ^
// [diag.undefinedOperator] The operator '<' isn't defined for the type 'Type'.
// ^
// [diag.equalityCannotBeEqualityOperand] A comparison expression can't be an operand of another comparison expression.
// ^^
// [diag.missingIdentifier] Expected an identifier.
}
''',
[
error(diag.undefinedOperator, 43, 1),
error(diag.equalityCannotBeEqualityOperand, 47, 1),
error(diag.missingIdentifier, 48, 2),
],
);
''');
// The parser produces nonsense here because the `<` disambiguates as a
// relational operator, so no need to assert anything about analysis
// results.
}
test_class_generic_named_typeArgs() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
void bar() {
A<int>.foo<int>;
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsConstructor] The constructor 'A.foo' doesn't have type parameters.
}
''',
[
error(
diag.wrongNumberOfTypeArgumentsConstructor,
52,
5,
messageContains: ["The constructor 'A.foo'"],
),
],
);
''');
var node = findNode.constructorReference('A<int>.foo<int>;');
assertResolvedNodeText(node, r'''
@@ -1080,25 +1060,17 @@ ConstructorReference
}
test_class_generic_new_typeArgs() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.new();
}
void bar() {
A<int>.new<int>;
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsConstructor] The constructor 'A.new' doesn't have type parameters.
}
''',
[
error(
diag.wrongNumberOfTypeArgumentsConstructor,
52,
5,
messageContains: ["The constructor 'A.new'"],
),
],
);
''');
var node = findNode.constructorReference('A<int>.new<int>;');
assertResolvedNodeText(node, r'''
@@ -1131,18 +1103,17 @@ ConstructorReference
}
test_class_generic_nonConstructor() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
static int i = 1;
}
void bar() {
A<int>.i;
//^^^^^^^^
// [diag.classInstantiationAccessToStaticMember] The static member 'i' can't be accessed on a class instantiation.
}
''',
[error(diag.classInstantiationAccessToStaticMember, 51, 8)],
);
''');
var node = findNode.constructorReference('A<int>.i;');
assertResolvedNodeText(node, r'''
@@ -1171,18 +1142,17 @@ ConstructorReference
}
test_class_generic_nothing_hasNamedConstructor() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A.foo();
}
void bar() {
A<int>.;
// ^
// [diag.missingIdentifier] Expected an identifier.
}
''',
[error(diag.missingIdentifier, 49, 1)],
);
''');
var node = findNode.constructorReference('A<int>.;');
assertResolvedNodeText(node, r'''
@@ -1211,7 +1181,7 @@ ConstructorReference
}
test_class_generic_unnamed() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A();
}
@@ -1252,7 +1222,7 @@ ConstructorReference
}
test_class_generic_unnamed_partOfPropertyAccess() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T> {
A();
}
@@ -1293,7 +1263,7 @@ ConstructorReference
}
test_class_genericWithBound_unnamed() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class A<T extends num> {
A();
}
@@ -1334,18 +1304,17 @@ ConstructorReference
}
test_class_genericWithBound_unnamed_badBound() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T extends num> {
A();
}
void bar() {
A<String>.new;
// ^^^^^^
// [diag.typeArgumentNotMatchingBounds] 'String' doesn't conform to the bound 'num' of the type parameter 'T'.
}
''',
[error(diag.typeArgumentNotMatchingBounds, 52, 6)],
);
''');
var node = findNode.constructorReference('A<String>.new;');
assertResolvedNodeText(node, r'''
@@ -1384,7 +1353,7 @@ class A<T> {
}
typedef TA<T> = A<T>;
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
void bar() {
a.TA<int>.new;
@@ -1431,7 +1400,7 @@ class A<T> {
A.foo();
}
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
void bar() {
a.A<int>.foo;
@@ -1478,7 +1447,7 @@ class A<T> {
A();
}
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
extension on Function {
void m() {}
@@ -1528,7 +1497,7 @@ class A<T> {
A();
}
''');
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'a.dart' as a;
void bar() {
a.A<int>.new;
@@ -1575,18 +1544,17 @@ class ConstructorReferenceResolutionTest_WithoutConstructorTearoffs
extends PubPackageResolutionTest
with WithoutConstructorTearoffsMixin {
test_class_generic_nonConstructor() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A<T> {
static int i = 1;
}
void bar() {
A<int>.i;
// ^^^^^
// [diag.experimentNotEnabled] This requires the 'constructor-tearoffs' language feature to be enabled.
}
''',
[error(diag.experimentNotEnabled, 52, 5)],
);
''');
var node = findNode.constructorReference('A<int>.i;');
assertResolvedNodeText(node, r'''
@@ -1615,18 +1583,17 @@ ConstructorReference
}
test_constructorTearoff() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class A {
A.foo();
}
void bar() {
A.foo;
//^^^^^
// [diag.sdkVersionConstructorTearoffs] Tearing off a constructor requires the 'constructor-tearoffs' language feature.
}
''',
[error(diag.sdkVersionConstructorTearoffs, 39, 5)],
);
''');
var node = findNode.constructorReference('A.foo;');
assertResolvedNodeText(node, r'''
@@ -2,21 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConstructorDeclarationResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class ConstructorDeclarationResolutionTest extends PubPackageResolutionTest {
test_factory_redirect_generic_instantiated() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A<T> implements B<T> {
A(T a);
}
@@ -47,16 +48,15 @@ ConstructorName
}
test_fieldShadowingWildcardParameter() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
var v;
var _;
A(_) : v = _;
// ^
// [diag.implicitThisReferenceInInitializer] The instance member '_' can't be accessed in an initializer.
}
''',
[error(diag.implicitThisReferenceInInitializer, 41, 1)],
);
''');
var node = findNode.constructorFieldInitializer('v = _');
assertResolvedNodeText(node, r'''
@@ -74,7 +74,7 @@ ConstructorFieldInitializer
}
test_formalParameterScope() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class a {}
class B {
@@ -121,16 +121,17 @@ ConstructorDeclaration
}
test_privateNamedParameter_accessInInitializer() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int? _x;
// ^^
// [diag.unusedField] The value of the field '_x' isn't used.
int? _y;
// ^^
// [diag.unusedField] The value of the field '_y' isn't used.
C({this._x}) : _y = _x;
}
''',
[error(diag.unusedField, 17, 2), error(diag.unusedField, 28, 2)],
);
''');
var node = findNode.singleConstructorFieldInitializer;
assertResolvedNodeText(node, r'''
@@ -148,15 +149,14 @@ ConstructorFieldInitializer
}
test_privateNamedParameter_fieldFormal() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int? _x;
// ^^
// [diag.unusedField] The value of the field '_x' isn't used.
C({this._x});
}
''',
[error(diag.unusedField, 17, 2)],
);
''');
var node = findNode.singleConstructorDeclaration;
assertResolvedNodeText(node, r'''
@@ -172,7 +172,7 @@ ConstructorDeclaration
thisKeyword: this
period: .
name: _x
declaredFragment: <testLibraryFragment> x@31
declaredFragment: <testLibraryFragment> x@103
element: hasImplicitType isFinal isPublic
type: int?
field: <testLibrary>::@class::C::@field::_x
@@ -189,14 +189,13 @@ ConstructorDeclaration
test_privateNamedParameter_nonFieldFormal() async {
// The user is incorrectly using a private named parameter for a non-field
// parameter. This is erroneous, but resolve using the private name.
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C({int? _x});
// ^^
// [diag.privateNamedNonFieldParameter] Named parameters that don't refer to instance variables can't start with underscore.
}
''',
[error(diag.privateNamedNonFieldParameter, 20, 2)],
);
''');
var node = findNode.singleConstructorDeclaration;
assertResolvedNodeText(node, r'''
@@ -229,7 +228,7 @@ ConstructorDeclaration
}
test_redirectedConstructor_named() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A implements B {
A.named();
}
@@ -271,7 +270,7 @@ ConstructorDeclaration
}
test_redirectedConstructor_named_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A<T> implements B<T> {
A.named();
}
@@ -325,18 +324,17 @@ ConstructorDeclaration
}
test_redirectedConstructor_named_unresolved() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A implements B {
A();
}
class B {
factory B() = A.named;
// ^^^^^^^
// [diag.redirectToMissingConstructor] The constructor 'A.named' couldn't be found in 'A'.
}
''',
[error(diag.redirectToMissingConstructor, 59, 7)],
);
''');
var node = findNode.constructorDeclaration('factory B');
assertResolvedNodeText(node, r'''
@@ -370,7 +368,7 @@ ConstructorDeclaration
}
test_redirectedConstructor_unnamed() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A implements B {
A();
}
@@ -409,7 +407,7 @@ ConstructorDeclaration
}
test_redirectedConstructor_unnamed_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A<T> implements B<T> {
A();
}
@@ -458,18 +456,17 @@ ConstructorDeclaration
}
test_redirectedConstructor_unnamed_unresolved() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class A implements B {
A.named();
}
class B {
factory B.named() = A;
// ^
// [diag.redirectToMissingConstructor] The constructor 'A' couldn't be found in 'A'.
}
''',
[error(diag.redirectToMissingConstructor, 71, 1)],
);
''');
var node = findNode.constructorDeclaration('factory B');
assertResolvedNodeText(node, r'''
@@ -2,31 +2,31 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(DeclaredVariablePatternResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class DeclaredVariablePatternResolutionTest extends PubPackageResolutionTest {
test_final_switchCase() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(int x) {
switch (x) {
case final y:
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
break;
}
}
''',
[error(diag.unusedLocalVariable, 46, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -40,17 +40,16 @@ DeclaredVariablePattern
}
test_final_typed_switchCase() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
switch (x) {
case final int y:
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
break;
}
}
''',
[error(diag.unusedLocalVariable, 46, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -68,7 +67,7 @@ DeclaredVariablePattern
}
test_patternVariableDeclaration_final_recordPattern_listPattern() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f() {
// ignore:unused_local_variable
final [a] = [0];
@@ -92,7 +91,7 @@ ListPattern
}
test_patternVariableDeclaration_final_recordPattern_listPattern_restPattern() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f() {
// ignore:unused_local_variable
final [...a] = [0, 1, 2];
@@ -118,7 +117,7 @@ ListPattern
}
test_patternVariableDeclaration_final_recordPattern_mapPattern_entry() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f() {
// ignore:unused_local_variable
final {0: a} = {0: 1};
@@ -147,7 +146,7 @@ MapPattern
}
test_patternVariableDeclaration_final_recordPattern_objectPattern() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f() {
// ignore:unused_local_variable
final int(sign: a) = 0;
@@ -179,7 +178,7 @@ ObjectPattern
}
test_patternVariableDeclaration_final_recordPattern_parenthesizedPattern() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f() {
// ignore:unused_local_variable
final (a) = 0;
@@ -201,7 +200,7 @@ ParenthesizedPattern
}
test_patternVariableDeclaration_final_recordPattern_recordPattern() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void f() {
// ignore:unused_local_variable
final (a,) = (0,);
@@ -226,17 +225,16 @@ RecordPattern
}
test_typed_switchCase() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(x) {
switch (x) {
case int y:
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
break;
}
}
''',
[error(diag.unusedLocalVariable, 40, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -253,16 +251,15 @@ DeclaredVariablePattern
}
test_var_demoteType() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f<T>(T x) {
if (x is int) {
if (x case var y) {}
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
}
}
''',
[error(diag.unusedLocalVariable, 54, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
@@ -277,14 +274,13 @@ DeclaredVariablePattern
}
test_var_ifCase() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(int x) {
if (x case var y) {}
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
}
''',
[error(diag.unusedLocalVariable, 33, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -298,14 +294,13 @@ DeclaredVariablePattern
}
test_var_nullOrEquivalent_neverQuestion() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(Never? x) {
if (x case var y) {}
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
}
''',
[error(diag.unusedLocalVariable, 36, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -319,14 +314,13 @@ DeclaredVariablePattern
}
test_var_nullOrEquivalent_nullNone() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(Null x) {
if (x case var y) {}
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
}
''',
[error(diag.unusedLocalVariable, 34, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -340,17 +334,16 @@ DeclaredVariablePattern
}
test_var_switchCase() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(int x) {
switch (x) {
case var y:
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
break;
}
}
''',
[error(diag.unusedLocalVariable, 44, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
DeclaredVariablePattern
@@ -364,17 +357,16 @@ DeclaredVariablePattern
}
test_var_switchCase_cast() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void f(num x) {
switch (x) {
case var y as int:
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
break;
}
}
''',
[error(diag.unusedLocalVariable, 44, 1)],
);
''');
var node = findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
CastPattern
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -19,23 +18,21 @@ main() {
class DotShorthandConstructorInvocationResolutionTest
extends PubPackageResolutionTest {
test_abstractClass() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class Foo<T> {
Foo();
}
void main() {
Foo _ = .new();
// ^^^^^^
// [diag.instantiateAbstractClass] Abstract classes can't be instantiated.
}
''',
[error(diag.instantiateAbstractClass, 60, 6)],
);
''');
}
test_abstractClass_const() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
static C fn() => CB.named(1);
}
@@ -47,16 +44,15 @@ class CB implements C {
void main() {
C c = const .fn(1);
// ^^
// [diag.constWithUndefinedConstructor] The class 'C' doesn't have a constant constructor 'fn'.
print(c);
}
''',
[error(diag.constWithUndefinedConstructor, 145, 2)],
);
''');
}
test_abstractClass_const_typeArguments() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class C {
static C fn() => CB.named(1);
}
@@ -68,18 +64,17 @@ class CB implements C {
void main() {
C c = const .fn<int>(1);
// ^^
// [diag.constWithUndefinedConstructor] The class 'C' doesn't have a constant constructor 'fn'.
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'C.fn', and type parameters can't be applied to dot shorthand constructor invocations.
print(c);
}
''',
[
error(diag.constWithUndefinedConstructor, 145, 2),
error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 147, 5),
],
);
''');
}
test_abstractClass_factory() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
void main() async {
var iter = [1, 2];
await for (var x in .fromIterable(iter)) {
@@ -115,7 +110,7 @@ DotShorthandConstructorInvocation
}
test_abstractClass_factory_const() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class Foo<T> {
const factory Foo.a() = _Foo;
@@ -149,8 +144,7 @@ DotShorthandConstructorInvocation
}
test_abstractClass_factory_const_typeArguments() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class Foo<T> {
const factory Foo.a() = _Foo;
@@ -162,14 +156,13 @@ class _Foo<T> extends Foo<T> {
}
Foo<int> bar<T>() => const .a<int>();
''',
[error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 154, 5)],
);
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'Foo.a', and type parameters can't be applied to dot shorthand constructor invocations.
''');
}
test_abstractClass_factory_typeArguments() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class Foo<T> {
factory Foo.a() = _Foo;
@@ -181,39 +174,37 @@ class _Foo<T> extends Foo<T> {
}
Foo<T> bar<T>() => .a<T>();
''',
[error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 128, 3)],
);
// ^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'Foo.a', and type parameters can't be applied to dot shorthand constructor invocations.
''');
}
test_abstractClass_function() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
Function getFunction() {
return .new();
// ^^^^^^
// [diag.instantiateAbstractClass] Abstract classes can't be instantiated.
}
''',
[error(diag.instantiateAbstractClass, 34, 6)],
);
''');
}
test_abstractClass_typeArguments() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
abstract class Foo<T> {
Foo();
}
void main() {
Foo _ = .new<int>();
// ^^^^^^^^^^^
// [diag.instantiateAbstractClass] Abstract classes can't be instantiated.
}
''',
[error(diag.instantiateAbstractClass, 60, 11)],
);
''');
}
test_chain_method() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -259,7 +250,7 @@ MethodInvocation
}
test_chain_method_const() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C(this.x);
@@ -306,7 +297,7 @@ MethodInvocation
}
test_chain_property() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -348,7 +339,7 @@ PropertyAccess
}
test_chain_property_const() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C(this.x);
@@ -391,7 +382,7 @@ PropertyAccess
}
test_conflict_instance_getter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
final int value; // Same name as constructor
A.value(this.value);
@@ -426,7 +417,7 @@ DotShorthandConstructorInvocation
}
test_conflict_instance_method() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
final int val;
A.value(this.val);
@@ -462,7 +453,7 @@ DotShorthandConstructorInvocation
}
test_conflict_instance_method_factory() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
final int val;
A._(this.val);
@@ -494,7 +485,7 @@ DotShorthandConstructorInvocation
}
test_conflict_instance_setter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class A {
int? val;
A.value(this.val);
@@ -534,7 +525,7 @@ DotShorthandConstructorInvocation
}
test_const_assert() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C.named(this.x);
@@ -570,7 +561,7 @@ DotShorthandConstructorInvocation
}
test_const_inConstantContext() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C.named(this.x);
@@ -604,7 +595,7 @@ DotShorthandConstructorInvocation
}
test_const_keyword() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C.named(this.x);
@@ -639,8 +630,7 @@ DotShorthandConstructorInvocation
}
test_const_nonConst_constructor() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
C.named(this.x);
@@ -648,16 +638,15 @@ class C {
void main() {
C c = const .named(1);
// ^^^^^
// [diag.constWithNonConst] The constructor being called isn't a const constructor.
print(c);
}
''',
[error(diag.constWithNonConst, 69, 5)],
);
''');
}
test_const_nonConst_method() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C fn() => C.named(1);
final int x;
@@ -666,15 +655,15 @@ class C {
void main() {
C c = const .fn(1);
// ^^
// [diag.constWithUndefinedConstructor] The class 'C' doesn't have a constant constructor 'fn'.
print(c);
}
''',
[error(diag.constWithUndefinedConstructor, 107, 2)],
);
''');
}
test_constructor_named() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C.named(this.x);
@@ -708,7 +697,7 @@ DotShorthandConstructorInvocation
}
test_constructor_named_futureOr() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'dart:async';
class C<T> {
@@ -748,8 +737,7 @@ DotShorthandConstructorInvocation
}
test_enum_constructor() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
enum E {
v.named();
@@ -758,15 +746,15 @@ enum E {
void f() {
E e = .named();
// ^^^^^
// [diag.invalidReferenceToGenerativeEnumConstructor] Generative enum constructors can only be used to create an enum constant.
print(e);
}
''',
[error(diag.invalidReferenceToGenerativeEnumConstructor, 65, 5)],
);
''');
}
test_equality() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C.named(this.x);
@@ -802,7 +790,7 @@ DotShorthandConstructorInvocation
}
test_equality_inferTypeParameters() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
void main() {
bool x = <int>[] == .filled(2, '2');
print(x);
@@ -838,7 +826,7 @@ DotShorthandConstructorInvocation
}
test_equality_pattern() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C.named(this.x);
@@ -873,7 +861,7 @@ DotShorthandConstructorInvocation
}
test_factory() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class Foo<T> {
factory Foo.a() = _Foo;
@@ -906,7 +894,7 @@ DotShorthandConstructorInvocation
}
test_factory_const() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class Foo<T> {
const factory Foo.a() = _Foo;
@@ -940,8 +928,7 @@ DotShorthandConstructorInvocation
}
test_factory_const_typeArguments() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class Foo<T> {
const factory Foo.a() = _Foo;
@@ -953,14 +940,13 @@ class _Foo<T> extends Foo<T> {
}
Foo<int> bar<T>() => const .a<int>();
''',
[error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 145, 5)],
);
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'Foo.a', and type parameters can't be applied to dot shorthand constructor invocations.
''');
}
test_factory_typeArguments() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class Foo<T> {
factory Foo.a() = _Foo;
@@ -972,26 +958,25 @@ class _Foo<T> extends Foo<T> {
}
Foo<T> bar<T>() => .a<T>();
''',
[error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 119, 3)],
);
// ^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'Foo.a', and type parameters can't be applied to dot shorthand constructor invocations.
''');
}
test_functionExpression() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {}
void main() {
final C _ = .new()();
// ^^^^^^
// [diag.invocationOfNonFunctionExpression] The expression doesn't evaluate to a function, so it can't be invoked.
}
''',
[error(diag.invocationOfNonFunctionExpression, 40, 6)],
);
''');
}
test_functionExpression_call() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C call() => this;
}
@@ -1025,7 +1010,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_argument() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C call(int x) => this;
}
@@ -1064,7 +1049,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_extension() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {}
extension CallC on C {
@@ -1100,7 +1085,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C call<T>(T t) => this;
}
@@ -1151,7 +1136,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_namedConstructor() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C.named();
C call() => this;
@@ -1186,7 +1171,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_nested() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C(C c);
C.a();
@@ -1235,8 +1220,7 @@ FunctionExpressionInvocation
}
test_functionExpression_nested() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C(C c);
C.a();
@@ -1244,14 +1228,14 @@ class C {
void main() {
C _ = .new(.a())();
// ^^^^^^^^^^
// [diag.invocationOfNonFunctionExpression] The expression doesn't evaluate to a function, so it can't be invoked.
}
''',
[error(diag.invocationOfNonFunctionExpression, 54, 10)],
);
''');
}
test_nested_invocation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static C member() => C(1);
T x;
@@ -1299,7 +1283,7 @@ DotShorthandConstructorInvocation
}
test_nested_property() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static C get member => C(1);
T x;
@@ -1343,7 +1327,7 @@ DotShorthandConstructorInvocation
}
test_new() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -1377,37 +1361,33 @@ DotShorthandConstructorInvocation
}
test_postfixOperator() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {}
void main() {
C c = .new()++;
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type '_'.
// ^^
// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression.
print(c);
}
''',
[
error(diag.dotShorthandUndefinedInvocation, 35, 3),
error(diag.illegalAssignmentToNonAssignable, 40, 2),
],
);
''');
}
test_prefixOperator() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {}
void main() {
C c = ++.new();
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type '_'.
// ^
// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'.
print(c);
}
''',
[
error(diag.dotShorthandUndefinedInvocation, 37, 3),
error(diag.missingAssignableSelector, 41, 1),
],
);
''');
}
test_privateClass_otherLibrary_constConstructor() async {
@@ -1420,17 +1400,16 @@ typedef Public = _Private;
const Public p = _Private.named();
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = const .named();
// ^^^^^^^^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(x);
}
''',
[error(diag.dotShorthandMissingContext, 50, 14)],
);
''');
}
test_privateClass_otherLibrary_constConstructor_withUnresolvedArg() async {
@@ -1443,24 +1422,22 @@ typedef Public = _Private;
const Public p = _Private.named(0);
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = const .named(unknown);
// ^^^^^^^^^^^^^^^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
// ^^^^^^^
// [diag.undefinedIdentifier] Undefined name 'unknown'.
print(x);
}
''',
[
error(diag.dotShorthandMissingContext, 50, 21),
error(diag.undefinedIdentifier, 63, 7),
],
);
''');
}
test_privateClass_sameLibrary_constConstructor() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class _Private {
const _Private.named();
}
@@ -1496,8 +1473,7 @@ DotShorthandConstructorInvocation
}
test_requiredParameters_missing() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C({required this.x});
@@ -1505,124 +1481,89 @@ class C {
void main() {
C c = .new();
// ^^^
// [diag.missingRequiredArgument] The named parameter 'x' is required, but there's no corresponding argument.
print(c);
}
''',
[error(diag.missingRequiredArgument, 69, 3)],
);
''');
}
test_typeParameters() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C();
}
void main() {
C c = .new<int>();
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'C.new', and type parameters can't be applied to dot shorthand constructor invocations.
print(c);
}
''',
[error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 46, 5)],
);
''');
}
test_typeParameters_const() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
const C();
}
void main() {
C c = const .new<int>();
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'C.new', and type parameters can't be applied to dot shorthand constructor invocations.
print(c);
}
''',
[error(diag.wrongNumberOfTypeArgumentsDotShorthandConstructor, 58, 5)],
);
''');
}
test_typeParameters_missingContext() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void main() {
var c = const .new<int>();
// ^^^^^^^^^^^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(c);
}
''',
[error(diag.dotShorthandMissingContext, 24, 17)],
);
''');
}
test_undefinedConstructor_message() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
int f() => const .foo();
''',
[
error(
diag.constWithUndefinedConstructor,
18,
3,
messageContains: ["class 'int'", "constructor 'foo'"],
),
],
);
// ^^^
// [diag.constWithUndefinedConstructor] The class 'int' doesn't have a constant constructor 'foo'.
''');
}
test_undefinedConstructor_message_equalityRhs() async {
await assertErrorsInCode(
r'''
// Make sure the error message properly refers to the `int` class. See
// https://github.com/dart-lang/sdk/issues/62352.
await resolveTestCodeWithDiagnostics(r'''
bool f(int x) => x == const .foo();
''',
[
// Make sure the error message properly refers to the `int` class. See
// https://github.com/dart-lang/sdk/issues/62352.
error(
diag.constWithUndefinedConstructor,
29,
3,
messageContains: ["class 'int'", "constructor 'foo'"],
),
],
);
// ^^^
// [diag.constWithUndefinedConstructor] The class 'int' doesn't have a constant constructor 'foo'.
''');
}
test_wrongNumberOfTypeArguments_message() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {}
C f() => .new<int>();
''',
[
error(
diag.wrongNumberOfTypeArgumentsDotShorthandConstructor,
25,
5,
messageContains: ["constructor 'C.new'"],
),
],
);
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'C.new', and type parameters can't be applied to dot shorthand constructor invocations.
''');
}
test_wrongNumberOfTypeArguments_message_equalityRhs() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {}
bool f(C c) => c == .new<int>();
''',
[
error(
diag.wrongNumberOfTypeArgumentsDotShorthandConstructor,
36,
5,
messageContains: ["constructor 'C.new'"],
),
],
);
// ^^^^^
// [diag.wrongNumberOfTypeArgumentsDotShorthandConstructor] The dot shorthand resolves to the constructor 'C.new', and type parameters can't be applied to dot shorthand constructor invocations.
''');
}
}
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -18,8 +17,7 @@ main() {
@reflectiveTest
class DotShorthandInvocationResolutionTest extends PubPackageResolutionTest {
test_assert_lhs() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
final int x;
const C.named(this.x);
@@ -28,14 +26,14 @@ class C {
class CAssert {
const CAssert.regular(C ctor)
: assert(const .named(1) == ctor);
// ^^^^^^^^^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
}
''',
[error(diag.dotShorthandMissingContext, 114, 15)],
);
''');
}
test_basic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C(1);
int x;
@@ -66,7 +64,7 @@ DotShorthandInvocation
}
test_basic_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static C member<U>(U x) => C(x);
T x;
@@ -114,7 +112,7 @@ DotShorthandInvocation
}
test_basic_parameter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member(int x) => C(x);
int x;
@@ -150,7 +148,7 @@ DotShorthandInvocation
}
test_chain_method() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C(1);
int x;
@@ -182,7 +180,7 @@ DotShorthandInvocation
}
test_chain_property() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C(1);
int x;
@@ -214,7 +212,7 @@ DotShorthandInvocation
}
test_equality() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class C {
static C member(int x) => C(x);
int x;
@@ -252,7 +250,7 @@ DotShorthandInvocation
}
test_equality_indexExpression() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -282,79 +280,74 @@ DotShorthandInvocation
}
test_error_context_invalid() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C { }
void main() {
C Function() c = .member();
// ^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'member' isn't defined for the context type 'C Function()'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 47, 6)],
);
''');
}
test_error_context_none() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
void main() {
var c = .member();
// ^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'member' isn't defined for the context type '_'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 25, 6)],
);
''');
}
test_error_notStatic() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C foo() => C();
}
void main() {
final C c = .foo();
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'foo' isn't defined for the context type 'C'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 60, 3)],
);
''');
}
test_error_unresolved() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C { }
void main() {
C c = .member();
// ^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'member' isn't defined for the context type 'C'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 36, 6)],
);
''');
}
test_error_unresolved_new() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
C.named();
}
void main() {
C c = .new();
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type 'C'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 49, 3)],
);
''');
}
test_extensionType() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
extension type C(int integer) {
static C one() => C(1);
}
@@ -383,22 +376,21 @@ DotShorthandInvocation
}
test_functionExpression() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C();
}
void main() {
final C _ = .member()();
// ^^^^^^^^^
// [diag.invocationOfNonFunctionExpression] The expression doesn't evaluate to a function, so it can't be invoked.
}
''',
[error(diag.invocationOfNonFunctionExpression, 69, 9)],
);
''');
}
test_functionExpression_call() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C();
C call() => this;
@@ -434,7 +426,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_argument() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C();
C call(int a) => this;
@@ -475,7 +467,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_extension() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C();
}
@@ -514,7 +506,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C();
C call<T>(T t) => this;
@@ -567,7 +559,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_nested() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member(C c) => C();
static C one() => C();
@@ -618,8 +610,7 @@ FunctionExpressionInvocation
}
test_functionExpression_nested() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member(C c) => C();
static C one() => C();
@@ -627,14 +618,14 @@ class C {
void main() {
C _ = .member(.one())();
// ^^^^^^^^^^^^^^^
// [diag.invocationOfNonFunctionExpression] The expression doesn't evaluate to a function, so it can't be invoked.
}
''',
[error(diag.invocationOfNonFunctionExpression, 92, 15)],
);
''');
}
test_futureOr() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'dart:async';
class C {
@@ -667,7 +658,7 @@ DotShorthandInvocation
}
test_futureOr_nested() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
import 'dart:async';
class C {
@@ -700,7 +691,7 @@ DotShorthandInvocation
}
test_mixin() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member(int x) => C(x);
int x;
@@ -740,7 +731,7 @@ DotShorthandInvocation
}
test_nested() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static C<int> member() => C(1);
static C<U> memberType<U, V>(U u) => C(u);
@@ -808,8 +799,7 @@ DotShorthandInvocation
}
test_postfixOperator() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C(1);
int x;
@@ -818,19 +808,17 @@ class C {
void main() {
C c = .member()++;
// ^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'member' isn't defined for the context type '_'.
// ^^
// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression.
print(c);
}
''',
[
error(diag.dotShorthandUndefinedInvocation, 87, 6),
error(diag.illegalAssignmentToNonAssignable, 95, 2),
],
);
''');
}
test_prefixOperator() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member() => C(1);
int x;
@@ -839,14 +827,13 @@ class C {
void main() {
C c = ++.member();
// ^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'member' isn't defined for the context type '_'.
// ^
// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'.
print(c);
}
''',
[
error(diag.dotShorthandUndefinedInvocation, 89, 6),
error(diag.missingAssignableSelector, 96, 1),
],
);
''');
}
test_privateClass_otherLibrary_constructor() async {
@@ -860,21 +847,19 @@ typedef Public = _Private;
final Public p = _Private();
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .new();
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type '_Private'.
x = .named();
// ^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'named' isn't defined for the context type '_Private'.
print(x);
}
''',
[
error(diag.dotShorthandUndefinedInvocation, 51, 3),
error(diag.dotShorthandUndefinedInvocation, 65, 5),
],
);
''');
}
test_privateClass_otherLibrary_invocation() async {
@@ -887,21 +872,20 @@ typedef Public = _Private;
final Public p = _Private();
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .instance();
// ^^^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'instance' isn't defined for the context type '_Private'.
print(x);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 51, 8)],
);
''');
}
test_privateClass_sameLibrary_constructor() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class _Private {
_Private();
}
@@ -936,7 +920,7 @@ DotShorthandConstructorInvocation
}
test_privateClass_sameLibrary_invocation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class _Private {
static _Private instance() => _Private();
}
@@ -979,17 +963,16 @@ typedef Public = _Private;
final Public p = _Private.one;
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .a();
// ^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'a' isn't defined for the context type '_Private'.
print(x);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 51, 1)],
);
''');
}
test_privateEnum_otherLibrary_invocation() async {
@@ -1003,21 +986,20 @@ typedef Public = _Private;
final Public p = _Private.one;
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .instance();
// ^^^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'instance' isn't defined for the context type '_Private'.
print(x);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 51, 8)],
);
''');
}
test_privateEnum_sameLibrary_constructor() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
enum _Private {
one;
factory _Private.a() => one;
@@ -1053,7 +1035,7 @@ DotShorthandConstructorInvocation
}
test_privateEnum_sameLibrary_invocation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
enum _Private {
one;
static _Private instance() => one;
@@ -1096,21 +1078,19 @@ typedef Public = _Private;
final Public p = _Private(1);
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .new(1);
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type '_Private'.
x = .named(1);
// ^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'named' isn't defined for the context type '_Private'.
print(x);
}
''',
[
error(diag.dotShorthandUndefinedInvocation, 51, 3),
error(diag.dotShorthandUndefinedInvocation, 66, 5),
],
);
''');
}
test_privateExtensionType_otherLibrary_invocation() async {
@@ -1123,21 +1103,20 @@ typedef Public = _Private;
final Public p = _Private(1);
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .instance();
// ^^^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'instance' isn't defined for the context type '_Private'.
print(x);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 51, 8)],
);
''');
}
test_privateExtensionType_sameLibrary_constructor() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
extension type _Private(int i) {}
typedef Public = _Private;
@@ -1175,7 +1154,7 @@ DotShorthandConstructorInvocation
}
test_privateExtensionType_sameLibrary_invocation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
extension type _Private(int it) {
static _Private instance() => _Private(0);
}
@@ -1218,21 +1197,20 @@ typedef Public = _Private;
final Public p = C();
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .instance();
// ^^^^^^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'instance' isn't defined for the context type '_Private'.
print(x);
}
''',
[error(diag.dotShorthandUndefinedInvocation, 51, 8)],
);
''');
}
test_privateMixin_sameLibrary_invocation() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
mixin _Private {
static _Private instance() => C();
}
@@ -1266,8 +1244,7 @@ DotShorthandInvocation
}
test_requiredParameters_missing() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C member({required int x}) => C(x);
int x;
@@ -1276,15 +1253,15 @@ class C {
void main() {
C c = .member();
// ^^^^^^
// [diag.missingRequiredArgument] The named parameter 'x' is required, but there's no corresponding argument.
print(c);
}
''',
[error(diag.missingRequiredArgument, 103, 6)],
);
''');
}
test_typeParameters_inference() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static C<X> foo<X>(X x) => new C<X>();
C<U> cast<U>() => new C<U>();
@@ -1318,8 +1295,7 @@ DotShorthandInvocation
}
test_typeParameters_notAssignable() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static C<int> member() => C(1);
@@ -1329,49 +1305,27 @@ class C<T> {
void main() {
C<bool> c = .member();
// ^^^^^^^^^
// [diag.invalidAssignment] A value of type 'C<int>' can't be assigned to a variable of type 'C<bool>'.
print(c);
}
''',
[error(diag.invalidAssignment, 105, 9)],
);
''');
}
test_undefinedInvocation_message() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
int f() => .foo();
''',
[
error(
diag.dotShorthandUndefinedInvocation,
12,
3,
messageContains: [
"context type 'int'",
"static method or constructor 'foo'",
],
),
],
);
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'foo' isn't defined for the context type 'int'.
''');
}
test_undefinedInvocation_message_equalityRhs() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
bool f(int x) => x == .foo();
''',
[
error(
diag.dotShorthandUndefinedInvocation,
23,
3,
messageContains: [
"context type 'int'",
"static method or constructor 'foo'",
],
),
],
);
// ^^^
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'foo' isn't defined for the context type 'int'.
''');
}
}
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -19,7 +18,7 @@ main() {
class DotShorthandPropertyAccessResolutionTest
extends PubPackageResolutionTest {
test_chain_method() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get member => C(1);
int x;
@@ -47,7 +46,7 @@ DotShorthandPropertyAccess
}
test_chain_property() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get member => C(1);
int x;
@@ -75,7 +74,7 @@ DotShorthandPropertyAccess
}
test_class_basic() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class C {
static C get member => C(1);
int x;
@@ -102,7 +101,7 @@ DotShorthandPropertyAccess
}
test_const_assert_class() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class Integer {
static const Integer one = const Integer._(1);
final int integer;
@@ -130,7 +129,7 @@ DotShorthandPropertyAccess
}
test_const_assert_enum() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
enum Color { red, green, blue }
class CAssert {
@@ -153,7 +152,7 @@ DotShorthandPropertyAccess
}
test_const_class() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class C {
static const C member = const C._(1);
final int x;
@@ -181,7 +180,7 @@ DotShorthandPropertyAccess
}
test_const_enum() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
enum Color { red, green, blue }
void main() {
@@ -204,7 +203,7 @@ DotShorthandPropertyAccess
}
test_const_extensionType() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension type C(int x) {
static const C member = const C._(1);
const C._(this.x);
@@ -230,7 +229,7 @@ DotShorthandPropertyAccess
}
test_enum_basic() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
enum C { red }
void main() {
@@ -253,7 +252,7 @@ DotShorthandPropertyAccess
}
test_equality() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
class C {
static C get member => C(1);
int x;
@@ -282,7 +281,7 @@ DotShorthandPropertyAccess
}
test_equality_indexExpression() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -308,7 +307,7 @@ DotShorthandPropertyAccess
}
test_equality_nullAssert() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -334,7 +333,7 @@ DotShorthandPropertyAccess
}
test_equality_nullAssert_chain() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -361,7 +360,7 @@ DotShorthandPropertyAccess
}
test_equality_pattern() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
enum Color { red, blue }
void main() {
@@ -384,63 +383,59 @@ DotShorthandPropertyAccess
}
test_error_context_invalid() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class C { }
void main() {
C Function() c = .member;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(c);
}
''',
[error(diag.dotShorthandMissingContext, 46, 7)],
);
''');
}
test_error_context_none() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
void main() {
var c = .member;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(c);
}
''',
[error(diag.dotShorthandMissingContext, 24, 7)],
);
''');
}
test_error_unresolved() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class C { }
void main() {
C c = .getter;
// ^^^^^^
// [diag.dotShorthandUndefinedGetter] The static getter 'getter' isn't defined for the context type 'C'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedGetter, 36, 6)],
);
''');
}
test_error_unresolved_new() async {
await assertErrorsInCode(
'''
await resolveTestCodeWithDiagnostics('''
class C {
C.named();
}
void main() {
C c = .new;
// ^^^
// [diag.dotShorthandUndefinedGetter] The static getter 'new' isn't defined for the context type 'C'.
print(c);
}
''',
[error(diag.dotShorthandUndefinedGetter, 49, 3)],
);
''');
}
test_extensionType() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
extension type C(int integer) {
static C get one => C(1);
}
@@ -465,7 +460,7 @@ DotShorthandPropertyAccess
}
test_functionExpression_call_argument() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static final C field = C();
C call(int a) => this;
@@ -502,7 +497,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_extension_field() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static final C field = C();
}
@@ -537,7 +532,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_extension_getter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get getter => C();
}
@@ -572,7 +567,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_field() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static final C field = C();
C call() => this;
@@ -604,7 +599,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static final C field = C();
C call<T>(T t) => this;
@@ -653,7 +648,7 @@ FunctionExpressionInvocation
}
test_functionExpression_call_getter() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get getter => C();
C call() => this;
@@ -685,37 +680,35 @@ FunctionExpressionInvocation
}
test_functionExpression_field() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static final C field = C();
}
void main() {
final C _ = .field();
// ^^^^^^
// [diag.invocationOfNonFunctionExpression] The expression doesn't evaluate to a function, so it can't be invoked.
}
''',
[error(diag.invocationOfNonFunctionExpression, 71, 6)],
);
''');
}
test_functionExpression_getter() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get getter => C();
}
void main() {
final C _ = .getter();
// ^^^^^^^
// [diag.invocationOfNonFunctionExpression] The expression doesn't evaluate to a function, so it can't be invoked.
}
''',
[error(diag.invocationOfNonFunctionExpression, 71, 7)],
);
''');
}
test_functionReference() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
static String foo<X>() => "C<$X>";
@@ -748,7 +741,7 @@ DotShorthandPropertyAccess
}
test_futureOr() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'dart:async';
enum C { red }
@@ -773,7 +766,7 @@ DotShorthandPropertyAccess
}
test_futureOr_nested() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
import 'dart:async';
enum C { red }
@@ -798,7 +791,7 @@ DotShorthandPropertyAccess
}
test_mixin() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
int x;
C(this.x);
@@ -833,8 +826,7 @@ DotShorthandPropertyAccess
}
test_postfixOperator() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get member => C(1);
int x;
@@ -843,19 +835,17 @@ class C {
void main() {
C c = .member++;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
// ^^
// [diag.illegalAssignmentToNonAssignable] Illegal assignment to non-assignable expression.
print(c);
}
''',
[
error(diag.dotShorthandMissingContext, 88, 7),
error(diag.illegalAssignmentToNonAssignable, 95, 2),
],
);
''');
}
test_prefixOperator() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
class C {
static C get member => C(1);
int x;
@@ -864,14 +854,13 @@ class C {
void main() {
C c = ++.member;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
// ^^^^^^
// [diag.missingAssignableSelector] Missing selector such as '.identifier' or '[0]'.
print(c);
}
''',
[
error(diag.dotShorthandMissingContext, 90, 7),
error(diag.missingAssignableSelector, 91, 6),
],
);
''');
}
test_privateClass_otherLibrary() async {
@@ -884,21 +873,20 @@ typedef Public = _Private;
final Public p = _Private();
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .getter;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(x);
}
''',
[error(diag.dotShorthandMissingContext, 50, 7)],
);
''');
}
test_privateClass_sameLibrary() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class _Private {
static _Private get getter => _Private();
}
@@ -934,21 +922,20 @@ typedef Public = _Private;
final Public p = _Private.one;
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .two;
// ^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(x);
}
''',
[error(diag.dotShorthandMissingContext, 50, 4)],
);
''');
}
test_privateEnum_sameLibrary() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
enum _Private { one, two }
typedef Public = _Private;
@@ -984,21 +971,20 @@ typedef Public = _Private;
final Public p = _Private(1);
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .getter;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(x);
}
''',
[error(diag.dotShorthandMissingContext, 50, 7)],
);
''');
}
test_privateExtensionType_sameLibrary() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
extension type _Private(int i) {
static _Private get getter => _Private(0);
}
@@ -1037,21 +1023,20 @@ typedef Public = _Private;
final Public p = C();
''');
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
import 'a.dart';
void main() {
var x = p;
x = .getter;
// ^^^^^^^
// [diag.dotShorthandMissingContext] A dot shorthand can't be used where there is no context type.
print(x);
}
''',
[error(diag.dotShorthandMissingContext, 50, 7)],
);
''');
}
test_privateMixin_sameLibrary() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
mixin _Private {
static _Private get getter => C();
}
@@ -1081,7 +1066,7 @@ DotShorthandPropertyAccess
}
test_tearOff_constructor() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C1 {
C1.id();
@@ -1110,18 +1095,17 @@ DotShorthandPropertyAccess
}
test_tearOff_constructor_abstract() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
Function fn() {
return .new;
// ^^^^
// [diag.tearoffOfGenerativeConstructorOfAbstractClass] A generative constructor of an abstract class can't be torn off.
}
''',
[error(diag.tearoffOfGenerativeConstructorOfAbstractClass, 25, 4)],
);
''');
}
test_tearOff_constructor_generic() async {
await assertNoErrorsInCode(r'''
await resolveTestCodeWithDiagnostics(r'''
class C<T> {
T t;
C(this.t);
@@ -1154,7 +1138,7 @@ DotShorthandPropertyAccess
}
test_tearOff_constructor_new() async {
await assertNoErrorsInCode('''
await resolveTestCodeWithDiagnostics('''
void main() {
Object o = .new;
print(o);
@@ -1175,34 +1159,18 @@ DotShorthandPropertyAccess
}
test_undefinedGetter_message() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
int f() => .foo;
''',
[
error(
diag.dotShorthandUndefinedGetter,
12,
3,
messageContains: ["static getter 'foo'", "context type 'int'"],
),
],
);
// ^^^
// [diag.dotShorthandUndefinedGetter] The static getter 'foo' isn't defined for the context type 'int'.
''');
}
test_undefinedGetter_message_equalityRhs() async {
await assertErrorsInCode(
r'''
await resolveTestCodeWithDiagnostics(r'''
bool f(int x) => x == .foo;
''',
[
error(
diag.dotShorthandUndefinedGetter,
23,
3,
messageContains: ["static getter 'foo'", "context type 'int'"],
),
],
);
// ^^^
// [diag.dotShorthandUndefinedGetter] The static getter 'foo' isn't defined for the context type 'int'.
''');
}
}