CQ. Replace more assertErrorsInCode() with resolveTestCodeWithDiagnostics().
Change-Id: Icc6c61a73608039ed453be72f5e7ae60201ba5f1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504420 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
f75086bb05
commit
9bc1a1015b
@@ -4,15 +4,16 @@
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/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 '../../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(FragmentOffsetTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,13 +85,12 @@ class C = Object with M;
|
||||
}
|
||||
|
||||
test_classFragment_classTypeAlias_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {}
|
||||
class = Object with M;
|
||||
''',
|
||||
[error(diag.missingIdentifier, 17, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var classTypeAlias = findNode.classTypeAlias('Object with M');
|
||||
checkOffsetInRange<ClassFragment>(
|
||||
classTypeAlias,
|
||||
@@ -99,14 +99,13 @@ class = Object with M;
|
||||
}
|
||||
|
||||
test_classFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library; // Ensures that the class declaration isn't at offset 0
|
||||
|
||||
class {}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 72, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var classDeclaration = findNode.classDeclaration('class {}');
|
||||
checkOffsetInRange<ClassFragment>(
|
||||
classDeclaration,
|
||||
@@ -131,14 +130,13 @@ class C {}
|
||||
}
|
||||
|
||||
test_constructorFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C.();
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 14, 1)],
|
||||
);
|
||||
''');
|
||||
var constructorDeclaration = findNode.constructor('C.()');
|
||||
checkOffsetInRange<ConstructorFragment>(
|
||||
constructorDeclaration,
|
||||
@@ -199,14 +197,13 @@ enum E { e1 }
|
||||
}
|
||||
|
||||
test_enumFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library; // Ensures that the enum declaration isn't at offset 0
|
||||
|
||||
enum { e1 }
|
||||
''',
|
||||
[error(diag.missingIdentifier, 70, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var enumDeclaration = findNode.enumDeclaration('enum { e1 }');
|
||||
checkOffsetInRange<EnumFragment>(
|
||||
enumDeclaration,
|
||||
@@ -254,14 +251,13 @@ extension type E(int i) {}
|
||||
}
|
||||
|
||||
test_extensionTypeFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library; // Ensures that the extension type declaration isn't at offset 0
|
||||
|
||||
extension type(int i) {}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 89, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var extensionTypeDeclaration = findNode.extensionTypeDeclaration(
|
||||
'extension type(int i)',
|
||||
);
|
||||
@@ -287,18 +283,16 @@ class C {
|
||||
}
|
||||
|
||||
test_fieldFormalParameterFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
int? x;
|
||||
C(this.);
|
||||
// ^^^^^
|
||||
// [diag.initializingFormalForNonExistentField] '' isn't a field in the enclosing class.
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.initializingFormalForNonExistentField, 24, 5),
|
||||
error(diag.missingIdentifier, 29, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var parameter = findNode.fieldFormalParameter('this.');
|
||||
checkOffsetInRange<FieldFormalParameterFragment>(
|
||||
parameter,
|
||||
@@ -388,12 +382,11 @@ void f(int x) {}
|
||||
}
|
||||
|
||||
test_formalParameterFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int x)) {}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 7, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var function = findNode.functionDeclaration('f(');
|
||||
var parameter =
|
||||
function.functionExpression.parameters!.parameters[0]
|
||||
@@ -406,12 +399,11 @@ void f((int x)) {}
|
||||
}
|
||||
|
||||
test_formalParameterFragment_missingName2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(void (int x)) {}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 12, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var function = findNode.functionDeclaration('f(');
|
||||
var parameter =
|
||||
function.functionExpression.parameters!.parameters[0]
|
||||
@@ -745,14 +737,13 @@ mixin M {}
|
||||
}
|
||||
|
||||
test_mixinFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library; // Ensures that the mixin declaration isn't at offset 0
|
||||
|
||||
mixin {}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 72, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var mixinDeclaration = findNode.mixinDeclaration('mixin {}');
|
||||
checkOffsetInRange<MixinFragment>(
|
||||
mixinDeclaration,
|
||||
@@ -801,13 +792,12 @@ import 'dart:math' as a; // second
|
||||
}
|
||||
|
||||
test_prefixFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore: unused_import
|
||||
import 'dart:async' as;
|
||||
''',
|
||||
[error(diag.missingIdentifier, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var importDirective = findNode.import('as;');
|
||||
checkOffsetInRange<PrefixFragment>(
|
||||
importDirective,
|
||||
@@ -895,18 +885,17 @@ class C extends B {
|
||||
}
|
||||
|
||||
test_superFormalParameterFragment_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B {
|
||||
B([int? i]);
|
||||
}
|
||||
|
||||
class C extends B {
|
||||
C(super.);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 58, 1)],
|
||||
);
|
||||
''');
|
||||
var parameter = findNode.superFormalParameter('super.');
|
||||
checkOffsetInRange<SuperFormalParameterFragment>(
|
||||
parameter,
|
||||
@@ -987,14 +976,14 @@ typedef void F();
|
||||
}
|
||||
|
||||
test_typeAliasFragment_functionTypeAlias_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library; // Ensures that the function type alias declaration isn't at offset 0
|
||||
// [diag.unusedElement][column 1][length 0] The declaration '<unnamed>' isn't referenced.
|
||||
|
||||
typedef void();
|
||||
''',
|
||||
[error(diag.unusedElement, 0, 0), error(diag.missingIdentifier, 92, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var functionTypeAlias = findNode.functionTypeAlias('void()');
|
||||
checkOffsetInRange<TypeAliasFragment>(
|
||||
functionTypeAlias,
|
||||
@@ -1015,14 +1004,14 @@ typedef T = int;
|
||||
}
|
||||
|
||||
test_typeAliasFragment_genericTypeAlias_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library; // Ensures that the generic type alias declaration isn't at offset 0
|
||||
// [diag.unusedElement][column 1][length 0] The declaration '<unnamed>' isn't referenced.
|
||||
|
||||
typedef = int;
|
||||
''',
|
||||
[error(diag.unusedElement, 0, 0), error(diag.missingIdentifier, 87, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
''');
|
||||
var genericTypeAlias = findNode.genericTypeAlias('= int');
|
||||
checkOffsetInRange<TypeAliasFragment>(
|
||||
genericTypeAlias,
|
||||
|
||||
@@ -10,10 +10,12 @@ import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonErrorResolverTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,14 +78,13 @@ export 'lib2.dart' show C;
|
||||
library lib;
|
||||
class N {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library L;
|
||||
export 'lib.dart';
|
||||
export 'lib.dart';
|
||||
''',
|
||||
[error(diag.duplicateExport, 37, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.duplicateExport] Duplicate export.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ambiguousImport_dart_implicitHide() async {
|
||||
@@ -139,17 +140,16 @@ library lib2;
|
||||
class N {}
|
||||
class N2 {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart' show N, N2;
|
||||
// ^
|
||||
// [diag.unusedShownName] The name N is shown, but isn't used.
|
||||
main() {
|
||||
new N1();
|
||||
new N2();
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedShownName, 44, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_annotated_partOfDeclaration() async {
|
||||
@@ -342,15 +342,14 @@ main() {
|
||||
}
|
||||
|
||||
test_assignmentToFinal_prefixNegate() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
-x;
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 14, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_assignmentToFinalNoSetter_prefixedIdentifier() async {
|
||||
@@ -428,15 +427,14 @@ dynamic f() async {}
|
||||
}
|
||||
|
||||
test_async_expression_function_type() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef Future<int> F(int i);
|
||||
main() {
|
||||
F f = (int i) async => i;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'f' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_async_flattened() async {
|
||||
@@ -556,27 +554,25 @@ f() async {}
|
||||
}
|
||||
|
||||
test_asyncForInWrongContext_async() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(list) async {
|
||||
await for (var e in list) {
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_asyncForInWrongContext_asyncStar() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(list) async* {
|
||||
await for (var e in list) {
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_await_flattened() async {
|
||||
@@ -663,14 +659,13 @@ typedef Foo(param);
|
||||
}
|
||||
|
||||
test_builtInIdentifierAsType_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
dynamic x;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 16, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_castFrom() async {
|
||||
@@ -678,18 +673,17 @@ f() {
|
||||
// substitution in the `newSet` parameter of `Set.castFrom`, we wind up with
|
||||
// a synthetic `ParameterMember` that belongs to no library. We need to
|
||||
// make sure this doesn't lead to a crash.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {}
|
||||
|
||||
void testNewSet(Set<C> setEls) {
|
||||
var customNewSet;
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'customNewSet' isn't used.
|
||||
Set.castFrom<C, Object>(setEls,
|
||||
newSet: <T>() => customNewSet = new Set<T>());
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 51, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_type_alias_documentationComment() async {
|
||||
@@ -802,17 +796,16 @@ class C extends A {
|
||||
}
|
||||
|
||||
test_constConstructorWithNonConstSuper_unresolved() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.a();
|
||||
}
|
||||
class B extends A {
|
||||
const B(): super();
|
||||
// ^^^^^^^
|
||||
// [diag.undefinedConstructorInInitializerDefault] The class 'A' doesn't have an unnamed constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedConstructorInInitializerDefault, 54, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constConstructorWithNonFinalField_finalInstanceVar() async {
|
||||
@@ -1081,14 +1074,13 @@ A a = new A();
|
||||
}
|
||||
|
||||
test_dynamicIdentifier() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
var v = dynamic;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 15, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_empty_generator_async() async {
|
||||
@@ -1516,32 +1508,31 @@ test() {
|
||||
|
||||
test_importDuplicatedLibraryName() async {
|
||||
newFile("$testPackageLibPath/lib.dart", "library lib;");
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library test;
|
||||
import 'lib.dart';
|
||||
// ^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'lib.dart'.
|
||||
import 'lib.dart';
|
||||
''',
|
||||
[
|
||||
error(diag.unusedImport, 21, 10),
|
||||
error(diag.unusedImport, 40, 10),
|
||||
error(diag.duplicateImport, 40, 10),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.duplicateImport] Duplicate import.
|
||||
// [diag.unusedImport] Unused import: 'lib.dart'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_importDuplicatedLibraryUnnamed() async {
|
||||
newFile("$testPackageLibPath/lib1.dart", '');
|
||||
newFile("$testPackageLibPath/lib2.dart", '');
|
||||
// No warning on duplicate import (https://github.com/dart-lang/sdk/issues/24156)
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library test;
|
||||
import 'lib1.dart';
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'lib1.dart'.
|
||||
import 'lib2.dart';
|
||||
''',
|
||||
[error(diag.unusedImport, 21, 11), error(diag.unusedImport, 41, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'lib2.dart'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_importOfNonLibrary_libraryDeclared() async {
|
||||
@@ -1724,15 +1715,14 @@ class A {
|
||||
static var _m;
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib.dart';
|
||||
class B extends A {
|
||||
_m() {}
|
||||
//^^
|
||||
// [diag.unusedElement] The declaration '_m' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 41, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_instanceMethodNameCollidesWithSuperclassStatic_method() async {
|
||||
@@ -1742,15 +1732,14 @@ class A {
|
||||
static _m() {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib.dart';
|
||||
class B extends A {
|
||||
_m() {}
|
||||
//^^
|
||||
// [diag.unusedElement] The declaration '_m' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 41, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_instantiateGenericFunctionWithNamedParameterAsGenericArg() async {
|
||||
@@ -1892,22 +1881,21 @@ main() {
|
||||
}
|
||||
|
||||
test_invalidIdentifierInAsync() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() {
|
||||
int async;
|
||||
// ^^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'async' isn't used.
|
||||
int await;
|
||||
// ^^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used.
|
||||
int yield;
|
||||
// ^^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 26, 5),
|
||||
error(diag.unusedLocalVariable, 41, 5),
|
||||
error(diag.unusedLocalVariable, 56, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_invalidMethodOverrideNamedParamType() async {
|
||||
@@ -2091,21 +2079,19 @@ f(S s) async {
|
||||
}
|
||||
|
||||
test_issue_32394() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var x = y.map((a) => a.toString());
|
||||
var y = [3];
|
||||
var z = x.toList();
|
||||
|
||||
void main() {
|
||||
String p = z;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'p' isn't used.
|
||||
// ^
|
||||
// [diag.invalidAssignment] A value of type 'List<String>' can't be assigned to a variable of type 'String'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 93, 1),
|
||||
error(diag.invalidAssignment, 97, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var z = result.unit.declaredFragment!.element.topLevelVariables
|
||||
.where((e) => e.name == 'z')
|
||||
.single;
|
||||
@@ -2153,16 +2139,15 @@ int f(v) {
|
||||
}
|
||||
|
||||
test_librarySource_of_type_substituted_synthetic_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Map<int, T> f<T>(T t) => throw '';
|
||||
Map<double, T> g<T>(T t) => throw '';
|
||||
h(bool b) {
|
||||
Map<num, String> m = (b ? f : g)('x');
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'm' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 104, 1)],
|
||||
);
|
||||
''');
|
||||
var parameter = findNode.stringLiteral("'x'").correspondingParameter;
|
||||
expect(parameter!.library, isNull);
|
||||
expect(parameter.library?.firstFragment.source, isNull);
|
||||
@@ -2408,18 +2393,17 @@ f(bool pb, pd) {
|
||||
}
|
||||
|
||||
test_nonBoolNegationExpression_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f1(bool dynamic) {
|
||||
!dynamic;
|
||||
}
|
||||
f2() {
|
||||
bool dynamic = true;
|
||||
// ^^^^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'dynamic' isn't used.
|
||||
!dynamic;
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 47, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonBoolOperand_and_bool() async {
|
||||
@@ -2545,14 +2529,13 @@ f() {
|
||||
}
|
||||
|
||||
test_nonConstMapAsExpressionStatement_notExpressionStatement() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
var m = {'a' : 0, 'b' : 1};
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'm' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 12, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConstMapAsExpressionStatement_typeArguments() async {
|
||||
@@ -2572,18 +2555,17 @@ main() {
|
||||
}
|
||||
|
||||
test_nonConstValueInInitializer_binary_bool() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
final v;
|
||||
const A.a1(bool p) : v = p && true;
|
||||
const A.a2(bool p) : v = true && p;
|
||||
const A.b1(bool p) : v = p || true;
|
||||
const A.b2(bool p) : v = true || p;
|
||||
// ^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 167, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConstValueInInitializer_binary_dynamic() async {
|
||||
@@ -2823,17 +2805,16 @@ main() {}
|
||||
test_parameterScope_local() async {
|
||||
// Parameter names shouldn't conflict with the name of the function they
|
||||
// are enclosed in.
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
g(g) {
|
||||
//^
|
||||
// [diag.unusedElement] The declaration 'g' isn't referenced.
|
||||
h(g);
|
||||
}
|
||||
}
|
||||
h(x) {}
|
||||
''',
|
||||
[error(diag.unusedElement, 8, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameterScope_method() async {
|
||||
@@ -2896,45 +2877,42 @@ class B<S> extends A<S> {
|
||||
}
|
||||
|
||||
test_referenceToDeclaredVariableInInitializer_constructorName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.x() {}
|
||||
}
|
||||
f() {
|
||||
var x = new A.x();
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 35, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_referenceToDeclaredVariableInInitializer_methodName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
x() {}
|
||||
}
|
||||
f(A a) {
|
||||
var x = a.x();
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_referenceToDeclaredVariableInInitializer_propertyName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
var x;
|
||||
}
|
||||
f(A a) {
|
||||
var x = a.x;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_regress34906() async {
|
||||
@@ -3141,19 +3119,18 @@ void f(A<V> p) {
|
||||
}
|
||||
|
||||
test_typePromotion_if_inClosure_assignedAfter_inSameFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
f(Object p) {
|
||||
//^
|
||||
// [diag.unusedElement] The declaration 'f' isn't referenced.
|
||||
if (p is String) {
|
||||
p.length;
|
||||
}
|
||||
p = 0;
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 11, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_is_and_left() async {
|
||||
|
||||
@@ -6,11 +6,13 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
import 'test_support.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonHintCodeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,23 +20,21 @@ main() {
|
||||
class NonHintCodeTest extends PubPackageResolutionTest {
|
||||
test_issue20904BuggyTypePromotionAtIfJoin_1() async {
|
||||
// https://code.google.com/p/dart/issues/detail?id=20904
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(message, dynamic_) {
|
||||
if (message is Function) {
|
||||
message = dynamic_;
|
||||
}
|
||||
int s = message;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 's' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 86, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_issue20904BuggyTypePromotionAtIfJoin_3() async {
|
||||
// https://code.google.com/p/dart/issues/detail?id=20904
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(message) {
|
||||
var dynamic_;
|
||||
if (message is Function) {
|
||||
@@ -43,16 +43,15 @@ f(message) {
|
||||
return;
|
||||
}
|
||||
int s = message;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 's' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 115, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_issue20904BuggyTypePromotionAtIfJoin_4() async {
|
||||
// https://code.google.com/p/dart/issues/detail?id=20904
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(message) {
|
||||
if (message is Function) {
|
||||
message = '';
|
||||
@@ -60,10 +59,10 @@ f(message) {
|
||||
return;
|
||||
}
|
||||
String s = message;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 's' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 96, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propagatedFieldType() async {
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(StrictModeTest);
|
||||
defineReflectiveTests(TypePropagationTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,14 +20,13 @@ main() {
|
||||
@reflectiveTest
|
||||
class StrictModeTest extends PubPackageResolutionTest {
|
||||
test_assert_is() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f(num n) {
|
||||
assert (n is int);
|
||||
return n & 0x0F;
|
||||
}''',
|
||||
[error(diag.undefinedOperator, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.undefinedOperator] The operator '&' isn't defined for the type 'num'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_conditional_and_is() async {
|
||||
@@ -71,17 +71,16 @@ void f(List<int> list) {
|
||||
}
|
||||
|
||||
test_forEach() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(List<int> list) {
|
||||
num sum = 0; // ignore: unused_local_variable
|
||||
for (num n in list) {
|
||||
sum += n & 0x0F;
|
||||
// ^
|
||||
// [diag.undefinedOperator] The operator '&' isn't defined for the type 'num'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedOperator, 110, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_if_and_is() async {
|
||||
@@ -140,14 +139,13 @@ int f(num n) {
|
||||
}
|
||||
|
||||
test_localVar() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f() {
|
||||
num n = 1234;
|
||||
return n & 0x0F;
|
||||
}''',
|
||||
[error(diag.undefinedOperator, 37, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.undefinedOperator] The operator '&' isn't defined for the type 'num'.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/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 '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SimpleResolverTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -522,19 +523,17 @@ SimpleIdentifier
|
||||
}
|
||||
|
||||
test_forEachLoops_nonConflicting() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
List list = [1,2,3];
|
||||
for (int x in list) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
for (int x in list) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 40, 1),
|
||||
error(diag.unusedLocalVariable, 65, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forLoops_nonConflicting() async {
|
||||
@@ -585,8 +584,7 @@ SimpleIdentifier
|
||||
}
|
||||
|
||||
test_getter_fromMixins_property_access() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class B {}
|
||||
mixin M1 {
|
||||
get x => null;
|
||||
@@ -597,10 +595,10 @@ mixin M2 {
|
||||
class C extends B with M1, M2 {}
|
||||
void main() {
|
||||
var y = new C().x;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 124, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
// Verify that the getter for "x" in "new C().x" refers to the getter
|
||||
// defined in M2.
|
||||
@@ -649,9 +647,10 @@ main() {
|
||||
// single error generated when the only problem is that an imported file
|
||||
// does not exist.
|
||||
//
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'missing.dart' as p;
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'missing.dart'.
|
||||
int a = p.q + p.r.s;
|
||||
String b = p.t(a) + p.u(v: 0);
|
||||
p.T c = new p.T();
|
||||
@@ -666,9 +665,7 @@ class G extends Object with p.V {}
|
||||
class H extends D<p.W> {
|
||||
H(int i) : super(i);
|
||||
}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 14)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_import_show_doesNotExist() async {
|
||||
@@ -677,9 +674,10 @@ class H extends D<p.W> {
|
||||
// single error generated when the only problem is that an imported file
|
||||
// does not exist.
|
||||
//
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'missing.dart' show q, r, t, u, T, U, V, W;
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'missing.dart'.
|
||||
int a = q + r.s;
|
||||
String b = t(a) + u(v: 0);
|
||||
T c = new T();
|
||||
@@ -694,9 +692,7 @@ class G extends Object with V {}
|
||||
class H extends D<W> {
|
||||
H(int i) : super(i);
|
||||
}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 14)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_import_spaceInUri() async {
|
||||
@@ -724,14 +720,13 @@ f() {
|
||||
}
|
||||
|
||||
test_indexExpression_typeParameters_invalidAssignmentWarning() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
List<List<int>> b = [];
|
||||
b[0][0] = 'hi';
|
||||
}''',
|
||||
[error(diag.invalidAssignment, 44, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_indirectOperatorThroughCall() async {
|
||||
@@ -764,12 +759,13 @@ class A {
|
||||
}
|
||||
|
||||
test_isValidMixin_badSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
class A extends B {}
|
||||
class B {}
|
||||
class C = Object with A;''',
|
||||
[error(diag.classUsedAsMixin, 54, 1)],
|
||||
class C = Object with A;
|
||||
// ^
|
||||
// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin.''',
|
||||
);
|
||||
|
||||
var a = findElement2.class_('A');
|
||||
@@ -777,13 +773,14 @@ class C = Object with A;''',
|
||||
}
|
||||
|
||||
test_isValidMixin_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
class C = Object with A;''',
|
||||
[error(diag.classUsedAsMixin, 43, 1)],
|
||||
class C = Object with A;
|
||||
// ^
|
||||
// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin.''',
|
||||
);
|
||||
|
||||
var a = findElement2.class_('A');
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/element/type.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 '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(StaticTypeAnalyzerTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,18 +44,16 @@ late Derived<Derived<int>> derivedDerivedInt;
|
||||
}
|
||||
|
||||
test_flatten_inhibit_recursion() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B extends A {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
late A a;
|
||||
late B b;
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var aType = findElement2.topVar('a').type;
|
||||
var bType = findElement2.topVar('b').type;
|
||||
// flatten(A) = A and flatten(B) = B, since neither class contains Future
|
||||
@@ -65,22 +64,21 @@ late B b;
|
||||
}
|
||||
|
||||
test_flatten_related_derived_types() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class Derived<T> implements Future<T> {}
|
||||
abstract class A extends Derived<int> implements Derived<num> {}
|
||||
// ^
|
||||
// [diag.conflictingGenericInterfaces] The class 'A' can't implement both 'Derived<int>' and 'Derived<num>' because the type arguments are different.
|
||||
// [diag.conflictingGenericInterfaces] The class 'A' can't implement both 'Future<int>' and 'Future<num>' because the type arguments are different.
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.implementsSuperClass] 'abstract class Derived<T> implements Future<T>' can't be used in both the 'extends' and 'implements' clauses.
|
||||
abstract class B1 implements Future<num> {}
|
||||
abstract class B2 extends B1 implements Future<int> {}
|
||||
// ^^
|
||||
// [diag.conflictingGenericInterfaces] The class 'B2' can't implement both 'Future<num>' and 'Future<int>' because the type arguments are different.
|
||||
late A a;
|
||||
late B2 b;
|
||||
''',
|
||||
[
|
||||
error(diag.conflictingGenericInterfaces, 65, 1),
|
||||
error(diag.conflictingGenericInterfaces, 65, 1),
|
||||
error(diag.implementsSuperClass, 99, 12),
|
||||
error(diag.conflictingGenericInterfaces, 174, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
InterfaceType intType = typeProvider.intType;
|
||||
InterfaceType numType = typeProvider.numType;
|
||||
var aType = findElement2.topVar('a').type;
|
||||
@@ -92,20 +90,18 @@ late B2 b;
|
||||
}
|
||||
|
||||
test_flatten_related_types() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A1 implements Future<int> {}
|
||||
abstract class A2 extends A1 implements Future<num> {}
|
||||
// ^^
|
||||
// [diag.conflictingGenericInterfaces] The class 'A2' can't implement both 'Future<int>' and 'Future<num>' because the type arguments are different.
|
||||
abstract class B1 implements Future<num> {}
|
||||
abstract class B2 extends B1 implements Future<int> {}
|
||||
// ^^
|
||||
// [diag.conflictingGenericInterfaces] The class 'B2' can't implement both 'Future<num>' and 'Future<int>' because the type arguments are different.
|
||||
late A2 a;
|
||||
late B2 b;
|
||||
''',
|
||||
[
|
||||
error(diag.conflictingGenericInterfaces, 59, 2),
|
||||
error(diag.conflictingGenericInterfaces, 158, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
InterfaceType intType = typeProvider.intType;
|
||||
InterfaceType numType = typeProvider.numType;
|
||||
var aType = findElement2.topVar('a').type;
|
||||
@@ -139,26 +135,24 @@ late B2 b;
|
||||
}
|
||||
|
||||
test_flatten_unrelated_types() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A1 implements Future<int> {}
|
||||
abstract class A2 extends A1 implements Future<String> {}
|
||||
// ^^
|
||||
// [diag.inconsistentInheritance] Superinterfaces don't have a valid override for 'catchError': Future.catchError (Future<int> Function(Function, {bool Function(Object)? test})), Future.catchError (Future<String> Function(Function, {bool Function(Object)? test})).
|
||||
// [diag.inconsistentInheritance] Superinterfaces don't have a valid override for 'then': Future.then (Future<R> Function<R>(FutureOr<R> Function(int), {Function? onError})), Future.then (Future<R> Function<R>(FutureOr<R> Function(String), {Function? onError})).
|
||||
// [diag.inconsistentInheritance] Superinterfaces don't have a valid override for 'whenComplete': Future.whenComplete (Future<int> Function(FutureOr<void> Function())), Future.whenComplete (Future<String> Function(FutureOr<void> Function())).
|
||||
// [diag.conflictingGenericInterfaces] The class 'A2' can't implement both 'Future<int>' and 'Future<String>' because the type arguments are different.
|
||||
abstract class B1 implements Future<String> {}
|
||||
abstract class B2 extends B1 implements Future<int> {}
|
||||
// ^^
|
||||
// [diag.inconsistentInheritance] Superinterfaces don't have a valid override for 'catchError': Future.catchError (Future<String> Function(Function, {bool Function(Object)? test})), Future.catchError (Future<int> Function(Function, {bool Function(Object)? test})).
|
||||
// [diag.inconsistentInheritance] Superinterfaces don't have a valid override for 'then': Future.then (Future<R> Function<R>(FutureOr<R> Function(String), {Function? onError})), Future.then (Future<R> Function<R>(FutureOr<R> Function(int), {Function? onError})).
|
||||
// [diag.inconsistentInheritance] Superinterfaces don't have a valid override for 'whenComplete': Future.whenComplete (Future<String> Function(FutureOr<void> Function())), Future.whenComplete (Future<int> Function(FutureOr<void> Function())).
|
||||
// [diag.conflictingGenericInterfaces] The class 'B2' can't implement both 'Future<String>' and 'Future<int>' because the type arguments are different.
|
||||
late A2 a;
|
||||
late B2 b;
|
||||
''',
|
||||
[
|
||||
error(diag.inconsistentInheritance, 59, 2),
|
||||
error(diag.inconsistentInheritance, 59, 2),
|
||||
error(diag.inconsistentInheritance, 59, 2),
|
||||
error(diag.conflictingGenericInterfaces, 59, 2),
|
||||
error(diag.inconsistentInheritance, 164, 2),
|
||||
error(diag.inconsistentInheritance, 164, 2),
|
||||
error(diag.inconsistentInheritance, 164, 2),
|
||||
error(diag.conflictingGenericInterfaces, 164, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var aType = findElement2.topVar('a').type;
|
||||
var bType = findElement2.topVar('b').type;
|
||||
// flatten(A) = A and flatten(B) = B, since neither string nor int is more
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(StaticTypeWarningCodeTest);
|
||||
defineReflectiveTests(StrongModeStaticTypeWarningCodeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,134 +21,119 @@ main() {
|
||||
@reflectiveTest
|
||||
class StaticTypeWarningCodeTest extends PubPackageResolutionTest {
|
||||
test_await_flattened() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external Future<Future<int>> ffi();
|
||||
f() async {
|
||||
Future<int> b = await ffi();
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 62, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_await_simple() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int> fi() => Future.value(0);
|
||||
f() async {
|
||||
String a = await fi(); // Warning: int not assignable to String
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.invalidAssignment] A value of type 'int' can't be assigned to a variable of type 'String'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 58, 1),
|
||||
error(diag.invalidAssignment, 62, 10),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_declaredVariableRightType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<int> stream) async {
|
||||
await for (int i in stream) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 47, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_declaredVariableWrongType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<String> stream) async {
|
||||
await for (int i in stream) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
// ^^^^^^
|
||||
// [diag.forInOfInvalidElementType] The type 'Stream<String>' used in the 'for' loop must implement 'Stream' with a type argument that can be assigned to 'int'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 50, 1),
|
||||
error(diag.forInOfInvalidElementType, 55, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_downcast() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<num> stream) async {
|
||||
await for (int i in stream) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
// ^^^^^^
|
||||
// [diag.forInOfInvalidElementType] The type 'Stream<num>' used in the 'for' loop must implement 'Stream' with a type argument that can be assigned to 'int'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 47, 1),
|
||||
error(diag.forInOfInvalidElementType, 52, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_dynamicVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<int> stream) async {
|
||||
await for (var i in stream) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 47, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_existingVariableRightType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<int> stream) async {
|
||||
late int i;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
await for (i in stream) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 41, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_existingVariableWrongType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<String> stream) async {
|
||||
late int i;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
await for (i in stream) {}
|
||||
// ^^^^^^
|
||||
// [diag.forInOfInvalidElementType] The type 'Stream<String>' used in the 'for' loop must implement 'Stream' with a type argument that can be assigned to 'int'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 44, 1),
|
||||
error(diag.forInOfInvalidElementType, 65, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_streamOfDynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream stream) async {
|
||||
await for (int i in stream) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 42, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_awaitForIn_upcast() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(Stream<int> stream) async {
|
||||
await for (num i in stream) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 47, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_bug21912() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
class B extends A {}
|
||||
|
||||
@@ -161,250 +147,228 @@ void f(
|
||||
) {
|
||||
{
|
||||
Function2<Function2<int, double>, Function2<int, double>> left;
|
||||
// ^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'left' isn't used.
|
||||
|
||||
left = t1;
|
||||
// ^^
|
||||
// [diag.invalidAssignment] A value of type 'Function2<Function2<A, B>, Function2<B, A>>' can't be assigned to a variable of type 'Function2<Function2<int, double>, Function2<int, double>>'.
|
||||
left = t2;
|
||||
// ^^
|
||||
// [diag.invalidAssignment] A value of type 'Function2<AToB, BToA>' can't be assigned to a variable of type 'Function2<Function2<int, double>, Function2<int, double>>'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 263, 4),
|
||||
error(diag.invalidAssignment, 281, 2),
|
||||
error(diag.invalidAssignment, 296, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_declaredVariableRightType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
for (int i in <int>[]) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 17, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_declaredVariableWrongType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
for (int i in <String>[]) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.forInOfInvalidElementType] The type 'List<String>' used in the 'for' loop must implement 'Iterable' with a type argument that can be assigned to 'int'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 17, 1),
|
||||
error(diag.forInOfInvalidElementType, 22, 10),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
dynamic d; // Could be [].
|
||||
for (var i in d) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 46, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_dynamicIterable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
dynamic iterable;
|
||||
for (int i in iterable) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 37, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_dynamicVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
for (var i in <int>[]) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 17, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_existingVariableRightType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
int i;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
for (i in <int>[]) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 12, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_existingVariableWrongType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
int i;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
for (i in <String>[]) {}
|
||||
// ^^^^^^^^^^
|
||||
// [diag.forInOfInvalidElementType] The type 'List<String>' used in the 'for' loop must implement 'Iterable' with a type argument that can be assigned to 'int'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 12, 1),
|
||||
error(diag.forInOfInvalidElementType, 27, 10),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_iterableOfDynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
for (int i in []) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 17, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_object() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f(List o) { // Could be [].
|
||||
for (var i in o) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 39, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_typeBoundBad() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class Foo<T extends Iterable<int>> {
|
||||
void method(T iterable) {
|
||||
for (String i in iterable) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
// ^^^^^^^^
|
||||
// [diag.forInOfInvalidElementType] The type 'Iterable<int>' used in the 'for' loop must implement 'Iterable' with a type argument that can be assigned to 'String'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 81, 1),
|
||||
error(diag.forInOfInvalidElementType, 86, 8),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_typeBoundGood() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class Foo<T extends Iterable<int>> {
|
||||
void method(T iterable) {
|
||||
for (var i in iterable) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 78, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forIn_upcast() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
for (num i in <int>[]) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 17, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
callMe(f()) { f(); }
|
||||
f(Object p) {
|
||||
(p is String) && callMe(() { p.length; });
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
p = 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 68, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_booleanAnd_useInRight_mutatedInLeft() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object p) {
|
||||
((p is String) && ((p = 42) == 42)) && p.length != 0;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 57, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_booleanAnd_useInRight_mutatedInRight() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object p) {
|
||||
(p is String) && (((p = 42) == 42) && p.length != 0);
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 56, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_after() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
callMe(f()) { f(); }
|
||||
g(Object p) {
|
||||
p is String ? callMe(() { p.length; }) : 0;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
p = 42;
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 65, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_before() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
callMe(f()) { f(); }
|
||||
g(Object p) {
|
||||
p = 42;
|
||||
p is String ? callMe(() { p.length; }) : 0;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 75, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_accessedInClosure_hasAssignment() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
callMe(f()) { f(); }
|
||||
f(Object p) {
|
||||
if (p is String) {
|
||||
callMe(() {
|
||||
p.length;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
});
|
||||
}
|
||||
p = 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 80, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_extends_notMoreSpecific_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class V {}
|
||||
class A<T> {}
|
||||
class B<S> extends A<S> {
|
||||
@@ -414,16 +378,15 @@ class B<S> extends A<S> {
|
||||
f(A<V> p) {
|
||||
if (p is B) {
|
||||
p.b;
|
||||
// ^
|
||||
// [diag.undefinedGetter] The getter 'b' isn't defined for the type 'A<V>'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 97, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_extends_notMoreSpecific_notMoreSpecificTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class V {}
|
||||
class A<T> {}
|
||||
class B<S> extends A<S> {
|
||||
@@ -433,58 +396,56 @@ class B<S> extends A<S> {
|
||||
f(A<V> p) {
|
||||
if (p is B<int>) {
|
||||
p.b;
|
||||
// ^
|
||||
// [diag.undefinedGetter] The getter 'b' isn't defined for the type 'A<V>'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 102, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_hasAssignment_before() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object p) {
|
||||
if (p is String) {
|
||||
p = 0;
|
||||
p.length;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 52, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_hasAssignment_inClosure_anonymous_before() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object p) {
|
||||
() {p = 0;};
|
||||
if (p is String) {
|
||||
p.length;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 56, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_hasAssignment_inClosure_function_before() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
g(Object p) {
|
||||
f() {p = 0;};
|
||||
//^
|
||||
// [diag.unusedElement] The declaration 'f' isn't referenced.
|
||||
if (p is String) {
|
||||
p.length;
|
||||
// ^^^^^^
|
||||
// [diag.undefinedGetter] The getter 'length' isn't defined for the type 'Object'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 16, 1), error(diag.undefinedGetter, 57, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_implements_notMoreSpecific_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class V {}
|
||||
class A<T> {}
|
||||
class B<S> implements A<S> {
|
||||
@@ -494,16 +455,15 @@ class B<S> implements A<S> {
|
||||
f(A<V> p) {
|
||||
if (p is B) {
|
||||
p.b;
|
||||
// ^
|
||||
// [diag.undefinedGetter] The getter 'b' isn't defined for the type 'A<V>'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 100, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typePromotion_if_with_notMoreSpecific_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class V {}
|
||||
mixin A<T> {}
|
||||
class B<S> extends Object with A<S> {
|
||||
@@ -513,25 +473,24 @@ class B<S> extends Object with A<S> {
|
||||
f(A<V> p) {
|
||||
if (p is B) {
|
||||
p.b;
|
||||
// ^
|
||||
// [diag.undefinedGetter] The getter 'b' isn't defined for the type 'A<V>'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedGetter, 109, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_wrongNumberOfTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<E> {
|
||||
late E element;
|
||||
}
|
||||
g(A<NoSuchType> a) {
|
||||
// ^^^^^^^^^^
|
||||
// [diag.nonTypeAsTypeArgument] The name 'NoSuchType' isn't a type, so it can't be used as a type argument.
|
||||
a.element.anyGetterExistsInDynamic;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonTypeAsTypeArgument, 37, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 '../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(StaticWarningCodeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +21,7 @@ class StaticWarningCodeTest extends PubPackageResolutionTest {
|
||||
// they're testing.
|
||||
test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubtypeIsUsedInImplementation() async {
|
||||
// 15028
|
||||
await assertErrorsInCode(
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
'''
|
||||
class C {
|
||||
foo(int x) => x;
|
||||
@@ -28,8 +29,9 @@ class C {
|
||||
abstract class D {
|
||||
foo(x, [y]);
|
||||
}
|
||||
class E extends C implements D {}''',
|
||||
[error(diag.invalidImplementationOverride, 73, 1)],
|
||||
class E extends C implements D {}
|
||||
// ^
|
||||
// [diag.invalidImplementationOverride] 'C.foo' ('dynamic Function(int)') isn't a valid concrete implementation of 'D.foo' ('dynamic Function(dynamic, [dynamic])').''',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,6 @@ import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
import 'package:analyzer/src/dart/analysis/status.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer/src/test_utilities/lint_registration_mixin.dart';
|
||||
import 'package:analyzer/src/utilities/extensions/async.dart';
|
||||
import 'package:analyzer_testing/package_config_file_builder.dart';
|
||||
@@ -3069,13 +3068,12 @@ linter:
|
||||
- omit_local_variable_types
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library my.lib;
|
||||
part 'a.dart';
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 21, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'package:test/a.dart'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_getResolvedUnit_part_empty_lints() async {
|
||||
@@ -3087,13 +3085,12 @@ linter:
|
||||
|
||||
newFile('$testPackageLibPath/a.dart', '');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library my.lib;
|
||||
part 'a.dart';
|
||||
''',
|
||||
[error(diag.partOfNonPart, 21, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.partOfNonPart] The included part 'package:test/a.dart' must have a part-of directive.
|
||||
''');
|
||||
}
|
||||
|
||||
test_getResolvedUnit_part_hasPartOfName_notThisLibrary_lints() async {
|
||||
@@ -3107,13 +3104,12 @@ linter:
|
||||
part of other.lib;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library my.lib;
|
||||
part 'a.dart';
|
||||
''',
|
||||
[error(diag.partOfDifferentLibrary, 21, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.partOfDifferentLibrary] Expected this library to be part of 'my.lib', not 'other.lib'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_getResolvedUnit_part_hasPartOfUri_notThisLibrary_lints() async {
|
||||
@@ -3127,13 +3123,12 @@ linter:
|
||||
part of 'not_test.dart';
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library my.lib;
|
||||
part 'a.dart';
|
||||
''',
|
||||
[error(diag.partOfDifferentLibrary, 21, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.partOfDifferentLibrary] Expected this library to be part of 'package:test/test.dart', not 'package:test/a.dart'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_getResolvedUnit_part_library() async {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,14 +4,15 @@
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../resolution/context_collection_resolution.dart';
|
||||
import '../resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ClassElementTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -286,16 +287,14 @@ abstract class B implements A {}
|
||||
}
|
||||
|
||||
test_lookUpInheritedConcreteGetter_recursive() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
var B = findElement2.class_('B');
|
||||
assertElementNull(B._lookUpInheritedConcreteGetter('foo'));
|
||||
}
|
||||
@@ -577,16 +576,14 @@ abstract class B implements A {}
|
||||
}
|
||||
|
||||
test_lookUpInheritedConcreteMethod_recursive() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
var B = findElement2.class_('B');
|
||||
assertElementNull(B._lookUpInheritedConcreteMethod('foo'));
|
||||
}
|
||||
@@ -868,16 +865,14 @@ abstract class B implements A {}
|
||||
}
|
||||
|
||||
test_lookUpInheritedConcreteSetter_recursive() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
var B = findElement2.class_('B');
|
||||
assertElementNull(B._lookUpInheritedConcreteSetter('foo'));
|
||||
}
|
||||
@@ -1129,16 +1124,14 @@ abstract class B implements A {}
|
||||
}
|
||||
|
||||
test_lookUpInheritedMethod_recursive() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
var B = findElement2.class_('B');
|
||||
assertElementNull(B._lookUpInheritedMethod('foo'));
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
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 '../resolution/context_collection_resolution.dart';
|
||||
import '../resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ElementDisplayStringTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -326,12 +327,11 @@ final class A {}
|
||||
}
|
||||
|
||||
test_writeDirectiveUri() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'src/f.dart';
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'src/f.dart'.
|
||||
''');
|
||||
var import =
|
||||
findElement2.libraryFragment.libraryImports[0] as LibraryImportImpl;
|
||||
expect(import.displayString(), "import package:test/src/f.dart");
|
||||
@@ -427,14 +427,13 @@ nonexistentType a;
|
||||
}
|
||||
|
||||
test_writeLabelElement() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
f: 0;
|
||||
//^^
|
||||
// [diag.unusedLabel] The label 'f' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLabel, 13, 2)],
|
||||
);
|
||||
''');
|
||||
var element = findElement2.label('f');
|
||||
expect(element.displayString(), 'f');
|
||||
}
|
||||
@@ -448,64 +447,59 @@ library f;
|
||||
}
|
||||
|
||||
test_writeLibraryExport() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'src/f.dart';
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'src/f.dart'.
|
||||
''');
|
||||
var export =
|
||||
findElement2.libraryFragment.libraryExports.single as LibraryExportImpl;
|
||||
expect(export.displayString(), "export package:test/src/f.dart");
|
||||
}
|
||||
|
||||
test_writeLibraryImport() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'src/f.dart';
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'src/f.dart'.
|
||||
''');
|
||||
var import =
|
||||
findElement2.libraryFragment.libraryImports[0] as LibraryImportImpl;
|
||||
expect(import.displayString(), "import package:test/src/f.dart");
|
||||
}
|
||||
|
||||
test_writeLocalFunctionElement() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
void g() {}
|
||||
// ^
|
||||
// [diag.unusedElement] The declaration 'g' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 18, 1)],
|
||||
);
|
||||
''');
|
||||
var element = findElement2.localFunction('g');
|
||||
expect(element.displayString(), "void g()");
|
||||
}
|
||||
|
||||
test_writeLocalFunctionElement_formalParameters() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
void g(int a, bool b, {String? c}) {}
|
||||
// ^
|
||||
// [diag.unusedElement] The declaration 'g' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 18, 1)],
|
||||
);
|
||||
''');
|
||||
var element = findElement2.localFunction('g');
|
||||
expect(element.displayString(), "void g(int a, bool b, {String? c})");
|
||||
}
|
||||
|
||||
test_writeLocalFunctionElement_typeParameters() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
void g<T, S extends num>() {}
|
||||
// ^
|
||||
// [diag.unusedElement] The declaration 'g' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 18, 1)],
|
||||
);
|
||||
''');
|
||||
var element = findElement2.localFunction('g');
|
||||
expect(element.displayString(), "void g<T, S extends num>()");
|
||||
}
|
||||
@@ -549,36 +543,35 @@ mixin M<T, S extends num> {}
|
||||
}
|
||||
|
||||
test_writeNeverType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Never a;
|
||||
''',
|
||||
[error(diag.notInitializedNonNullableVariable, 6, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.notInitializedNonNullableVariable] The non-nullable variable 'a' must be initialized.
|
||||
''');
|
||||
var element = findElement2.topVar('a');
|
||||
expect(element.displayString(), "Never a");
|
||||
}
|
||||
|
||||
test_writePartInclude() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'src/f.dart';
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 5, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'package:test/src/f.dart'.
|
||||
''');
|
||||
var element =
|
||||
findElement2.libraryFragment.partIncludes.single as PartIncludeImpl;
|
||||
expect(element.displayString(), 'part package:test/src/f.dart');
|
||||
}
|
||||
|
||||
test_writePrefixElement_multipleImports() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'src/f.dart' as a;
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'src/f.dart'.
|
||||
import 'src/bar.dart' as a;
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 12), error(diag.uriDoesNotExist, 33, 14)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'src/bar.dart'.
|
||||
''');
|
||||
var prefix = findElement2.prefix('a');
|
||||
expect(
|
||||
prefix.displayString(),
|
||||
@@ -587,12 +580,11 @@ import 'src/bar.dart' as a;
|
||||
}
|
||||
|
||||
test_writePrefixElement_singleImport() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'src/f.dart' as a;
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'src/f.dart'.
|
||||
''');
|
||||
var prefix = findElement2.prefix('a');
|
||||
expect(prefix.displayString(), "import 'src/f.dart' as a;");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'package:analyzer/src/dart/analysis/file_state.dart';
|
||||
import 'package:analyzer/src/dart/micro/resolve_file.dart';
|
||||
import 'package:analyzer/src/dart/micro/utils.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:linter/src/diagnostic.dart' as diag;
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
@@ -846,13 +845,12 @@ analyzer:
|
||||
implicit-casts: false
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
num a = 0;
|
||||
int b = a;
|
||||
''',
|
||||
[error(diag.invalidAssignment, 19, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.invalidAssignment] A value of type 'num' can't be assigned to a variable of type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_analysisOptions_file_inPackage() async {
|
||||
@@ -862,13 +860,12 @@ analyzer:
|
||||
implicit-casts: false
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
num a = 0;
|
||||
int b = a;
|
||||
''',
|
||||
[error(diag.invalidAssignment, 19, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.invalidAssignment] A value of type 'num' can't be assigned to a variable of type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_analysisOptions_file_inThirdParty() async {
|
||||
@@ -926,15 +923,14 @@ linter:
|
||||
- omit_local_variable_types
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
int a = 0;
|
||||
//^^^
|
||||
// [diag.omitLocalVariableTypes] Unnecessary type annotation on a local variable.
|
||||
a;
|
||||
}
|
||||
''',
|
||||
[error(diag.omitLocalVariableTypes, 11, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_basic() async {
|
||||
@@ -1032,21 +1028,13 @@ p.dynamic f() {}
|
||||
}
|
||||
|
||||
Future<void> test_errors_hasNullSuffix() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
String f(Map<int, String> a) {
|
||||
return a[0];
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String?' can't be returned from the function 'f' because it has a return type of 'String'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.returnOfInvalidTypeFromFunction,
|
||||
40,
|
||||
4,
|
||||
messageContains: ["'String'", 'String?'],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_findReferences_class() async {
|
||||
@@ -2572,21 +2560,19 @@ void f(MyEnum myEnum) {
|
||||
}
|
||||
|
||||
test_unknown_uri() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo:bar';
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'foo:bar'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_warning() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:math';
|
||||
''',
|
||||
[error(diag.unusedImport, 7, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:math'.
|
||||
''');
|
||||
}
|
||||
|
||||
void _assertResolvedFiles(List<File> expected, {bool andClear = true}) {
|
||||
|
||||
@@ -4843,25 +4843,23 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_simpleIdentifier_staticMethod_superSetter_simple() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
set x(num _) {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
static void x() {}
|
||||
// ^
|
||||
// [diag.conflictingStaticAndInstance] Class 'B' can't define static member 'x' and have instance member 'A.x' with the same name.
|
||||
|
||||
void f() {
|
||||
x = 2;
|
||||
// ^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.conflictingStaticAndInstance, 65, 1),
|
||||
error(diag.assignmentToMethod, 90, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('x = 2');
|
||||
|
||||
@@ -4921,14 +4919,13 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_simpleIdentifier_synthetic_simple() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(int y) {
|
||||
= y;
|
||||
//^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingIdentifier, 18, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('= y');
|
||||
|
||||
@@ -5100,8 +5097,7 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topGetter_superSetter_simple() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
set x(num _) {}
|
||||
}
|
||||
@@ -5112,11 +5108,11 @@ class B extends A {
|
||||
|
||||
void f() {
|
||||
x = 2;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToFinal, 86, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('x = 2');
|
||||
|
||||
|
||||
@@ -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';
|
||||
@@ -717,16 +716,15 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_bangEq_extensionOverride_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {}
|
||||
|
||||
void f(int a) {
|
||||
E(a) != 0;
|
||||
// ^^
|
||||
// [diag.undefinedExtensionOperator] The operator '==' isn't defined for the extension 'E'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedExtensionOperator, 46, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('!= 0'), r'''
|
||||
BinaryExpression
|
||||
@@ -756,14 +754,13 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_bangEqEq() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(int a, int b) {
|
||||
a !== b;
|
||||
// ^
|
||||
// [diag.unsupportedOperator] The '!==' operator is not supported.
|
||||
}
|
||||
''',
|
||||
[error(diag.unsupportedOperator, 22, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('a !== b'), r'''
|
||||
BinaryExpression
|
||||
@@ -809,16 +806,15 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_eqEq_extensionOverride_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {}
|
||||
|
||||
void f(int a) {
|
||||
E(a) == 0;
|
||||
// ^^
|
||||
// [diag.undefinedExtensionOperator] The operator '==' isn't defined for the extension 'E'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedExtensionOperator, 46, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('== 0'), r'''
|
||||
BinaryExpression
|
||||
@@ -874,14 +870,13 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_eqEq_invalidType_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(A a) {
|
||||
// ^
|
||||
// [diag.undefinedClass] Undefined class 'A'.
|
||||
a == 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedClass, 7, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.binary('a == 0');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -902,14 +897,13 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_eqEqEq() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(int a, int b) {
|
||||
a === b;
|
||||
// ^
|
||||
// [diag.unsupportedOperator] The '===' operator is not supported.
|
||||
}
|
||||
''',
|
||||
[error(diag.unsupportedOperator, 22, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('a === b'), r'''
|
||||
BinaryExpression
|
||||
|
||||
+14
-25
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationExtendsClauseAlreadyPresentTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,42 +18,30 @@ main() {
|
||||
class AugmentationExtendsClauseAlreadyPresentTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_alreadyPresent() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationExtendsClauseAlreadyPresent,
|
||||
49,
|
||||
7,
|
||||
contextMessages: [message(testFile, 18, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.augmentationExtendsClauseAlreadyPresent][context 1] The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause and it isn't allowed to be repeated or changed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_alreadyPresent2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class B {}
|
||||
augment class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationExtendsClauseAlreadyPresent,
|
||||
68,
|
||||
7,
|
||||
contextMessages: [message(testFile, 18, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.augmentationExtendsClauseAlreadyPresent][context 1] The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause and it isn't allowed to be repeated or changed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_notPresent() async {
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationModifierExtraTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AugmentationModifierExtraTest extends PubPackageResolutionTest {
|
||||
test_class_abstract_abstractBase() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {}
|
||||
augment abstract base class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 37, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'base' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_abstractBase_abstractBase() async {
|
||||
@@ -33,97 +33,87 @@ augment abstract base class A {}
|
||||
}
|
||||
|
||||
test_class_base_abstractBase() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
augment abstract base class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 24, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'abstract' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_abstract() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment abstract class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'abstract' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_abstractBase() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment abstract base class A {}
|
||||
''',
|
||||
[
|
||||
error(diag.augmentationModifierExtra, 19, 8),
|
||||
error(diag.augmentationModifierExtra, 28, 4),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'abstract' modifier that the declaration doesn't have.
|
||||
// ^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'base' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_base() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment base class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'base' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_final() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment final class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'final' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_interface() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment interface class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'interface' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_mixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment mixin class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'mixin' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_nothing_abstract() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment class A {}
|
||||
augment abstract class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 38, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'abstract' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_nothing_sealed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment sealed class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'sealed' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_base_base() async {
|
||||
@@ -134,23 +124,21 @@ augment base mixin A {}
|
||||
}
|
||||
|
||||
test_mixin_nothing_base() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
augment base mixin A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 19, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'base' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_nothing_nothing_base() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
augment mixin A {}
|
||||
augment base mixin A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierExtra, 38, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.augmentationModifierExtra] The augmentation has the 'base' modifier that the declaration doesn't have.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,48 +2,43 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationModifierMissingTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AugmentationModifierMissingTest extends PubPackageResolutionTest {
|
||||
test_class_abstract_abstract_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {}
|
||||
augment abstract class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 48, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'abstract' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_abstract_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 20, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'abstract' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_abstractBase_abstract() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract base class A {}
|
||||
augment abstract class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 25, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'base' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_abstractBase_abstractBase() async {
|
||||
@@ -54,76 +49,60 @@ augment abstract base class A {}
|
||||
}
|
||||
|
||||
test_class_abstractBase_base() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract base class A {}
|
||||
augment base class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 25, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'abstract' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_abstractBase_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract base class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[
|
||||
error(diag.augmentationModifierMissing, 25, 7),
|
||||
error(diag.augmentationModifierMissing, 25, 7),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'abstract' modifier that the declaration has.
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'base' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_base_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 16, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'base' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_final_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 17, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'final' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_interface_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
interface class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 21, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'interface' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_mixin_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 17, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'mixin' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 18, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'sealed' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_base_base() async {
|
||||
@@ -134,23 +113,19 @@ augment base mixin A {}
|
||||
}
|
||||
|
||||
test_mixin_base_base_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin A {}
|
||||
augment base mixin A {}
|
||||
augment mixin A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 40, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'base' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_base_nothing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin A {}
|
||||
augment mixin A {}
|
||||
''',
|
||||
[error(diag.augmentationModifierMissing, 16, 7)],
|
||||
);
|
||||
// [diag.augmentationModifierMissing][column 1][length 7] The augmentation is missing the 'base' modifier that the declaration has.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ClassUsedAsMixinTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,16 +27,14 @@ class Bar with Comparable<int> {
|
||||
}
|
||||
|
||||
test_coreLib_dartCoreEnum() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A with Enum {}
|
||||
// ^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Enum' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
abstract class B = Object with Enum;
|
||||
''',
|
||||
[
|
||||
error(diag.classUsedAsMixin, 22, 4),
|
||||
error(diag.classUsedAsMixin, 61, 4),
|
||||
],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Enum' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_coreLib_dartCoreEnum_language219() async {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
@@ -126,15 +125,16 @@ class C {
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_constFactory_emptyBody_language305() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.5
|
||||
class C {
|
||||
const factory C();
|
||||
//^^^^^
|
||||
// [diag.constFactory] Only redirecting factory constructors can be declared to be 'const'.
|
||||
// ^
|
||||
// [diag.missingFunctionBody] A function body must be provided.
|
||||
}
|
||||
''',
|
||||
[error(diag.constFactory, 27, 5), error(diag.missingFunctionBody, 44, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_constFactory_expressionBody() async {
|
||||
@@ -772,17 +772,18 @@ enum E {
|
||||
}
|
||||
|
||||
test_enum_secondaryConstructor_constFactory_emptyBody_language305() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.5
|
||||
enum E {
|
||||
v;
|
||||
const E();
|
||||
const factory E.named();
|
||||
//^^^^^
|
||||
// [diag.constFactory] Only redirecting factory constructors can be declared to be 'const'.
|
||||
// ^
|
||||
// [diag.missingFunctionBody] A function body must be provided.
|
||||
}
|
||||
''',
|
||||
[error(diag.constFactory, 44, 5), error(diag.missingFunctionBody, 67, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_secondaryConstructor_constFactory_expressionBody() async {
|
||||
@@ -1119,15 +1120,16 @@ extension type const E(int it) {
|
||||
}
|
||||
|
||||
test_extensionType_secondaryConstructor_constFactory_emptyBody_language305() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.5
|
||||
extension type const E(int it) {
|
||||
const factory E.named();
|
||||
//^^^^^
|
||||
// [diag.constFactory] Only redirecting factory constructors can be declared to be 'const'.
|
||||
// ^
|
||||
// [diag.missingFunctionBody] A function body must be provided.
|
||||
}
|
||||
''',
|
||||
[error(diag.constFactory, 50, 5), error(diag.missingFunctionBody, 73, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_secondaryConstructor_constFactory_expressionBody() async {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/package_config_file_builder.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
@@ -1408,19 +1407,18 @@ class B = Object with A;
|
||||
test_namedParameterMissingName() async {
|
||||
// This is a regression test; previously this code would cause an analyzer
|
||||
// crash in DeprecatedMemberUseVerifier.
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
const C({this.});
|
||||
// ^^^^^
|
||||
// [diag.initializingFormalForNonExistentField] '' isn't a field in the enclosing class.
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
}
|
||||
var z = C(x: '');
|
||||
''',
|
||||
[
|
||||
error(diag.initializingFormalForNonExistentField, 21, 5),
|
||||
error(diag.missingIdentifier, 26, 1),
|
||||
error(diag.undefinedNamedParameter, 42, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.undefinedNamedParameter] The named parameter 'x' isn't defined.
|
||||
''');
|
||||
}
|
||||
|
||||
test_operator() async {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:analyzer_testing/package_config_file_builder.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -15,6 +16,7 @@ main() {
|
||||
defineReflectiveTests(ExperimentalInstantiateTest);
|
||||
defineReflectiveTests(ExperimentalMemberUseTest);
|
||||
defineReflectiveTests(ExperimentalMixinTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -779,16 +781,15 @@ class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:aaa/a.dart';
|
||||
|
||||
void f(A a) {
|
||||
a.foo;
|
||||
// ^^^
|
||||
// [diag.experimentalMemberUse] 'foo' is experimental and could be removed or changed at any time.
|
||||
}
|
||||
''',
|
||||
[error(diag.experimentalMemberUse, 48, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_field_implicitSetter() async {
|
||||
@@ -1377,16 +1378,15 @@ class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:aaa/a.dart';
|
||||
|
||||
void f() {
|
||||
A();
|
||||
//^
|
||||
// [diag.experimentalMemberUse] 'A' is experimental and could be removed or changed at any time.
|
||||
}
|
||||
''',
|
||||
[error(diag.experimentalMemberUse, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_instanceCreation_unnamedConstructor() async {
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(FieldInitializerFactoryConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,21 +39,19 @@ class A {
|
||||
}
|
||||
|
||||
test_class_fieldFormalParameter_functionTyped_language305() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
// TODO(srawlins): Only report one error. Theoretically change Fasta to
|
||||
// report "Field initializer in factory constructor" as a parse error.
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.5
|
||||
class A {
|
||||
int Function()? x;
|
||||
factory A(int this.x());
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.fieldInitializerFactoryConstructor] Initializing formal parameters can't be used in factory constructors.
|
||||
// ^
|
||||
// [diag.missingFunctionBody] A function body must be provided.
|
||||
}
|
||||
''',
|
||||
[
|
||||
// TODO(srawlins): Only report one error. Theoretically change Fasta to
|
||||
// report "Field initializer in factory constructor" as a parse error.
|
||||
error(diag.fieldInitializerFactoryConstructor, 58, 12),
|
||||
error(diag.missingFunctionBody, 71, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_fieldFormalParameter() async {
|
||||
|
||||
@@ -6,12 +6,14 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(InvalidAssignment_ImplicitCallReferenceTest);
|
||||
defineReflectiveTests(InvalidAssignmentTest);
|
||||
defineReflectiveTests(InvalidAssignmentWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -886,8 +888,7 @@ f(C c) {
|
||||
}
|
||||
|
||||
test_promotedTypeParameter_regress35306() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends D {}
|
||||
@@ -896,31 +897,31 @@ class D {}
|
||||
void f<X extends A, Y extends B>(X x) {
|
||||
if (x is Y) {
|
||||
A a = x;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
B b = x;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used.
|
||||
X x2 = x;
|
||||
// ^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x2' isn't used.
|
||||
Y y = x;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 127, 1),
|
||||
error(diag.unusedLocalVariable, 140, 1),
|
||||
error(diag.unusedLocalVariable, 153, 2),
|
||||
error(diag.unusedLocalVariable, 167, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_recordType_localVariable_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f() {
|
||||
(int, int) r = (a: 1, b: 2);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.invalidAssignment] A value of type '({int a, int b})' can't be assigned to a variable of type '(int, int)'.
|
||||
print(r);
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidAssignment, 28, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_recordType_parameter() async {
|
||||
|
||||
+46
-77
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(InvalidOverrideOfNonVirtualMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,8 +23,7 @@ class InvalidOverrideOfNonVirtualMemberTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_class_field() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -34,22 +34,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
int g = 0;
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.invalidOverrideOfNonVirtualMember,
|
||||
113,
|
||||
1,
|
||||
messageContains: ["member 'g'", "in 'C'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -59,15 +51,14 @@ class C {
|
||||
|
||||
class B extends C {
|
||||
int g = 0, h = 1;
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 101, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_overriddenByGetter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -78,22 +69,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
int get g => 0;
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.invalidOverrideOfNonVirtualMember,
|
||||
117,
|
||||
1,
|
||||
messageContains: ["member 'g'", "in 'C'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_overriddenBySetter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -104,15 +87,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
set g(int v) {}
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 113, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -123,15 +105,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
int get g => 0;
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 122, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_getter_overriddenByField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -142,10 +123,10 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
int g = 0;
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 118, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_getter() async {
|
||||
@@ -181,8 +162,7 @@ class B implements C {
|
||||
}
|
||||
|
||||
test_class_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -193,15 +173,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
void f() {}
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'f' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 115, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -212,15 +191,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
set g(int v) {}
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 118, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_setter_overriddenByField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -231,15 +209,14 @@ class C {
|
||||
class B extends C {
|
||||
@override
|
||||
int g = 0;
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'C' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 118, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
mixin M {
|
||||
@@ -250,22 +227,14 @@ mixin M {
|
||||
class B with M {
|
||||
@override
|
||||
void f() {}
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'f' is declared non-virtual in 'M' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.invalidOverrideOfNonVirtualMember,
|
||||
111,
|
||||
1,
|
||||
messageContains: ["member 'f'", "in 'M'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
mixin M {
|
||||
@@ -276,9 +245,9 @@ mixin M {
|
||||
class B with M {
|
||||
@override
|
||||
set g(int v) {}
|
||||
// ^
|
||||
// [diag.invalidOverrideOfNonVirtualMember] The member 'g' is declared non-virtual in 'M' and can't be overridden in subclasses.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidOverrideOfNonVirtualMember, 114, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,28 +2,30 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(InvalidUseOfNeverTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class InvalidUseOfNeverTest extends PubPackageResolutionTest {
|
||||
test_binaryExpression_eqEq() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
(throw '') == 1 + 2;
|
||||
//^^^^^^^^^^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 13, 10), error(diag.deadCode, 24, 8)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('=='), r'''
|
||||
BinaryExpression
|
||||
@@ -57,14 +59,15 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_binaryExpression_never_eqEq() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x == 1 + 2;
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 22, 8)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('x =='), r'''
|
||||
BinaryExpression
|
||||
@@ -93,14 +96,15 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_binaryExpression_never_plus() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x + (1 + 2);
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 22, 9)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('x +'), r'''
|
||||
BinaryExpression
|
||||
@@ -166,14 +170,13 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_binaryExpression_neverQ_plus() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x + (1 + 2);
|
||||
// ^
|
||||
// [diag.uncheckedOperatorInvocationOfNullableValue] The operator '+' can't be unconditionally invoked because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedOperatorInvocationOfNullableValue, 23, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('x +'), r'''
|
||||
BinaryExpression
|
||||
@@ -206,14 +209,15 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_binaryExpression_plus() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
(throw '') + (1 + 2);
|
||||
//^^^^^^^^^^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 13, 10), error(diag.deadCode, 24, 9)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.binary('+ ('), r'''
|
||||
BinaryExpression
|
||||
@@ -269,36 +273,37 @@ void f(bool c, Never x) {
|
||||
}
|
||||
|
||||
test_functionExpressionInvocation_never() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x();
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 21, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionExpressionInvocation_neverQ() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x();
|
||||
//^
|
||||
// [diag.uncheckedInvocationOfNullableValue] The function can't be unconditionally invoked because it can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedInvocationOfNullableValue, 21, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_indexExpression_never_read() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x[0];
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 22, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.index('x[0]'), r'''
|
||||
IndexExpression
|
||||
@@ -318,14 +323,15 @@ IndexExpression
|
||||
}
|
||||
|
||||
test_indexExpression_never_readWrite() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x[0] += 1 + 2;
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 22, 12)],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('[0] +=');
|
||||
assertResolvedNodeText(assignment, r'''
|
||||
@@ -367,14 +373,15 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_indexExpression_never_write() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x[0] = 1 + 2;
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 22, 11)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.assignment('x[0]'), r'''
|
||||
AssignmentExpression
|
||||
@@ -415,14 +422,13 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_indexExpression_neverQ_read() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x[0];
|
||||
// ^
|
||||
// [diag.uncheckedMethodInvocationOfNullableValue] The method '[]' can't be unconditionally invoked because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedMethodInvocationOfNullableValue, 22, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.index('x[0]'), r'''
|
||||
IndexExpression
|
||||
@@ -442,14 +448,13 @@ IndexExpression
|
||||
}
|
||||
|
||||
test_indexExpression_neverQ_readWrite() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x[0] += 1 + 2;
|
||||
// ^
|
||||
// [diag.uncheckedMethodInvocationOfNullableValue] The method '[]' can't be unconditionally invoked because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedMethodInvocationOfNullableValue, 22, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('[0] +=');
|
||||
assertResolvedNodeText(assignment, r'''
|
||||
@@ -491,14 +496,13 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_indexExpression_neverQ_write() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x[0] = 1 + 2;
|
||||
// ^
|
||||
// [diag.uncheckedMethodInvocationOfNullableValue] The method '[]' can't be unconditionally invoked because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedMethodInvocationOfNullableValue, 22, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.assignment('x[0]'), r'''
|
||||
AssignmentExpression
|
||||
@@ -547,14 +551,15 @@ void f(g, Never x) {
|
||||
}
|
||||
|
||||
test_methodInvocation_never() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.foo(1 + 2);
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 25, 8)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('.foo(1 + 2)');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -591,14 +596,15 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_never_toString() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.toString(1 + 2);
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1), error(diag.deadCode, 30, 8)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('.toString(1 + 2)');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -635,14 +641,13 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_neverQ_toString() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x.toString(1 + 2);
|
||||
// ^^^^^
|
||||
// [diag.extraPositionalArguments] Too many positional arguments: 0 expected, but 1 found.
|
||||
}
|
||||
''',
|
||||
[error(diag.extraPositionalArguments, 32, 5)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('.toString(1 + 2)');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -679,14 +684,15 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_toString() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
(throw '').toString();
|
||||
//^^^^^^^^^^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
// ^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 13, 10), error(diag.deadCode, 32, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('toString()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -714,14 +720,13 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_postfixExpression_never_plusPlus() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x++;
|
||||
//^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 20, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.postfix('x++'), r'''
|
||||
PostfixExpression
|
||||
@@ -740,14 +745,13 @@ PostfixExpression
|
||||
}
|
||||
|
||||
test_postfixExpression_neverQ_plusPlus() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x++;
|
||||
// ^^
|
||||
// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedMethodInvocationOfNullableValue, 22, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.postfix('x++'), r'''
|
||||
PostfixExpression
|
||||
@@ -767,14 +771,13 @@ PostfixExpression
|
||||
|
||||
test_prefixExpression_never_plusPlus() async {
|
||||
// Reports 'undefined operator'
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
++x;
|
||||
// ^
|
||||
// [diag.receiverOfTypeNever] The receiver is of type 'Never', and will never complete with a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.receiverOfTypeNever, 22, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.prefix('++x'), r'''
|
||||
PrefixExpression
|
||||
@@ -793,14 +796,13 @@ PrefixExpression
|
||||
}
|
||||
|
||||
test_prefixExpression_neverQ_plusPlus() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
++x;
|
||||
//^^
|
||||
// [diag.uncheckedMethodInvocationOfNullableValue] The method '+' can't be unconditionally invoked because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedMethodInvocationOfNullableValue, 21, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.prefix('++x'), r'''
|
||||
PrefixExpression
|
||||
@@ -819,14 +821,13 @@ PrefixExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_never_read() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.foo;
|
||||
// ^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 22, 4)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePrefixedIdentifier;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -846,14 +847,13 @@ PrefixedIdentifier
|
||||
}
|
||||
|
||||
test_propertyAccess_never_read_hashCode() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.hashCode;
|
||||
// ^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 22, 9)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePrefixedIdentifier;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -873,14 +873,13 @@ PrefixedIdentifier
|
||||
}
|
||||
|
||||
test_propertyAccess_never_readWrite() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.foo += 0;
|
||||
// ^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 29, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('foo += 0');
|
||||
assertResolvedNodeText(assignment, r'''
|
||||
@@ -912,14 +911,13 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_never_tearOff_toString() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.toString;
|
||||
// ^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 22, 9)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePrefixedIdentifier;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -939,14 +937,13 @@ PrefixedIdentifier
|
||||
}
|
||||
|
||||
test_propertyAccess_never_write() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never x) {
|
||||
x.foo = 0;
|
||||
// ^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 28, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
var assignment = findNode.assignment('foo = 0');
|
||||
assertResolvedNodeText(assignment, r'''
|
||||
@@ -978,14 +975,13 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_neverQ_read() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Never? x) {
|
||||
x.foo;
|
||||
// ^^^
|
||||
// [diag.uncheckedPropertyAccessOfNullableValue] The property 'foo' can't be unconditionally accessed because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedPropertyAccessOfNullableValue, 23, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePrefixedIdentifier;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -1053,14 +1049,13 @@ PrefixedIdentifier
|
||||
}
|
||||
|
||||
test_propertyAccess_toString() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
(throw '').toString;
|
||||
// ^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 24, 9)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -1084,14 +1079,13 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_throw_getter_hashCode() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
(throw '').hashCode;
|
||||
// ^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 24, 9)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
+6
-9
@@ -2,7 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
@@ -54,15 +53,13 @@ class B = A with M implements B;
|
||||
}
|
||||
|
||||
test_mixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A implements B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
mixin B implements A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 30, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+104
-352
@@ -7,50 +7,34 @@ import 'package:analyzer_testing/analysis_rule/analysis_rule.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SubtypeOfBaseIsNotBaseFinalOrSealedTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfBaseIsNotBaseFinalOrSealedTest extends PubPackageResolutionTest {
|
||||
test_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
22,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_multiple() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
base class B extends A {}
|
||||
class C extends A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
48,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_outside() async {
|
||||
@@ -58,21 +42,12 @@ class C extends A {}
|
||||
base class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_outside_viaLanguage219AndCore() async {
|
||||
@@ -85,39 +60,21 @@ abstract class A implements LinkedListEntry<Never> {}
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
abstract class B extends A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
32,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'LinkedListEntry' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'LinkedListEntry' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
22,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_outside() async {
|
||||
@@ -125,22 +82,14 @@ class B implements A {}
|
||||
base class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
this.error(diag.baseClassImplementedOutsideOfLibrary, 36, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
// ^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'A' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_outside_viaLanguage219AndCore() async {
|
||||
@@ -153,141 +102,65 @@ abstract class A implements LinkedListEntry<Never> {}
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
abstract class B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
32,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'LinkedListEntry' is 'base'.",
|
||||
),
|
||||
this.error(diag.baseClassImplementedOutsideOfLibrary, 45, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'LinkedListEntry' is 'base'.
|
||||
// ^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'LinkedListEntry' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B extends A {}
|
||||
class C extends B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
50,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_interface_implements_base() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'C' is a subtype of 'A', and 'A' is defined here.
|
||||
interface class B {}
|
||||
sealed class C extends B implements A {}
|
||||
class D extends C {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
84,
|
||||
1,
|
||||
text:
|
||||
"The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'C' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_interface_with_base() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin A {}
|
||||
// ^
|
||||
// [context 1] The type 'C' is a subtype of 'A', and 'A' is defined here.
|
||||
interface class B {}
|
||||
sealed class C extends B with A {}
|
||||
class D extends C {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
78,
|
||||
1,
|
||||
text:
|
||||
"The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'C' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_multiple() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'C' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B extends A {}
|
||||
sealed class C extends B {}
|
||||
class D extends C {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
78,
|
||||
1,
|
||||
text:
|
||||
"The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'C' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_outside() async {
|
||||
@@ -324,188 +197,85 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_class_sealed_extends_unordered() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C extends B {}
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
sealed class B extends A {}
|
||||
base class A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
6,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
60,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B implements A {}
|
||||
class C implements B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
53,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
mixin B {}
|
||||
class C = Object with B implements A;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
33,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_interface() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
mixin B {}
|
||||
interface class C = Object with B implements A;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
43,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_sealed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'AA' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class AA extends A {}
|
||||
mixin B {}
|
||||
class C = Object with B implements AA;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
62,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'AA' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_sealed_interface() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'AA' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class AA extends A {}
|
||||
mixin B {}
|
||||
interface class C = Object with B implements AA;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
72,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'AA' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_sealed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B with A {}
|
||||
class C extends B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
53,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
17,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_sealed_outside() async {
|
||||
@@ -542,21 +312,12 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_mixinClass_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin class A {}
|
||||
class B with A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
28,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_with_outside() async {
|
||||
@@ -564,20 +325,11 @@ class B with A {}
|
||||
base mixin class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B with A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfBaseIsNotBaseFinalOrSealed,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfBaseIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,112 +2,104 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SubtypeOfFfiClassInExtendsTest);
|
||||
defineReflectiveTests(SubtypeOfFfiClassInImplementsTest);
|
||||
defineReflectiveTests(SubtypeOfFfiClassInWithTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfFfiClassInExtendsTest extends PubPackageResolutionTest {
|
||||
test_Double() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Double {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 41, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Double' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Double_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
import 'dart:ffi';
|
||||
class C extends Double {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 49, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Double' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Finalizable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Finalizable {}
|
||||
''',
|
||||
[error(diag.noGenerativeConstructorsInSuperclass, 35, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.noGenerativeConstructorsInSuperclass] The class 'C' can't extend 'Finalizable' because 'Finalizable' only has factory constructors (no generative constructors), and 'C' has at least one generative constructor.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Float() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Float {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Float' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int16() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Int16 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Int16' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Int32 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Int32' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int64() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Int64 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Int64' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int8() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Int8 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Int8' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Pointer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Pointer {
|
||||
// ^^^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Pointer' can't be extended outside of its library because it's a final class.
|
||||
external factory C();
|
||||
}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_Struct() async {
|
||||
@@ -120,43 +112,39 @@ final class C extends Struct {
|
||||
}
|
||||
|
||||
test_Uint16() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Uint16 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Uint16' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Uint32 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Uint32' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint64() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Uint64 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Uint64' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint8() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Uint8 {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Uint8' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Union() async {
|
||||
@@ -169,47 +157,43 @@ final class C extends Union {
|
||||
}
|
||||
|
||||
test_Void() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Void {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 35, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'Void' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfFfiClassInImplementsTest extends PubPackageResolutionTest {
|
||||
test_Double() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Double {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Double' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Double_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
import 'dart:ffi';
|
||||
class C implements Double {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 52, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Double' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Double_prefixed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi' as ffi;
|
||||
class C implements ffi.Double {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 45, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Double' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Finalizable() async {
|
||||
@@ -220,299 +204,269 @@ class C implements Finalizable {}
|
||||
}
|
||||
|
||||
test_Float() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Float {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Float' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int16() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Int16 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Int16' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Int32 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Int32' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int64() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Int64 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Int64' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int8() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Int8 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Int8' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Pointer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Pointer {}
|
||||
''',
|
||||
[
|
||||
error(diag.finalClassImplementedOutsideOfLibrary, 38, 7),
|
||||
error(diag.nonAbstractClassInheritsAbstractMemberOne, 25, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'Pointer.cast'.
|
||||
// ^^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Pointer' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Struct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C implements Struct {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 44, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Struct' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint16() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Uint16 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Uint16' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Uint32 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Uint32' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint64() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Uint64 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Uint64' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint8() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Uint8 {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Uint8' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Union() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C implements Union {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 44, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Union' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Void() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C implements Void {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 38, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'Void' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfFfiClassInWithTest extends PubPackageResolutionTest {
|
||||
test_Double() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Double {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Double' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Double_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
import 'dart:ffi';
|
||||
class C with Double {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 46, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Double' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Double_prefixed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi' as ffi;
|
||||
class C with ffi.Double {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 39, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Double' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Float() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Float {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Float' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int16() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Int16 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Int16' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Int32 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Int32' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int64() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Int64 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Int64' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Int8() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Int8 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Int8' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Pointer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Pointer {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Pointer' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Struct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C with Struct {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 38, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Struct' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint16() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Uint16 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Uint16' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Uint32 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Uint32' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint64() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Uint64 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Uint64' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Uint8() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Uint8 {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Uint8' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Union() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C with Union {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 38, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Union' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Void() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
class C with Void {}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 32, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.classUsedAsMixin] The class 'Void' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+85
-253
@@ -3,14 +3,15 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/analysis_rule/analysis_rule.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SubtypeOfFinalIsNotBaseFinalOrSealedTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,21 +19,12 @@ main() {
|
||||
class SubtypeOfFinalIsNotBaseFinalOrSealedTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
@@ -49,7 +41,7 @@ final class A {}
|
||||
class B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
38,
|
||||
1,
|
||||
@@ -67,13 +59,12 @@ class B {}
|
||||
final class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'A' can't be extended outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_outside_viaLanguage219AndCore() async {
|
||||
@@ -89,42 +80,24 @@ class A implements MapEntry<int, int> {
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'MapEntry' is 'final'.
|
||||
int get key => 0;
|
||||
int get value => 1;
|
||||
}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'MapEntry' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed] The type 'B' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_outside() async {
|
||||
@@ -134,13 +107,12 @@ class B implements A {}
|
||||
final class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B implements A {}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'A' can't be implemented outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_outside_viaLanguage219AndCore() async {
|
||||
@@ -159,16 +131,15 @@ class A implements MapEntry<int, int> {
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
class B implements A {
|
||||
// ^
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'MapEntry' can't be implemented outside of its library because it's a final class.
|
||||
int get key => 0;
|
||||
int get value => 1;
|
||||
}
|
||||
''',
|
||||
[error(diag.finalClassImplementedOutsideOfLibrary, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_on_outside() async {
|
||||
@@ -178,72 +149,37 @@ class B implements A {
|
||||
final class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
mixin B on A {}
|
||||
''',
|
||||
[error(diag.finalClassUsedAsMixinConstraintOutsideOfLibrary, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.finalClassUsedAsMixinConstraintOutsideOfLibrary] The class 'A' can't be used as a mixin superclass constraint outside of its library because it's a final class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B extends A {}
|
||||
class C extends B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
51,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
12,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_multiple() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
// ^
|
||||
// [context 1] The type 'C' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B extends A {}
|
||||
sealed class C extends B {}
|
||||
class D extends C {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
79,
|
||||
1,
|
||||
text:
|
||||
"The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
12,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'C' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_outside() async {
|
||||
@@ -253,199 +189,95 @@ class D extends C {}
|
||||
final class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
sealed class B extends A {}
|
||||
// ^
|
||||
// [diag.finalClassExtendedOutsideOfLibrary] The class 'A' can't be extended outside of its library because it's a final class.
|
||||
class C extends B {}
|
||||
''',
|
||||
[error(diag.finalClassExtendedOutsideOfLibrary, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_extends_unordered() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C extends B {}
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
sealed class B extends A {}
|
||||
final class A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
6,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
61,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B implements A {}
|
||||
class C implements B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
54,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
12,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_sealed_with_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
final class B {}
|
||||
// ^
|
||||
// [context 1] The type 'C' is a subtype of 'B', and 'B' is defined here.
|
||||
sealed class C extends B with A {}
|
||||
class D extends C {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
69,
|
||||
1,
|
||||
text:
|
||||
"The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'B' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
23,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'C' is a subtype of 'B', and 'B' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'D' must be 'base', 'final' or 'sealed' because the supertype 'B' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
mixin B {}
|
||||
class C = Object with B implements A;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
34,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_interface() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
mixin B {}
|
||||
interface class C = Object with B implements A;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
44,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_sealed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
// ^
|
||||
// [context 1] The type 'AA' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class AA extends A {}
|
||||
mixin B {}
|
||||
class C = Object with B implements AA;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
63,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
12,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'AA' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_sealed_interface() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
// ^
|
||||
// [context 1] The type 'AA' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class AA extends A {}
|
||||
mixin B {}
|
||||
interface class C = Object with B implements AA;
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.subtypeOfFinalIsNotBaseFinalOrSealed,
|
||||
73,
|
||||
1,
|
||||
text:
|
||||
"The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
12,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'AA' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfFinalIsNotBaseFinalOrSealed][context 1] The type 'C' must be 'base', 'final' or 'sealed' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/package_config_file_builder.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SubtypeOfSealedClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,13 +35,11 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
class Bar extends Foo {}
|
||||
''',
|
||||
[error(diag.subtypeOfSealedClass, 31, 24)],
|
||||
);
|
||||
// [diag.subtypeOfSealedClass][column 1][length 24] The class 'Foo' shouldn't be extended, mixed in, or implemented because it's sealed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implementingSealedClass() async {
|
||||
@@ -55,13 +54,11 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
class Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.subtypeOfSealedClass, 31, 27)],
|
||||
);
|
||||
// [diag.subtypeOfSealedClass][column 1][length 27] The class 'Foo' shouldn't be extended, mixed in, or implemented because it's sealed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinApplicationOfSealedClass() async {
|
||||
@@ -77,14 +74,12 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
class Bar1 {}
|
||||
class Bar2 = Bar1 with Foo;
|
||||
''',
|
||||
[error(diag.subtypeOfSealedClass, 45, 27)],
|
||||
);
|
||||
// [diag.subtypeOfSealedClass][column 1][length 27] The class 'Foo' shouldn't be extended, mixed in, or implemented because it's sealed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinApplicationOfSealedMixin() async {
|
||||
@@ -99,14 +94,12 @@ import 'package:meta/meta.dart';
|
||||
@sealed mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
class Bar1 {}
|
||||
class Bar2 = Bar1 with Foo;
|
||||
''',
|
||||
[error(diag.subtypeOfSealedClass, 45, 27)],
|
||||
);
|
||||
// [diag.subtypeOfSealedClass][column 1][length 27] The class 'Foo' shouldn't be extended, mixed in, or implemented because it's sealed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixingInWithSealedMixin() async {
|
||||
@@ -121,13 +114,11 @@ import 'package:meta/meta.dart';
|
||||
@sealed mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
class Bar extends Object with Foo {}
|
||||
''',
|
||||
[error(diag.subtypeOfSealedClass, 31, 36)],
|
||||
);
|
||||
// [diag.subtypeOfSealedClass][column 1][length 36] The class 'Foo' shouldn't be extended, mixed in, or implemented because it's sealed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinImplementsSealedClass() async {
|
||||
@@ -142,13 +133,11 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
mixin Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.subtypeOfSealedClass, 31, 27)],
|
||||
);
|
||||
// [diag.subtypeOfSealedClass][column 1][length 27] The class 'Foo' shouldn't be extended, mixed in, or implemented because it's sealed.
|
||||
''');
|
||||
}
|
||||
|
||||
test_withinLibrary_language219() async {
|
||||
|
||||
@@ -2,53 +2,51 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SubtypeOfStructClassInExtendsTest);
|
||||
defineReflectiveTests(SubtypeOfStructClassInImplementsTest);
|
||||
defineReflectiveTests(SubtypeOfStructClassInWithTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfStructClassInExtendsTest extends PubPackageResolutionTest {
|
||||
test_extends_struct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class S extends Struct {
|
||||
external Pointer notEmpty;
|
||||
}
|
||||
final class C extends S {}
|
||||
''',
|
||||
[error(diag.subtypeOfStructClassInExtends, 103, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfStructClassInExtends] The class 'C' can't extend 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extends_union() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class S extends Union {
|
||||
external Pointer notEmpty;
|
||||
}
|
||||
final class C extends S {}
|
||||
''',
|
||||
[error(diag.subtypeOfStructClassInExtends, 102, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.subtypeOfStructClassInExtends] The class 'C' can't extend 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfStructClassInImplementsTest extends PubPackageResolutionTest {
|
||||
test_implements_abi_specific_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
@AbiSpecificIntegerMapping({
|
||||
Abi.androidArm: Uint32(),
|
||||
@@ -57,29 +55,25 @@ final class AbiSpecificInteger1 extends AbiSpecificInteger {
|
||||
const AbiSpecificInteger1();
|
||||
}
|
||||
final class AbiSpecificInteger4 implements AbiSpecificInteger1 {
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'AbiSpecificInteger' can't be implemented outside of its library because it's a base class.
|
||||
// [diag.subtypeOfStructClassInImplements] The class 'AbiSpecificInteger4' can't implement 'AbiSpecificInteger1' because 'AbiSpecificInteger1' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
const AbiSpecificInteger4();
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.baseClassImplementedOutsideOfLibrary, 216, 19),
|
||||
error(diag.subtypeOfStructClassInImplements, 216, 19),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_struct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class S extends Struct {}
|
||||
// ^
|
||||
// [diag.emptyStruct] The class 'S' can't be empty because it's a subclass of 'Struct'.
|
||||
final class C implements S {}
|
||||
''',
|
||||
[
|
||||
error(diag.emptyStruct, 31, 1),
|
||||
error(diag.baseClassImplementedOutsideOfLibrary, 76, 1),
|
||||
error(diag.subtypeOfStructClassInImplements, 76, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Struct' can't be implemented outside of its library because it's a base class.
|
||||
// [diag.subtypeOfStructClassInImplements] The class 'C' can't implement 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_struct_prefixed() async {
|
||||
@@ -87,55 +81,43 @@ final class C implements S {}
|
||||
import 'dart:ffi';
|
||||
final class S extends Struct {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as lib1;
|
||||
class C implements lib1.S {}
|
||||
''',
|
||||
[
|
||||
error(diag.baseClassImplementedOutsideOfLibrary, 47, 6),
|
||||
error(diag.finalClassImplementedOutsideOfLibrary, 47, 6),
|
||||
error(diag.subtypeOfStructClassInImplements, 47, 6),
|
||||
],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Struct' can't be implemented outside of its library because it's a base class.
|
||||
// [diag.finalClassImplementedOutsideOfLibrary] The class 'S' can't be implemented outside of its library because it's a final class.
|
||||
// [diag.subtypeOfStructClassInImplements] The class 'C' can't implement 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_union() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class S extends Union {}
|
||||
// ^
|
||||
// [diag.emptyStruct] The class 'S' can't be empty because it's a subclass of 'Union'.
|
||||
final class C implements S {}
|
||||
''',
|
||||
[
|
||||
error(diag.emptyStruct, 31, 1),
|
||||
error(diag.baseClassImplementedOutsideOfLibrary, 75, 1),
|
||||
error(diag.subtypeOfStructClassInImplements, 75, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Union' can't be implemented outside of its library because it's a base class.
|
||||
// [diag.subtypeOfStructClassInImplements] The class 'C' can't implement 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SubtypeOfStructClassInWithTest extends PubPackageResolutionTest {
|
||||
test_with_struct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class S extends Struct {}
|
||||
// ^
|
||||
// [diag.emptyStruct] The class 'S' can't be empty because it's a subclass of 'Struct'.
|
||||
final class C with S {}
|
||||
''',
|
||||
[
|
||||
error(diag.emptyStruct, 31, 1),
|
||||
error(diag.classUsedAsMixin, 70, 1),
|
||||
error(
|
||||
diag.subtypeOfStructClassInWith,
|
||||
70,
|
||||
1,
|
||||
messageContains: ["class 'C'", "mix in 'S'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.classUsedAsMixin] The class 'S' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
// [diag.subtypeOfStructClassInWith] The class 'C' can't mix in 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_with_struct_prefixed() async {
|
||||
@@ -143,36 +125,26 @@ final class C with S {}
|
||||
import 'dart:ffi';
|
||||
final class S extends Struct {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as lib1;
|
||||
|
||||
class C with lib1.S {}
|
||||
''',
|
||||
[
|
||||
error(diag.classUsedAsMixin, 42, 6),
|
||||
error(
|
||||
diag.subtypeOfStructClassInWith,
|
||||
42,
|
||||
6,
|
||||
messageContains: ["class 'C'", "mix in 'S'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.classUsedAsMixin] The class 'S' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
// [diag.subtypeOfStructClassInWith] The class 'C' can't mix in 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_with_union() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class S extends Union {}
|
||||
// ^
|
||||
// [diag.emptyStruct] The class 'S' can't be empty because it's a subclass of 'Union'.
|
||||
final class C with S {}
|
||||
''',
|
||||
[
|
||||
error(diag.emptyStruct, 31, 1),
|
||||
error(diag.classUsedAsMixin, 69, 1),
|
||||
error(diag.subtypeOfStructClassInWith, 69, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.classUsedAsMixin] The class 'S' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
// [diag.subtypeOfStructClassInWith] The class 'C' can't mix in 'S' because 'S' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+18
-21
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperFormalParameterTypeIsNotSubtypeOfAssociatedTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,18 +18,17 @@ main() {
|
||||
class SuperFormalParameterTypeIsNotSubtypeOfAssociatedTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_generic_requiredPositional_explicit_notSubtype() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
A(T a);
|
||||
}
|
||||
|
||||
class B extends A<int> {
|
||||
B(num super.a);
|
||||
// ^
|
||||
// [diag.superFormalParameterTypeIsNotSubtypeOfAssociated] The type 'num' of this parameter isn't a subtype of the type 'int' of the associated super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterTypeIsNotSubtypeOfAssociated, 65, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_generic_requiredPositional_explicit_same() async {
|
||||
@@ -56,18 +56,17 @@ class B extends A<num> {
|
||||
}
|
||||
|
||||
test_requiredNamed_explicit_notSubtype() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int a});
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
B({required num super.a});
|
||||
// ^
|
||||
// [diag.superFormalParameterTypeIsNotSubtypeOfAssociated] The type 'num' of this parameter isn't a subtype of the type 'int' of the associated super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterTypeIsNotSubtypeOfAssociated, 80, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_requiredNamed_explicit_same() async {
|
||||
@@ -107,34 +106,32 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_requiredPositional_explicit_notSubtype() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int a);
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
B(num super.a);
|
||||
// ^
|
||||
// [diag.superFormalParameterTypeIsNotSubtypeOfAssociated] The type 'num' of this parameter isn't a subtype of the type 'int' of the associated super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterTypeIsNotSubtypeOfAssociated, 59, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
/// No implicit coercions, like downcast from `dynamic`.
|
||||
test_requiredPositional_explicit_notSubtype_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int a);
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
B(dynamic super.a);
|
||||
// ^
|
||||
// [diag.superFormalParameterTypeIsNotSubtypeOfAssociated] The type 'dynamic' of this parameter isn't a subtype of the type 'int' of the associated super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterTypeIsNotSubtypeOfAssociated, 63, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_requiredPositional_explicit_same() async {
|
||||
|
||||
+18
-21
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperFormalParameterWithoutAssociatedNamedTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,54 +18,50 @@ main() {
|
||||
class SuperFormalParameterWithoutAssociatedNamedTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_explicit_optional() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
B({super.a}) : super();
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedNamed] No associated named super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedNamed, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_explicit_required() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
B({required super.a}) : super();
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedNamed] No associated named super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedNamed, 52, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_implicit_optional() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
B({super.a});
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedNamed] No associated named super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedNamed, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_implicit_required() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
B({required super.a});
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedNamed] No associated named super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedNamed, 52, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+50
-62
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperFormalParameterWithoutAssociatedPositionalTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,146 +18,133 @@ main() {
|
||||
class SuperFormalParameterWithoutAssociatedPositionalTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_primary_optionalPositional_01() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B([super.a]) extends A {}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 27, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_primary_requiredPositional_01() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B(super.a) extends A {}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 26, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondary_optionalPositional_01() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
B([super.a]);
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondary_requiredPositional_01() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
B(super.a);
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 42, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondary_requiredPositional_12() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int a);
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
B(super.a, super.b);
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 64, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_primary_requiredPositional_01() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(super.a) {
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
v(0);
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 13, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_secondary_requiredPositional_01() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(0);
|
||||
const E(super.x);
|
||||
// ^
|
||||
// [diag.superFormalParameterWithoutAssociatedPositional] No associated positional super constructor parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.superFormalParameterWithoutAssociatedPositional, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_recovery_hasSuperClass_noSuperConstructor_primary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int x);
|
||||
}
|
||||
|
||||
class B(super.a) extends A {
|
||||
this : super.named();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.undefinedConstructorInInitializer] The class 'A' doesn't have a constructor named 'named'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedConstructorInInitializer, 63, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_recovery_hasSuperClass_noSuperConstructor_secondary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int x);
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
B(super.x) : super.named();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.undefinedConstructorInInitializer] The class 'A' doesn't have a constructor named 'named'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedConstructorInInitializer, 60, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_recovery_noSuperClass_primary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B(super.a) extends A {
|
||||
// ^
|
||||
// [diag.extendsNonClass] Classes can only extend other classes.
|
||||
this : super.named();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.undefinedConstructorInInitializer] The class 'Object' doesn't have a constructor named 'named'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.extendsNonClass, 25, 1),
|
||||
error(diag.undefinedConstructorInInitializer, 38, 13),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_recovery_noSuperClass_secondary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.extendsNonClass] Classes can only extend other classes.
|
||||
B(super.x) : super.named();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.undefinedConstructorInInitializer] The class 'Object' doesn't have a constructor named 'named'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.extendsNonClass, 16, 1),
|
||||
error(diag.undefinedConstructorInInitializer, 35, 13),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,68 +2,64 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperInEnumConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SuperInEnumConstructorTest extends PubPackageResolutionTest {
|
||||
test_primary_one() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E() {
|
||||
v;
|
||||
this : super();
|
||||
// ^^^^^
|
||||
// [diag.superInEnumConstructor] The enum constructor can't have a 'super' initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInEnumConstructor, 25, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_hasRedirect() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E.named();
|
||||
const E() : this.named(), super();
|
||||
// ^^^^^
|
||||
// [diag.superInEnumConstructor] The enum constructor can't have a 'super' initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInEnumConstructor, 61, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_one() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E() : super();
|
||||
// ^^^^^
|
||||
// [diag.superInEnumConstructor] The enum constructor can't have a 'super' initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInEnumConstructor, 28, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_two() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E() : super(), super();
|
||||
// ^^^^^
|
||||
// [diag.superInEnumConstructor] The enum constructor can't have a 'super' initializer.
|
||||
// ^^^^^
|
||||
// [diag.superInEnumConstructor] The enum constructor can't have a 'super' initializer.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.superInEnumConstructor, 28, 5),
|
||||
error(diag.superInEnumConstructor, 37, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,46 +2,46 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperInExtensionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SuperInExtensionTest extends PubPackageResolutionTest {
|
||||
test_binaryOperator_inMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension E on int {
|
||||
int plusOne() => super + 1;
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtension, 40, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_binaryOperator_withGenericExtendedType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension <T> on T {
|
||||
f() {
|
||||
//^
|
||||
// [diag.unusedElement] The declaration 'f' isn't referenced.
|
||||
super + 1;
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 23, 1), error(diag.superInExtension, 33, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_getter_inSetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
int get value => 0;
|
||||
set value(int newValue) {}
|
||||
@@ -49,76 +49,70 @@ class C {
|
||||
extension E on C {
|
||||
set sign(int sign) {
|
||||
value = super.value * sign;
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtension, 117, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_indexOperator_inMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
int operator[](int i) => 0;
|
||||
}
|
||||
extension E on C {
|
||||
int at(int i) => super[i];
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtension, 80, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_inGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension E on int {
|
||||
String get displayText => super.toString();
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtension, 49, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_methodInvocation_field_instance_late() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension E on int {
|
||||
late final v = super.foo();
|
||||
// ^
|
||||
// [diag.extensionDeclaresInstanceField] Extensions can't declare instance fields.
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.extensionDeclaresInstanceField, 34, 1),
|
||||
error(diag.superInExtension, 38, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_methodInvocation_method_instance() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension E on int {
|
||||
void foo() {
|
||||
super.foo();
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtension, 40, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixOperator_inGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
C operator-() => this;
|
||||
}
|
||||
extension E on C {
|
||||
C get negated => -super;
|
||||
// ^^^^^
|
||||
// [diag.superInExtension] The 'super' keyword can't be used in an extension because an extension doesn't have a superclass.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtension, 76, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +2,30 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperInExtensionTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SuperInExtensionTypeTest extends PubPackageResolutionTest {
|
||||
test_binaryOperator() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension type A(int it) {
|
||||
void f() {
|
||||
super + 0;
|
||||
// ^^^^^
|
||||
// [diag.superInExtensionType] The 'super' keyword can't be used in an extension type because an extension type doesn't have a superclass.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtensionType, 44, 5)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleBinaryExpression;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -45,16 +45,15 @@ BinaryExpression
|
||||
}
|
||||
|
||||
test_methodInvocation() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension type A(int it) {
|
||||
void f() {
|
||||
super.foo();
|
||||
// ^^^^^
|
||||
// [diag.superInExtensionType] The 'super' keyword can't be used in an extension type because an extension type doesn't have a superclass.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtensionType, 44, 5)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleMethodInvocation;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -76,16 +75,15 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_propertyAccess() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension type A(int it) {
|
||||
void f() {
|
||||
super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInExtensionType] The 'super' keyword can't be used in an extension type because an extension type doesn't have a superclass.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInExtensionType, 44, 5)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -2,41 +2,40 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperInInvalidContextTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SuperInInvalidContextTest extends PubPackageResolutionTest {
|
||||
test_binaryExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = super + 0;
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 8, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_instance() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 63, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_instance_late() async {
|
||||
@@ -52,53 +51,49 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_class_field_static() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
static var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 70, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_static_late() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
static late var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 75, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructorInitializer_field() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() {}
|
||||
}
|
||||
class B extends A {
|
||||
var f;
|
||||
B() : f = super.m();
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 62, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructorInitializer_super() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class S {
|
||||
final int f;
|
||||
S(this.f);
|
||||
@@ -106,15 +101,14 @@ class S {
|
||||
|
||||
class C extends S {
|
||||
C() : super(super.f);
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 75, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructorInitializer_this() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class S {
|
||||
final int f;
|
||||
S(this.f);
|
||||
@@ -122,82 +116,77 @@ class S {
|
||||
|
||||
class C extends S {
|
||||
C() : this.other(super.f);
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
C.other(int a) : super(a);
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 80, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factoryConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() {}
|
||||
}
|
||||
class B extends A {
|
||||
factory B() {
|
||||
super.m();
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
return B._();
|
||||
}
|
||||
B._();
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 61, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_instanceVariableInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
var a;
|
||||
}
|
||||
class B extends A {
|
||||
var b = super.a;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 50, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_methodInvocation_extension_field_static() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension E on int {
|
||||
static final v = super.foo();
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 40, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_methodInvocation_extension_method_static() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension E on int {
|
||||
static void foo() {
|
||||
super.foo();
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 47, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_field_instance() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
mixin M on A {
|
||||
var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 58, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_field_instance_late() async {
|
||||
@@ -213,77 +202,72 @@ mixin M on A {
|
||||
}
|
||||
|
||||
test_mixin_field_static() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
mixin M on A {
|
||||
static var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 65, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_field_static_late() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
mixin M on A {
|
||||
static late var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 70, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_extension_field_static() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
extension E on int {
|
||||
static var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 71, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_extension_field_static_late() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
extension E on int {
|
||||
static late var f = super.foo;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 76, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_staticMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static m() {}
|
||||
}
|
||||
class B extends A {
|
||||
static n() { return super.m(); }
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 70, 5)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('super.m()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -305,17 +289,16 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_staticVariableInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int a = 0;
|
||||
}
|
||||
class B extends A {
|
||||
static int b = super.a;
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 69, 5)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -333,44 +316,40 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_topLevelFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
super.f();
|
||||
//^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 8, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariableInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = super.y;
|
||||
''',
|
||||
[error(diag.superInInvalidContext, 8, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.superInInvalidContext] Invalid context for 'super' invocation.
|
||||
''');
|
||||
}
|
||||
|
||||
test_valid() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() {}
|
||||
}
|
||||
class B extends A {
|
||||
B() {
|
||||
var v = super.m();
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
}
|
||||
n() {
|
||||
var v = super.m();
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 57, 1),
|
||||
error(diag.unusedLocalVariable, 92, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,64 +2,61 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperInRedirectingConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SuperInRedirectingConstructorTest extends PubPackageResolutionTest {
|
||||
test_class_primary_redirectBeforeSuper() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A() {
|
||||
A.named() : this();
|
||||
this : this.named(), super();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 43, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_primary_superBeforeRedirect() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A() {
|
||||
A.named() : this();
|
||||
this : super(), this.named();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 52, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_redirectionSuper() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() : this.name(), super();
|
||||
// ^^^^^^^
|
||||
// [diag.superInRedirectingConstructor] The redirecting constructor can't have a 'super' initializer.
|
||||
A.name() {}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInRedirectingConstructor, 31, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_superRedirection() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() : super(), this.name();
|
||||
// ^^^^^^^
|
||||
// [diag.superInRedirectingConstructor] The redirecting constructor can't have a 'super' initializer.
|
||||
A.name() {}
|
||||
}
|
||||
''',
|
||||
[error(diag.superInRedirectingConstructor, 18, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,40 +2,39 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SuperInvocationNotLastTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SuperInvocationNotLastTest extends PubPackageResolutionTest {
|
||||
test_primary_superBeforeAssert() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
this : super(), assert(x > 0);
|
||||
// ^^^^^
|
||||
// [diag.superInvocationNotLast] The superconstructor call must be last in an initializer list.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInvocationNotLast, 26, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primary_superBeforeField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A() {
|
||||
int x;
|
||||
this : super(), x = 0;
|
||||
// ^^^^^
|
||||
// [diag.superInvocationNotLast] The superconstructor call must be last in an initializer list.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInvocationNotLast, 30, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primary_superIsLast() async {
|
||||
@@ -48,26 +47,24 @@ class A() {
|
||||
}
|
||||
|
||||
test_typeName_superBeforeAssert() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? x) : super(), assert(x != null);
|
||||
// ^^^^^
|
||||
// [diag.superInvocationNotLast] The superconstructor call must be last in an initializer list.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInvocationNotLast, 24, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_superBeforeField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
final int x;
|
||||
A() : super(), x = 1;
|
||||
// ^^^^^
|
||||
// [diag.superInvocationNotLast] The superconstructor call must be last in an initializer list.
|
||||
}
|
||||
''',
|
||||
[error(diag.superInvocationNotLast, 33, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_superIsLast() async {
|
||||
|
||||
@@ -6,77 +6,70 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(TodoTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TodoTest extends PubPackageResolutionTest {
|
||||
test_eof() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {}
|
||||
// TODO: Implement something else
|
||||
''',
|
||||
[error(diag.todo, 13, 30, text: 'TODO: Implement something else')],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.todo] TODO: Implement something else
|
||||
''');
|
||||
}
|
||||
|
||||
test_fixme() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
// FIXME: Implement
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.fixme] FIXME: Implement
|
||||
}
|
||||
''',
|
||||
[error(diag.fixme, 14, 16, text: 'FIXME: Implement')],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hack() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
// HACK: This is a hack
|
||||
// ^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.hack] HACK: This is a hack
|
||||
}
|
||||
''',
|
||||
[error(diag.hack, 14, 20, text: 'HACK: This is a hack')],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_todo_multiLineComment() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
/* TODO: Implement */
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.todo] TODO: Implement
|
||||
/* TODO: Implement*/
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.todo] TODO: Implement
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.todo, 14, 15, text: 'TODO: Implement'),
|
||||
error(diag.todo, 38, 15, text: 'TODO: Implement'),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_todo_multiLineComment2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
/*
|
||||
TODO: Implement1
|
||||
// [diag.todo][column 1][length 16] TODO: Implement1
|
||||
TODO: Implement2
|
||||
// [diag.todo][column 1][length 16] TODO: Implement2
|
||||
*/
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.todo, 12, 16, text: 'TODO: Implement1'),
|
||||
error(diag.todo, 29, 16, text: 'TODO: Implement2'),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_todo_multiLineCommentWrapped() async {
|
||||
@@ -188,14 +181,13 @@ main() {
|
||||
}
|
||||
|
||||
test_todo_singleLineComment() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
// TODO: Implement
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.todo] TODO: Implement
|
||||
}
|
||||
''',
|
||||
[error(diag.todo, 14, 15, text: 'TODO: Implement')],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_todo_singleLineCommentDoubleCommented() async {
|
||||
@@ -230,14 +222,13 @@ main() {
|
||||
}
|
||||
|
||||
test_todo_singleLineCommentFollowedByDartdoc() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// TODO: Implement something
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.todo] TODO: Implement something
|
||||
/// This is the function documentation
|
||||
void f() {}
|
||||
''',
|
||||
[error(diag.todo, 3, 25, text: 'TODO: Implement something')],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_todo_singleLineCommentLessIndentedContinuation() async {
|
||||
@@ -349,13 +340,12 @@ main() {
|
||||
}
|
||||
|
||||
test_undone() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
// UNDONE: This was undone
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.undone] UNDONE: This was undone
|
||||
}
|
||||
''',
|
||||
[error(diag.undone, 14, 23, text: 'UNDONE: This was undone')],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(UnawaitedReturnInTryBlockTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,17 +34,16 @@ Future<int> foo(dynamic v) async {
|
||||
}
|
||||
|
||||
Future<void> test_dynamic_returnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
foo() async {
|
||||
try {
|
||||
return Future.value(42);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return Future.value(42);
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 26, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_finallyBlock() async {
|
||||
@@ -58,43 +58,42 @@ Future<int> foo() async {
|
||||
}
|
||||
|
||||
Future<void> test_futureOr() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'dart:async';
|
||||
|
||||
Future<int> foo(FutureOr<int> v) async {
|
||||
try {
|
||||
return v;
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return v;
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 75, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_futureOr_returnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'dart:async';
|
||||
|
||||
FutureOr<int> foo() async {
|
||||
try {
|
||||
return Future.value(42);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return Future.value(42);
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 62, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_futureSubtype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int> foo() async {
|
||||
try {
|
||||
return MyFuture();
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return MyFuture();
|
||||
}
|
||||
@@ -103,24 +102,21 @@ class MyFuture implements Future<int> {
|
||||
@override
|
||||
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 38, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_insideBlock() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<void> foo() async {
|
||||
try {
|
||||
{
|
||||
return Future<Null>.value(null);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 47, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_insideClosure() async {
|
||||
@@ -136,97 +132,90 @@ void foo() {
|
||||
}
|
||||
|
||||
Future<void> test_insideClosure_functionExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void foo() {
|
||||
try {
|
||||
var x = () async => return Future.value(null);
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
// ^^^^^^
|
||||
// [diag.unexpectedToken] Unexpected text 'return'.
|
||||
} catch (_) {}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 29, 1),
|
||||
error(diag.unexpectedToken, 45, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_invalidType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
foo() async {
|
||||
return unknown;
|
||||
// ^^^^^^^
|
||||
// [diag.undefinedIdentifier] Undefined name 'unknown'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedIdentifier, 23, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_localFunction() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f() {
|
||||
Future<int> foo() async {
|
||||
try {
|
||||
return Future.value(0);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return 0;
|
||||
}
|
||||
foo();
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 55, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_localFunctionExpression_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f() {
|
||||
var foo = () async {
|
||||
try {
|
||||
return Future.value(0);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return 0;
|
||||
};
|
||||
foo();
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 50, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
Future<int> foo() async {
|
||||
try {
|
||||
return Future.value(0);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 54, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_nestedTry() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int> foo() async {
|
||||
try {
|
||||
try {
|
||||
} catch (_) {
|
||||
return Future.value(42);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
}
|
||||
} catch (_) {}
|
||||
return -1;
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 68, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_nonFuture() async {
|
||||
@@ -252,33 +241,31 @@ Future<int> foo() {
|
||||
}
|
||||
|
||||
Future<void> test_stream() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'dart:async';
|
||||
|
||||
Stream<int> foo() async* {
|
||||
try {
|
||||
yield 42;
|
||||
return Future.value(42);
|
||||
// ^^^^^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
} catch (_) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.returnInGenerator, 75, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_typeParameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int> foo<T extends Future<int>>(T v) async {
|
||||
try {
|
||||
return v;
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
} catch (_) {}
|
||||
return v;
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 64, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_withinTryCatch() async {
|
||||
@@ -293,40 +280,37 @@ Future<int> foo() async {
|
||||
}
|
||||
|
||||
Future<void> test_withinTryCatch_withinTryBlock() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int> foo() async {
|
||||
try {
|
||||
try {} catch (_) {
|
||||
return Future.value(42);
|
||||
// ^^^^^^
|
||||
// [diag.unawaitedReturnInTryBlock] Returning a 'Future' without 'await' inside a try block.
|
||||
}
|
||||
} catch (_) {}
|
||||
return -1;
|
||||
}
|
||||
''',
|
||||
[error(diag.unawaitedReturnInTryBlock, 63, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_wrongType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int> foo() async {
|
||||
return '';
|
||||
// ^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'foo' because it has a return type of 'Future<int>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 35, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_wrongType2() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
Future<int>? foo() async {
|
||||
return Future<Null>.value(null);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Future<Null>' can't be returned from the function 'foo' because it has a return type of 'Future<int>?'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 36, 24)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
@@ -1058,17 +1057,16 @@ m() {
|
||||
}
|
||||
|
||||
test_member_nullable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
int? x;
|
||||
x.isEven;
|
||||
// ^^^^^^
|
||||
// [diag.uncheckedPropertyAccessOfNullableValue] The property 'isEven' can't be unconditionally accessed because the receiver can be 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.uncheckedPropertyAccessOfNullableValue, 20, 6)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('isEven');
|
||||
var node = findNode.simple('isEven;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: isEven
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/utilities/utilities.dart';
|
||||
import 'package:linter/src/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../src/dart/resolution/context_collection_resolution.dart';
|
||||
import '../../src/dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ErrorSuppressionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,48 +32,46 @@ class ErrorSuppressionTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_codeMismatch() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore: $ignoredCode
|
||||
int x = '';
|
||||
// ^^
|
||||
// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type 'int'.
|
||||
int _y = 0; //INVALID_ASSIGNMENT
|
||||
''',
|
||||
[error(diag.invalidAssignment, 34, 2), error(diag.unusedElement, 42, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.unusedElement] The declaration '_y' isn't referenced.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreFirstOfMultiple() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore: unnecessary_cast
|
||||
int x = (0 as int);
|
||||
// ... but no ignore here ...
|
||||
var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 90, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreFirstOfMultipleWithTrailingComment() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int x = (0 as int); // ignore: unnecessary_cast
|
||||
// ... but no ignore here ...
|
||||
var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 90, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreForFile() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int x = (0 as int); //UNNECESSARY_CAST
|
||||
var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'.
|
||||
// ignore_for_file: unnecessary_cast
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 51, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreForFileWithMuchWhitespace() async {
|
||||
@@ -107,14 +106,13 @@ void f() {
|
||||
}
|
||||
|
||||
test_ignoreForFileWithTypeMismatchLintVsWarning() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore_for_file: type=lint
|
||||
int a = 0;
|
||||
int _x = 1;
|
||||
''',
|
||||
[error(diag.unusedElement, 45, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.unusedElement] The declaration '_x' isn't referenced.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreOnlyDiagnosticWithTrailingComment() async {
|
||||
@@ -124,26 +122,24 @@ int x = (0 as int); // ignore: unnecessary_cast
|
||||
}
|
||||
|
||||
test_ignoreSecondDiagnostic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//UNNECESSARY_CAST
|
||||
int x = (0 as int);
|
||||
// ^^^^^^^^
|
||||
// [diag.unnecessaryCast] Unnecessary cast.
|
||||
// ignore: unused_element
|
||||
String _foo = ''; //UNUSED_ELEMENT
|
||||
''',
|
||||
[error(diag.unnecessaryCast, 28, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreSecondDiagnosticWithTrailingComment() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//UNNECESSARY_CAST
|
||||
int x = (0 as int);
|
||||
// ^^^^^^^^
|
||||
// [diag.unnecessaryCast] Unnecessary cast.
|
||||
String _foo = ''; // ignore: $ignoredCode
|
||||
''',
|
||||
[error(diag.unnecessaryCast, 28, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreTypeMatches() async {
|
||||
@@ -154,23 +150,21 @@ void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
|
||||
}
|
||||
|
||||
test_ignoreTypeMismatchLintVsWarning() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore: type=lint
|
||||
int _x = 1;
|
||||
''',
|
||||
[error(diag.unusedElement, 25, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.unusedElement] The declaration '_x' isn't referenced.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreTypeWithBadType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore: type=wrong
|
||||
void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
|
||||
''',
|
||||
[error(diag.avoidTypesAsParameterNamesFormalParameter, 34, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.avoidTypesAsParameterNamesFormalParameter] The parameter name 'int' matches a visible type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ignoreUniqueName() async {
|
||||
@@ -193,41 +187,36 @@ int x = (0 as int); // ignore: UNNECESSARY_CAST
|
||||
}
|
||||
|
||||
test_invalidCode() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore: right_format_wrong_code
|
||||
int x = '';
|
||||
// ^^
|
||||
// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type 'int'.
|
||||
var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
''',
|
||||
[
|
||||
error(diag.invalidAssignment, 43, 2),
|
||||
error(diag.argumentTypeNotAssignable, 59, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_missingCodes() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int x = 3;
|
||||
// ignore:
|
||||
String y = x + ''; //INVALID_ASSIGNMENT, ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
''',
|
||||
[
|
||||
error(diag.invalidAssignment, 33, 6),
|
||||
error(diag.argumentTypeNotAssignable, 37, 2),
|
||||
],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.invalidAssignment] A value of type 'num' can't be assigned to a variable of type 'String'.
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_missingMetadataSuffix() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// ignore invalid_assignment
|
||||
String y = 3; //INVALID_ASSIGNMENT
|
||||
''',
|
||||
[error(diag.invalidAssignment, 40, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.invalidAssignment] A value of type 'int' can't be assigned to a variable of type 'String'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_multipleCodesInIgnore() async {
|
||||
@@ -254,37 +243,33 @@ int _y = x as int; // ignore: unnecessary_cast, $ignoredCode
|
||||
}
|
||||
|
||||
test_multipleCommentsPreceding() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int x = (0 as int); //This is the first comment...
|
||||
// ^^^^^^^^
|
||||
// [diag.unnecessaryCast] Unnecessary cast.
|
||||
// ignore: $ignoredCode
|
||||
String _foo = ''; //UNUSED_ELEMENT
|
||||
''',
|
||||
[error(diag.unnecessaryCast, 9, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noIgnores() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int x = ''; //INVALID_ASSIGNMENT
|
||||
// ^^
|
||||
// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type 'int'.
|
||||
var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
''',
|
||||
[
|
||||
error(diag.invalidAssignment, 8, 2),
|
||||
error(diag.argumentTypeNotAssignable, 45, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_trailingCommentDoesNotCountAsAbove() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int x = (0 as int); // ignore: unnecessary_cast
|
||||
int y = (0 as int);
|
||||
''',
|
||||
[error(diag.unnecessaryCast, 57, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.unnecessaryCast] Unnecessary cast.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefinedFunctionWithinFlutterCanBeIgnored() async {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
@@ -93,13 +92,14 @@ var t = b
|
||||
}
|
||||
|
||||
test_initializer_dependencyCycle() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var a = b;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'a' can't be inferred because it depends on itself through the cycle: a, b.
|
||||
var b = a;
|
||||
''',
|
||||
[error(diag.topLevelCycle, 4, 1), error(diag.topLevelCycle, 15, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'b' can't be inferred because it depends on itself through the cycle: a, b.
|
||||
''');
|
||||
}
|
||||
|
||||
test_initializer_equality() async {
|
||||
@@ -297,38 +297,28 @@ var t = {
|
||||
}
|
||||
|
||||
test_override_conflictFieldType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
int aaa = 0;
|
||||
// ^^^
|
||||
// [context 1] The member being overridden.
|
||||
}
|
||||
abstract class B {
|
||||
String aaa = '0';
|
||||
// ^^^
|
||||
// [context 2] The member being overridden.
|
||||
}
|
||||
class C implements A, B {
|
||||
var aaa;
|
||||
// ^^^
|
||||
// [diag.invalidOverride][context 1] 'C.aaa' ('dynamic Function()') isn't a valid override of 'A.aaa' ('int Function()').
|
||||
// [diag.invalidOverride][context 2] 'C.aaa' ('dynamic Function()') isn't a valid override of 'B.aaa' ('String Function()').
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.invalidOverride,
|
||||
109,
|
||||
3,
|
||||
contextMessages: [message(testFile, 64, 3)],
|
||||
),
|
||||
error(
|
||||
diag.invalidOverride,
|
||||
109,
|
||||
3,
|
||||
contextMessages: [message(testFile, 25, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_override_conflictParameterType_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
void mmm(int a);
|
||||
}
|
||||
@@ -337,10 +327,10 @@ abstract class B {
|
||||
}
|
||||
class C implements A, B {
|
||||
void mmm(a) {}
|
||||
// ^^^
|
||||
// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.mmm (void Function(int)), B.mmm (void Function(String)).
|
||||
}
|
||||
''',
|
||||
[error(diag.noCombinedSuperSignature, 116, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> _assertErrorOnlyLeft(List<String> operators) async {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/element/type.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer/src/test_utilities/function_ast_visitor.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
@@ -167,8 +166,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_compoundAssignment_simpleIdentifier_topLevel() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
@@ -181,10 +179,10 @@ void set topLevel(A value) {}
|
||||
|
||||
main() {
|
||||
var /*@type=B*/ v = topLevel += 1;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 152, 1)],
|
||||
);
|
||||
''');
|
||||
_assertTypeAnnotations();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,6 @@
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer/src/wolf/ir/ast_to_ir.dart';
|
||||
import 'package:analyzer/src/wolf/ir/call_descriptor.dart';
|
||||
import 'package:analyzer/src/wolf/ir/coded_ir.dart';
|
||||
@@ -17,11 +16,13 @@ import 'package:test/test.dart' show fail;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../dart/resolution/context_collection_resolution.dart';
|
||||
import '../../dart/resolution/node_text_expectations.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AstToIRTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1781,15 +1782,14 @@ test() {
|
||||
}
|
||||
|
||||
test_variableDeclarationList_singleVariable_uninitialized_unsound() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
test() {
|
||||
int i;
|
||||
return i; // UNSOUND
|
||||
// ^
|
||||
// [diag.notAssignedPotentiallyNonNullableLocalVariable] The non-nullable local variable 'i' must be assigned before it can be used.
|
||||
}
|
||||
''',
|
||||
[error(diag.notAssignedPotentiallyNonNullableLocalVariable, 27, 1)],
|
||||
);
|
||||
''');
|
||||
analyze(findNode.singleFunctionDeclaration);
|
||||
check(astNodes)[findNode.variableDeclarationList('int i')].not(
|
||||
(s) => s.instructions.any((s) => s.opcode.equals(Opcode.writeLocal)),
|
||||
|
||||
Reference in New Issue
Block a user