CQ. Migrate diagnostics tests to resolveTestCodeWithDiagnostics. A-B.
Change-Id: I260150562d253f480f70f04b7038fc7bcdadca26 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501764 Reviewed-by: Johnni Winther <johnniwinther@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
63d042fe0d
commit
245105300c
@@ -186,6 +186,11 @@ class NodeTextExpectationsCollector {
|
||||
methodName: 'assertResolvedNodeText',
|
||||
argument: _ArgumentIndex(1),
|
||||
),
|
||||
_AssertMethod(
|
||||
className: 'ResolutionTest',
|
||||
methodName: 'resolveTestCodeWithDiagnostics',
|
||||
argument: _ArgumentIndex(0),
|
||||
),
|
||||
_AssertMethod(
|
||||
className: 'SearchTest',
|
||||
methodName: 'assertDeclarationsText',
|
||||
|
||||
@@ -24,6 +24,7 @@ import 'package:analyzer/src/test_utilities/find_element2.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_node.dart';
|
||||
import 'package:analyzer_testing/resource_provider_mixin.dart';
|
||||
import 'package:analyzer_testing/src/analysis_rule/pub_package_resolution.dart';
|
||||
import 'package:analyzer_testing/src/expected_diagnostics.dart';
|
||||
import 'package:analyzer_utilities/testing/tree_string_sink.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -462,6 +463,23 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
||||
return resolveTestFile();
|
||||
}
|
||||
|
||||
/// Resolves [code] and checks that its inline diagnostic markers match the
|
||||
/// diagnostics. Unmarked code is expected to have no diagnostics.
|
||||
Future<void> resolveTestCodeWithDiagnostics(String code) async {
|
||||
addTestFile(code);
|
||||
await resolveTestFile();
|
||||
|
||||
var actual = updateExpectedDiagnostics(
|
||||
content: code,
|
||||
actualDiagnostics: result.diagnostics,
|
||||
);
|
||||
if (actual != code) {
|
||||
NodeTextExpectationsCollector.add(actual);
|
||||
printPrettyDiff(code, actual);
|
||||
fail('See the difference above.');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resolveTestFile() {
|
||||
return resolveFile2(testFile);
|
||||
}
|
||||
|
||||
@@ -2,66 +2,52 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AbiSpecificIntegerMappingTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AbiSpecificIntegerMappingTest extends PubPackageResolutionTest {
|
||||
test_doubleMapping() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
@AbiSpecificIntegerMapping({})
|
||||
@AbiSpecificIntegerMapping({})
|
||||
// [diag.abiSpecificIntegerMappingExtra][column 2][length 25] Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a 'NativeType' integer with a fixed size.
|
||||
final class UintPtr extends AbiSpecificInteger {
|
||||
const UintPtr();
|
||||
}
|
||||
''',
|
||||
[error(diag.abiSpecificIntegerMappingExtra, 51, 25)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_invalidMapping() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
@AbiSpecificIntegerMapping({
|
||||
Abi.androidArm: Uint32(),
|
||||
Abi.androidArm64: IntPtr(),
|
||||
// ^^^^^^^^
|
||||
// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'IntPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported.
|
||||
Abi.androidIA32: UintPtr(),
|
||||
// ^^^^^^^^^
|
||||
// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'UintPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported.
|
||||
})
|
||||
final class UintPtr extends AbiSpecificInteger {
|
||||
const UintPtr();
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.abiSpecificIntegerMappingUnsupported,
|
||||
96,
|
||||
8,
|
||||
messageContains: ["Invalid mapping to 'IntPtr'"],
|
||||
),
|
||||
error(
|
||||
diag.abiSpecificIntegerMappingUnsupported,
|
||||
125,
|
||||
9,
|
||||
messageContains: ["Invalid mapping to 'UintPtr'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_invalidMapping_identifier() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
const c = {
|
||||
Abi.androidArm: Uint32(),
|
||||
@@ -69,41 +55,28 @@ const c = {
|
||||
Abi.androidIA32: UintPtr(),
|
||||
};
|
||||
@AbiSpecificIntegerMapping(c)
|
||||
// ^
|
||||
// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'IntPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported.
|
||||
// [diag.abiSpecificIntegerMappingUnsupported] Invalid mapping to 'UintPtr'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported.
|
||||
final class UintPtr extends AbiSpecificInteger {
|
||||
const UintPtr();
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.abiSpecificIntegerMappingUnsupported,
|
||||
149,
|
||||
1,
|
||||
messageContains: ["Invalid mapping to 'IntPtr'"],
|
||||
),
|
||||
error(
|
||||
diag.abiSpecificIntegerMappingUnsupported,
|
||||
149,
|
||||
1,
|
||||
messageContains: ["Invalid mapping to 'UintPtr'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noMapping() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class UintPtr extends AbiSpecificInteger {
|
||||
// ^^^^^^^
|
||||
// [diag.abiSpecificIntegerMappingMissing] Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a 'NativeType' integer with a fixed size.
|
||||
const UintPtr();
|
||||
}
|
||||
''',
|
||||
[error(diag.abiSpecificIntegerMappingMissing, 31, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_singleMapping() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
@AbiSpecificIntegerMapping({})
|
||||
final class UintPtr extends AbiSpecificInteger {
|
||||
@@ -113,7 +86,7 @@ final class UintPtr extends AbiSpecificInteger {
|
||||
}
|
||||
|
||||
test_validMapping() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
@AbiSpecificIntegerMapping({
|
||||
Abi.androidArm: Uint32(),
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AbstractClassMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AbstractClassMemberTest extends PubPackageResolutionTest {
|
||||
test_abstract_field_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract dynamic x;
|
||||
}
|
||||
@@ -23,7 +25,7 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_abstract_field_untyped() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract var x;
|
||||
}
|
||||
@@ -31,7 +33,7 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_abstract_field_untyped_covariant() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract covariant var x;
|
||||
}
|
||||
|
||||
+20
-23
@@ -2,57 +2,55 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AbstractFieldConstructorInitializerTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AbstractFieldConstructorInitializerTest extends PubPackageResolutionTest {
|
||||
test_abstract_field_constructor_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
A() : x = 0;
|
||||
// ^
|
||||
// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractFieldConstructorInitializer, 45, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_final_constructor_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
A() : x = 0;
|
||||
// ^
|
||||
// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractFieldConstructorInitializer, 51, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_final_initializing_formal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
A(this.x);
|
||||
// ^
|
||||
// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractFieldConstructorInitializer, 52, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_final_no_initialization() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
A();
|
||||
@@ -61,19 +59,18 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_abstract_field_initializing_formal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
A(this.x);
|
||||
// ^
|
||||
// [diag.abstractFieldConstructorInitializer] Abstract fields can't have initializers.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractFieldConstructorInitializer, 46, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_no_initialization() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
A();
|
||||
|
||||
@@ -2,32 +2,32 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AbstractFieldInitializerTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AbstractFieldInitializerTest extends PubPackageResolutionTest {
|
||||
test_abstract_field_final_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract final int x = 0;
|
||||
// ^
|
||||
// [diag.abstractFieldInitializer] Abstract fields can't have initializers.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractFieldInitializer, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_final_no_initializer() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
}
|
||||
@@ -35,18 +35,17 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_abstract_field_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract int x = 0;
|
||||
// ^
|
||||
// [diag.abstractFieldInitializer] Abstract fields can't have initializers.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractFieldInitializer, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_no_initializer() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AbstractSuperMemberReferenceTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AbstractSuperMemberReferenceTest extends PubPackageResolutionTest {
|
||||
test_methodInvocation_mixin_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo(int _) {}
|
||||
}
|
||||
@@ -25,11 +25,11 @@ class A {
|
||||
mixin M implements A {
|
||||
void bar() {
|
||||
super.foo(0);
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 82, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('super.foo(0)');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -56,7 +56,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_mixinHasConcrete() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
mixin M {
|
||||
@@ -92,8 +92,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_mixinHasNoSuchMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {
|
||||
void foo();
|
||||
noSuchMethod(im) => 42;
|
||||
@@ -101,11 +100,11 @@ mixin A {
|
||||
|
||||
class B extends Object with A {
|
||||
void foo() => super.foo(); // ref
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype.
|
||||
noSuchMethod(im) => 87;
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 107, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('super.foo()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -127,8 +126,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_superHasAbstract() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo(int _);
|
||||
}
|
||||
@@ -136,13 +134,13 @@ abstract class A {
|
||||
abstract class B extends A {
|
||||
void bar() {
|
||||
super.foo(0);
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype.
|
||||
}
|
||||
|
||||
void foo(int _) {} // does not matter
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 95, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('super.foo(0)');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -169,7 +167,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_superHasConcrete_mixinHasAbstract() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -205,7 +203,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_superHasNoSuchMethod() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo();
|
||||
noSuchMethod(im) => 42;
|
||||
@@ -237,7 +235,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_methodInvocation_superSuperHasConcrete() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -273,8 +271,7 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_propertyAccess_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
int get foo;
|
||||
}
|
||||
@@ -282,11 +279,11 @@ abstract class A {
|
||||
abstract class B extends A {
|
||||
bar() {
|
||||
super.foo; // ref
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 86, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -304,8 +301,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_getter_mixin_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
@@ -313,11 +309,11 @@ class A {
|
||||
mixin M implements A {
|
||||
void bar() {
|
||||
super.foo;
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 81, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -335,8 +331,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_getter_mixinHasNoSuchMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {
|
||||
int get foo;
|
||||
noSuchMethod(im) => 1;
|
||||
@@ -344,11 +339,11 @@ mixin A {
|
||||
|
||||
class B extends Object with A {
|
||||
int get foo => super.foo; // ref
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype.
|
||||
noSuchMethod(im) => 2;
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 108, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -366,7 +361,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_getter_superHasNoSuchMethod() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get foo;
|
||||
noSuchMethod(im) => 1;
|
||||
@@ -394,8 +389,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_getter_superImplements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
@@ -405,10 +399,10 @@ abstract class B implements A {
|
||||
|
||||
class C extends B {
|
||||
int get foo => super.foo; // ref
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The getter 'foo' is always abstract in the supertype.
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 111, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -426,7 +420,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_getter_superSuperHasConcrete() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
@@ -456,8 +450,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_method_tearOff_abstract() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -465,11 +458,11 @@ abstract class A {
|
||||
abstract class B extends A {
|
||||
void bar() {
|
||||
super.foo; // ref
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The method 'foo' is always abstract in the supertype.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 90, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePropertyAccess;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -487,8 +480,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_propertyAccess_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
set foo(int _);
|
||||
}
|
||||
@@ -496,11 +488,11 @@ abstract class A {
|
||||
abstract class B extends A {
|
||||
void bar() {
|
||||
super.foo = 0;
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The setter 'foo' is always abstract in the supertype.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 94, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.assignment('foo ='), r'''
|
||||
AssignmentExpression
|
||||
@@ -529,8 +521,7 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_setter_mixin_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set foo(int _) {}
|
||||
}
|
||||
@@ -538,11 +529,11 @@ class A {
|
||||
mixin M implements A {
|
||||
void bar() {
|
||||
super.foo = 0;
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The setter 'foo' is always abstract in the supertype.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 81, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.assignment('foo ='), r'''
|
||||
AssignmentExpression
|
||||
@@ -571,8 +562,7 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_setter_mixinHasNoSuchMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {
|
||||
set foo(int a);
|
||||
noSuchMethod(im) {}
|
||||
@@ -580,11 +570,11 @@ mixin A {
|
||||
|
||||
class B extends Object with A {
|
||||
set foo(int a) => super.foo = a; // ref
|
||||
// ^^^
|
||||
// [diag.abstractSuperMemberReference] The setter 'foo' is always abstract in the supertype.
|
||||
noSuchMethod(im) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.abstractSuperMemberReference, 111, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.assignment('foo ='), r'''
|
||||
AssignmentExpression
|
||||
@@ -614,7 +604,7 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_setter_superHasNoSuchMethod() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set foo(int a);
|
||||
noSuchMethod(im) => 1;
|
||||
@@ -654,7 +644,7 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_propertyAccess_setter_superSuperHasConcrete() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void set foo(int _) {}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AmbiguousExportTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,13 +24,12 @@ class N {}
|
||||
newFile('$testPackageLibPath/lib2.dart', r'''
|
||||
class N {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'lib1.dart';
|
||||
export 'lib2.dart';
|
||||
''',
|
||||
[error(diag.ambiguousExport, 27, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.ambiguousExport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_library_extensions_bothExported() async {
|
||||
@@ -38,20 +39,19 @@ extension E on String {}
|
||||
newFile('$testPackageLibPath/lib2.dart', r'''
|
||||
extension E on String {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'lib1.dart';
|
||||
export 'lib2.dart';
|
||||
''',
|
||||
[error(diag.ambiguousExport, 27, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.ambiguousExport] The name 'E' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_library_extensions_localAndExported() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
extension E on String {}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'lib1.dart';
|
||||
|
||||
extension E on String {}
|
||||
|
||||
@@ -6,18 +6,19 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AmbiguousExtensionMemberAccessTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AmbiguousExtensionMemberAccessTest extends PubPackageResolutionTest {
|
||||
test_call() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
extension E1 on A {
|
||||
@@ -29,14 +30,13 @@ extension E2 on A {
|
||||
}
|
||||
|
||||
int f(A a) => a();
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 110, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'call' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific.
|
||||
''');
|
||||
}
|
||||
|
||||
test_getter_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int {
|
||||
void get a => 1;
|
||||
}
|
||||
@@ -47,10 +47,10 @@ extension E2 on int {
|
||||
|
||||
f() {
|
||||
0.a;
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 98, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.propertyAccess('0.a');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -68,7 +68,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_getter_getterStatic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int {
|
||||
void get a => 1;
|
||||
}
|
||||
@@ -98,8 +98,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_getter_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {
|
||||
int get a => 1;
|
||||
}
|
||||
@@ -110,10 +109,10 @@ extension E2 on int {
|
||||
|
||||
f() {
|
||||
0.a;
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 91, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.propertyAccess('0.a');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -131,8 +130,7 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_getter_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {
|
||||
int get a => 1;
|
||||
}
|
||||
@@ -143,10 +141,10 @@ extension E2 on int {
|
||||
|
||||
f() {
|
||||
0.a;
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 96, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.propertyAccess('0.a');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -164,26 +162,16 @@ PropertyAccess
|
||||
}
|
||||
|
||||
test_method_conflict_conflict_notSpecific() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int { void foo() {} }
|
||||
extension E2 on int { void foo() {} }
|
||||
extension E on int? { void foo() {} }
|
||||
void f() {
|
||||
0.foo();
|
||||
// ^^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.ambiguousExtensionMemberAccessTwo,
|
||||
129,
|
||||
3,
|
||||
messageContains: [
|
||||
"in 'extension E1 on int' and 'extension E2 on int',",
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_conflict_conflict_notSpecific_sameName() async {
|
||||
@@ -218,39 +206,26 @@ void f() {
|
||||
}
|
||||
|
||||
test_method_conflict_conflict_notSpecific_sameName_invalidType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore_for_file: unused_element
|
||||
void f(Iterable<void> p) {
|
||||
p.foo();
|
||||
// ^^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo][context 1][context 2] A member named 'foo' is defined in 'extension on Iterable<InvalidType> (where <unnamed extension> is defined in /home/test/lib/test.dart)' and 'extension on Iterable<InvalidType> (where <unnamed extension> is defined in /home/test/lib/test.dart)', and neither is more specific.
|
||||
}
|
||||
extension on Iterable<Undef1> { void foo() {} }
|
||||
// [context 1][column 1][length 0] <unnamed extension> is defined in /home/test/lib/test.dart
|
||||
// ^^^^^^
|
||||
// [diag.nonTypeAsTypeArgument] The name 'Undef1' isn't a type, so it can't be used as a type argument.
|
||||
extension on Iterable<Undef2> { void foo() {} }
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.ambiguousExtensionMemberAccessTwo,
|
||||
66,
|
||||
3,
|
||||
messageContains: [
|
||||
"'extension on Iterable<InvalidType> "
|
||||
"(where <unnamed extension> is defined in ${testFile.path})' and "
|
||||
"'extension on Iterable<InvalidType> "
|
||||
"(where <unnamed extension> is defined in ${testFile.path})',",
|
||||
],
|
||||
contextMessages: [
|
||||
message(testFile, 75, 0),
|
||||
message(testFile, 123, 0),
|
||||
],
|
||||
),
|
||||
error(diag.nonTypeAsTypeArgument, 97, 6),
|
||||
error(diag.nonTypeAsTypeArgument, 145, 6),
|
||||
],
|
||||
);
|
||||
// [context 2][column 1][length 0] <unnamed extension> is defined in /home/test/lib/test.dart
|
||||
// ^^^^^^
|
||||
// [diag.nonTypeAsTypeArgument] The name 'Undef2' isn't a type, so it can't be used as a type argument.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_conflict_conflict_specific() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int? { void foo() {} }
|
||||
extension E2 on int? { void foo() {} }
|
||||
extension E on int { void foo() {} }
|
||||
@@ -261,30 +236,20 @@ void f() {
|
||||
}
|
||||
|
||||
test_method_conflict_notSpecific_conflict() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int { void foo() {} }
|
||||
extension E on int? { void foo() {} }
|
||||
extension E2 on int { void foo() {} }
|
||||
void f() {
|
||||
0.foo();
|
||||
// ^^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.ambiguousExtensionMemberAccessTwo,
|
||||
129,
|
||||
3,
|
||||
messageContains: [
|
||||
"in 'extension E1 on int' and 'extension E2 on int',",
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_conflict_specific_conflict() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int? { void foo() {} }
|
||||
extension E on int { void foo() {} }
|
||||
extension E2 on int? { void foo() {} }
|
||||
@@ -295,8 +260,7 @@ void f() {
|
||||
}
|
||||
|
||||
test_method_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int {
|
||||
void a() {}
|
||||
}
|
||||
@@ -307,10 +271,10 @@ extension E2 on int {
|
||||
|
||||
f() {
|
||||
0.a();
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 88, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.methodInvocation('0.a()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -332,54 +296,34 @@ MethodInvocation
|
||||
}
|
||||
|
||||
test_method_notSpecific_conflict_conflict() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int? { void foo() {} }
|
||||
extension E1 on int { void foo() {} }
|
||||
extension E2 on int { void foo() {} }
|
||||
void f() {
|
||||
0.foo();
|
||||
// ^^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.ambiguousExtensionMemberAccessTwo,
|
||||
129,
|
||||
3,
|
||||
messageContains: [
|
||||
"in 'extension E1 on int' and 'extension E2 on int',",
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_notSpecific_conflict_conflict_conflict() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int? { void foo() {} }
|
||||
extension E1 on int { void foo() {} }
|
||||
extension E2 on int { void foo() {} }
|
||||
extension E3 on int { void foo() {} }
|
||||
void f() {
|
||||
0.foo();
|
||||
// ^^^
|
||||
// [diag.ambiguousExtensionMemberAccessThreeOrMore] A member named 'foo' is defined in extension 'E1', extension 'E2', and extension 'E3', and none are more specific.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.ambiguousExtensionMemberAccessThreeOrMore,
|
||||
167,
|
||||
3,
|
||||
messageContains: [
|
||||
"in extension 'E1', extension 'E2', and extension 'E3',",
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_specific_conflict_conflict() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int { void foo() {} }
|
||||
extension E1 on int? { void foo() {} }
|
||||
extension E2 on int? { void foo() {} }
|
||||
@@ -421,8 +365,7 @@ void f() {
|
||||
}
|
||||
|
||||
test_noMoreSpecificExtension() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class Target<T> {}
|
||||
|
||||
class SubTarget<T> extends Target<T> {}
|
||||
@@ -440,15 +383,14 @@ f(SubTarget<num> t) {
|
||||
// The instantiated on type of `E2(t)` is `Target<num>`.
|
||||
// Neither is a subtype of the other, so the resolution is ambiguous.
|
||||
t.foo;
|
||||
// ^^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'foo' is defined in 'extension E1 on SubTarget<Object>' and 'extension E2<T> on Target<T>', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 396, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_operator_binary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
extension E1 on A {
|
||||
@@ -460,14 +402,13 @@ extension E2 on A {
|
||||
}
|
||||
|
||||
A f(A a) => a + a;
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 122, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named '+' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific.
|
||||
''');
|
||||
}
|
||||
|
||||
test_operator_binary_compoundAssignment() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
extension E1 on A {
|
||||
@@ -480,15 +421,14 @@ extension E2 on A {
|
||||
|
||||
void f(A a) {
|
||||
a += 0;
|
||||
// ^^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named '+' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 130, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_operator_index_index() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
extension E1 on A {
|
||||
@@ -500,14 +440,13 @@ extension E2 on A {
|
||||
}
|
||||
|
||||
int f(A a) => a[0];
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 134, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named '[]' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific.
|
||||
''');
|
||||
}
|
||||
|
||||
test_operator_index_indexEq() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int {
|
||||
int operator[](int index) => 0;
|
||||
}
|
||||
@@ -518,15 +457,14 @@ extension E2 on int {
|
||||
|
||||
f() {
|
||||
0[1] += 2;
|
||||
//^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named '[]' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 136, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_operator_unary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
extension E1 on A {
|
||||
@@ -538,14 +476,13 @@ extension E2 on A {
|
||||
}
|
||||
|
||||
int f(A a) => -a;
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 123, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'unary-' is defined in 'extension E1 on A' and 'extension E2 on A', and neither is more specific.
|
||||
''');
|
||||
}
|
||||
|
||||
test_setter_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E1 on int {
|
||||
set a(x) {}
|
||||
}
|
||||
@@ -556,10 +493,10 @@ extension E2 on int {
|
||||
|
||||
f() {
|
||||
0.a = 3;
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'a' is defined in 'extension E1 on int' and 'extension E2 on int', and neither is more specific.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousExtensionMemberAccessTwo, 88, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.assignment('= 3'), r'''
|
||||
AssignmentExpression
|
||||
@@ -588,8 +525,7 @@ AssignmentExpression
|
||||
}
|
||||
|
||||
test_unnamed_extensions() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B {}
|
||||
class C extends A implements B {}
|
||||
@@ -603,21 +539,12 @@ extension on List<B> {
|
||||
}
|
||||
|
||||
int f(List<C> x) => x();
|
||||
// ^
|
||||
// [diag.ambiguousExtensionMemberAccessTwo] A member named 'call' is defined in 'extension on List<A>' and 'extension on List<B>', and neither is more specific.
|
||||
|
||||
// Additional calls to avoid UNUSED_ELEMENT
|
||||
int g(List<A> x) => x();
|
||||
int h(List<B> x) => x();
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.ambiguousExtensionMemberAccessTwo,
|
||||
167,
|
||||
1,
|
||||
messageContains: [
|
||||
"'extension on List<A>' and 'extension on List<B>',",
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AmbiguousImportTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,19 +30,15 @@ const foo = 0;
|
||||
const foo = 0;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
import 'b.dart';
|
||||
|
||||
@foo
|
||||
// [diag.invalidAnnotation][column 1][length 4] Annotation must be either a const variable reference or const constructor invocation.
|
||||
// [diag.ambiguousImport][column 2][length 3] The name 'foo' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
class A {}
|
||||
''',
|
||||
[
|
||||
error(diag.invalidAnnotation, 35, 4),
|
||||
error(diag.ambiguousImport, 36, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_as() async {
|
||||
@@ -50,12 +48,13 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
f(p) {p as N;}''',
|
||||
[error(diag.ambiguousImport, 51, 1)],
|
||||
f(p) {p as N;}
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,12 +65,14 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
class A extends N {}''',
|
||||
[error(diag.ambiguousImport, 56, 1), error(diag.extendsNonClass, 56, 1)],
|
||||
class A extends N {}
|
||||
// ^
|
||||
// [diag.extendsNonClass] Classes can only extend other classes.
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -82,15 +83,14 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
class A implements N {}''',
|
||||
[
|
||||
error(diag.implementsNonClass, 59, 1),
|
||||
error(diag.ambiguousImport, 59, 1),
|
||||
],
|
||||
class A implements N {}
|
||||
// ^
|
||||
// [diag.implementsNonClass] Classes and mixins can only implement other classes and mixins.
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,13 +128,14 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
library L;
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
f() {new N();}''',
|
||||
[error(diag.ambiguousImport, 60, 1)],
|
||||
f() {new N();}
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,20 +146,18 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library L;
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
f() {
|
||||
N n = .new();
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
// ^^^
|
||||
// [diag.dotShorthandUndefinedInvocation] The static method or constructor 'new' isn't defined for the context type 'InvalidType'.
|
||||
print(n);
|
||||
}''',
|
||||
[
|
||||
error(diag.ambiguousImport, 59, 1),
|
||||
error(diag.dotShorthandUndefinedInvocation, 66, 3),
|
||||
],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_is() async {
|
||||
@@ -168,12 +167,13 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
f(p) {p is N;}''',
|
||||
[error(diag.ambiguousImport, 51, 1)],
|
||||
f(p) {p is N;}
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -184,12 +184,13 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
g() { N.FOO; }''',
|
||||
[error(diag.ambiguousImport, 46, 1)],
|
||||
g() { N.FOO; }
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,7 +200,7 @@ g() { N.FOO; }''',
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class StreamController {}
|
||||
''');
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async'; // ignore: unused_import
|
||||
import 'a.dart';
|
||||
|
||||
@@ -208,14 +209,13 @@ StreamController s = StreamController();
|
||||
}
|
||||
|
||||
test_systemLibrary_systemLibrary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:html';
|
||||
import 'dart:io';
|
||||
g(File f) {}
|
||||
''',
|
||||
[error(diag.ambiguousImport, 40, 4)],
|
||||
);
|
||||
//^^^^
|
||||
// [diag.ambiguousImport] The name 'File' is defined in the libraries 'dart:html' and 'dart:io'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeAnnotation() async {
|
||||
@@ -225,29 +225,34 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
typedef N FT(N p);
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
N f(N p) {
|
||||
// [diag.ambiguousImport][column 1][length 1] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
N v;
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
return null;
|
||||
}
|
||||
class A {
|
||||
N m() { return null; }
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||
}
|
||||
class B<T extends N> {}''',
|
||||
[
|
||||
error(diag.ambiguousImport, 48, 1),
|
||||
error(diag.ambiguousImport, 53, 1),
|
||||
error(diag.ambiguousImport, 59, 1),
|
||||
error(diag.ambiguousImport, 63, 1),
|
||||
error(diag.ambiguousImport, 72, 1),
|
||||
error(diag.unusedLocalVariable, 74, 1),
|
||||
error(diag.ambiguousImport, 106, 1),
|
||||
error(diag.ambiguousImport, 149, 1),
|
||||
],
|
||||
class B<T extends N> {}
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -258,13 +263,14 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
class A<T> {}
|
||||
A<N>? f() { return null; }''',
|
||||
[error(diag.ambiguousImport, 56, 1)],
|
||||
A<N>? f() { return null; }
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -275,13 +281,14 @@ class N {}''');
|
||||
newFile("$testPackageLibPath/lib2.dart", '''
|
||||
library lib2;
|
||||
class N {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
import 'lib1.dart';
|
||||
import 'lib2.dart';
|
||||
class A<T> {}
|
||||
f() {new A<N>();}''',
|
||||
[error(diag.ambiguousImport, 65, 1)],
|
||||
f() {new A<N>();}
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -294,17 +301,16 @@ var x;
|
||||
var x;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
import 'b.dart';
|
||||
|
||||
void f() {
|
||||
x;
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousImport, 48, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_variable_read_prefixed() async {
|
||||
@@ -316,17 +322,16 @@ var x;
|
||||
var x;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' as p;
|
||||
import 'b.dart' as p;
|
||||
|
||||
void f() {
|
||||
p.x;
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousImport, 60, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_variable_write() async {
|
||||
@@ -338,25 +343,25 @@ var x;
|
||||
var x;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
import 'b.dart';
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
x += 1;
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
x++;
|
||||
//^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.ambiguousImport, 48, 1, messageContains: ["'x'"]),
|
||||
error(diag.ambiguousImport, 57, 1),
|
||||
error(diag.ambiguousImport, 69, 1),
|
||||
error(diag.ambiguousImport, 74, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_variable_write_prefixed() async {
|
||||
@@ -368,24 +373,24 @@ var x;
|
||||
var x;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' as p;
|
||||
import 'b.dart' as p;
|
||||
|
||||
void f() {
|
||||
p.x = 0;
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
p.x += 1;
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
++p.x;
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
p.x++;
|
||||
// ^
|
||||
// [diag.ambiguousImport] The name 'x' is defined in the libraries 'package:test/a.dart' and 'package:test/b.dart'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.ambiguousImport, 60, 1),
|
||||
error(diag.ambiguousImport, 71, 1),
|
||||
error(diag.ambiguousImport, 85, 1),
|
||||
error(diag.ambiguousImport, 92, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,23 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AmbiguousSetOrMapLiteralBothTest);
|
||||
defineReflectiveTests(AmbiguousSetOrMapLiteralEitherTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AmbiguousSetOrMapLiteralBothTest extends PubPackageResolutionTest {
|
||||
test_map() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map<int, int> map) {
|
||||
return {...map};
|
||||
}
|
||||
@@ -25,7 +26,7 @@ f(Map<int, int> map) {
|
||||
}
|
||||
|
||||
test_map_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map map) {
|
||||
return {...map};
|
||||
}
|
||||
@@ -33,7 +34,7 @@ f(Map map) {
|
||||
}
|
||||
|
||||
test_map_keyNonNullable_valueNullable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map<int, int?> map) {
|
||||
return {...map};
|
||||
}
|
||||
@@ -41,7 +42,7 @@ f(Map<int, int?> map) {
|
||||
}
|
||||
|
||||
test_map_keyNullable_valueNonNullable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map<int?, int> map) {
|
||||
return {...map};
|
||||
}
|
||||
@@ -49,7 +50,7 @@ f(Map<int?, int> map) {
|
||||
}
|
||||
|
||||
test_map_keyNullable_valueNullable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map<int?, int?> map) {
|
||||
return {...map};
|
||||
}
|
||||
@@ -57,7 +58,7 @@ f(Map<int?, int?> map) {
|
||||
}
|
||||
|
||||
test_set() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Set<int> set) {
|
||||
return {...set};
|
||||
}
|
||||
@@ -65,7 +66,7 @@ f(Set<int> set) {
|
||||
}
|
||||
|
||||
test_set_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Set set) {
|
||||
return {...set};
|
||||
}
|
||||
@@ -73,7 +74,7 @@ f(Set set) {
|
||||
}
|
||||
|
||||
test_set_elementNullable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Set<int?> set) {
|
||||
return {...set};
|
||||
}
|
||||
@@ -81,25 +82,23 @@ f(Set<int?> set) {
|
||||
}
|
||||
|
||||
test_setAndMap() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map<int, int> map, Set<int> set) {
|
||||
return {...set, ...map};
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.ambiguousSetOrMapLiteralBoth] The literal can't be either a map or a set because it contains at least one literal map entry or a spread operator spreading a 'Map', and at least one element which is neither of these.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousSetOrMapLiteralBoth, 46, 16)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_setAndMap_nullable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Map<int?, int> map, Set<int?> set) {
|
||||
return {...set, ...map};
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.ambiguousSetOrMapLiteralBoth] The literal can't be either a map or a set because it contains at least one literal map entry or a spread operator spreading a 'Map', and at least one element which is neither of these.
|
||||
}
|
||||
''',
|
||||
[error(diag.ambiguousSetOrMapLiteralBoth, 48, 16)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,22 +106,20 @@ f(Map<int?, int> map, Set<int?> set) {
|
||||
class AmbiguousSetOrMapLiteralEitherTest extends PubPackageResolutionTest {
|
||||
test_invalidPrefixOperator() async {
|
||||
// Guard against an exception being thrown.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
union(a, b) => !{...a, ...b};
|
||||
''',
|
||||
[error(diag.ambiguousSetOrMapLiteralEither, 16, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.ambiguousSetOrMapLiteralEither] This literal must be either a map or a set, but the elements don't have enough information for type inference to work.
|
||||
''');
|
||||
}
|
||||
|
||||
test_setAndMap() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var map;
|
||||
var set;
|
||||
var c = {...set, ...map};
|
||||
''',
|
||||
[error(diag.ambiguousSetOrMapLiteralEither, 26, 16)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.ambiguousSetOrMapLiteralEither] This literal must be either a map or a set, but the elements don't have enough information for type inference to work.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,42 +2,41 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AnnotationOnPointerFieldTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AnnotationOnPointerFieldTest extends PubPackageResolutionTest {
|
||||
test_double() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
@Double()
|
||||
//^^^^^^^^^
|
||||
// [diag.annotationOnPointerField] Fields in a struct class whose type is 'Pointer' shouldn't have any annotations.
|
||||
external Pointer<Int8> x;
|
||||
}
|
||||
''',
|
||||
[error(diag.annotationOnPointerField, 52, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_int32() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
@Int32()
|
||||
//^^^^^^^^
|
||||
// [diag.annotationOnPointerField] Fields in a struct class whose type is 'Pointer' shouldn't have any annotations.
|
||||
external Pointer<Float> x;
|
||||
}
|
||||
''',
|
||||
[error(diag.annotationOnPointerField, 52, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AnnotationSyntaxTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AnnotationSyntaxTest extends PubPackageResolutionTest {
|
||||
test_annotation_on_type_argument() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const annotation = null;
|
||||
|
||||
class Annotation {
|
||||
@@ -29,12 +29,11 @@ class A<E> {}
|
||||
|
||||
class C {
|
||||
m() => new A<@annotation @Annotation("test") C>();
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.annotationOnTypeArgument] Type arguments can't have annotations because they aren't declarations.
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.annotationOnTypeArgument] Type arguments can't have annotations because they aren't declarations.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.annotationOnTypeArgument, 146, 11),
|
||||
error(diag.annotationOnTypeArgument, 158, 19),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ArgumentMustBeAConstantTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ArgumentMustBeAConstantTest extends PubPackageResolutionTest {
|
||||
test_AsFunctionIsLeafGlobal() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef Int8UnOp = Int8 Function(Int8);
|
||||
typedef IntUnOp = int Function(int);
|
||||
@@ -25,16 +25,15 @@ bool isLeaf = false;
|
||||
doThings() {
|
||||
Pointer<NativeFunction<Int8UnOp>> p = Pointer.fromAddress(1337);
|
||||
IntUnOp f = p.asFunction(isLeaf:isLeaf);
|
||||
// ^^^^^^
|
||||
// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant.
|
||||
f(8);
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentMustBeAConstant, 231, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_AsFunctionIsLeafLocal() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef Int8UnOp = Int8 Function(Int8);
|
||||
typedef IntUnOp = int Function(int);
|
||||
@@ -42,56 +41,53 @@ doThings() {
|
||||
bool isLeaf = false;
|
||||
Pointer<NativeFunction<Int8UnOp>> p = Pointer.fromAddress(1337);
|
||||
IntUnOp f = p.asFunction(isLeaf:isLeaf);
|
||||
// ^^^^^^
|
||||
// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant.
|
||||
f(8);
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentMustBeAConstant, 233, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_AsFunctionIsLeafParam() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef Int8UnOp = Int8 Function(Int8);
|
||||
typedef IntUnOp = int Function(int);
|
||||
doThings(bool isLeaf) {
|
||||
Pointer<NativeFunction<Int8UnOp>> p = Pointer.fromAddress(1337);
|
||||
IntUnOp f = p.asFunction(isLeaf:isLeaf);
|
||||
// ^^^^^^
|
||||
// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant.
|
||||
f(8);
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentMustBeAConstant, 221, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_FromFunctionExceptionReturn() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef NativeDoubleUnOp = Double Function(Double);
|
||||
double myTimesThree(double d) => d * 3;
|
||||
void testFromFunctionFunctionExceptionValueMustBeConst() {
|
||||
final notAConst = 1.1;
|
||||
Pointer.fromFunction<NativeDoubleUnOp>(myTimesThree, notAConst);
|
||||
// ^^^^^^^^^
|
||||
// [diag.argumentMustBeAConstant] Argument 'exceptionalReturn' must be a constant.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentMustBeAConstant, 250, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_LookupFunctionIsLeaf() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef Int8UnOp = Int8 Function(Int8);
|
||||
typedef IntUnOp = int Function(int);
|
||||
doThings(bool isLeaf) {
|
||||
DynamicLibrary l = DynamicLibrary.open("my_lib");
|
||||
l.lookupFunction<Int8UnOp, IntUnOp>("timesFour", isLeaf:isLeaf);
|
||||
// ^^^^^^
|
||||
// [diag.argumentMustBeAConstant] Argument 'isLeaf' must be a constant.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentMustBeAConstant, 230, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@ import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ArgumentTypeNotAssignableTest);
|
||||
defineReflectiveTests(ArgumentTypeNotAssignableWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,15 +24,14 @@ class ArgumentTypeNotAssignableTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/lib2.dart', '''
|
||||
class _A {}
|
||||
g(h(_A a)) {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib2.dart';
|
||||
class _A {}
|
||||
f() {
|
||||
g((_A a) {});
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 42, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'Null Function(_A)' can't be assigned to the parameter type 'dynamic Function(_A)'.
|
||||
}''');
|
||||
// The name _A is private to the library it's defined in, so this is a type
|
||||
// mismatch. Furthermore, the error message should mention both _A and the
|
||||
// filenames so the user can figure out what's going on.
|
||||
@@ -39,45 +40,42 @@ f() {
|
||||
}
|
||||
|
||||
test_annotation_extensionType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type const A(String _) {}
|
||||
|
||||
@A(0)
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
void f() {}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_annotation_namedConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.fromInt(int p);
|
||||
}
|
||||
@A.fromInt('0')
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
main() {}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 49, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_annotation_namedConstructor_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
const A.fromInt(T p);
|
||||
}
|
||||
@A<int>.fromInt('0')
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
main() {
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 55, 3)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_annotation_type_arguments_inferred() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
@C([])
|
||||
int i = 0;
|
||||
|
||||
@@ -88,69 +86,63 @@ class C<T> {
|
||||
}
|
||||
|
||||
test_annotation_unnamedConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A(int p);
|
||||
}
|
||||
@A('0')
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
main() {
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 33, 3)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_binary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
operator +(int p) {}
|
||||
}
|
||||
f(A a) {
|
||||
a + '0';
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 50, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_binary_eqEq_covariantParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
bool operator==(covariant A other) => false;
|
||||
}
|
||||
|
||||
void f(A a, A? aq) {
|
||||
a == 0;
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'.
|
||||
aq == 1;
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'A?'.
|
||||
aq == aq;
|
||||
aq == null;
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.argumentTypeNotAssignable, 88, 1),
|
||||
error(diag.argumentTypeNotAssignable, 99, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_call() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef bool Predicate<T>(T object);
|
||||
|
||||
Predicate<String> f() => (String s) => false;
|
||||
|
||||
void main() {
|
||||
f().call(3);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 110, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_cascadeSecond() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// filler filler filler filler filler filler filler filler filler filler
|
||||
class A {
|
||||
B ma() { return new B(); }
|
||||
@@ -162,68 +154,62 @@ class B {
|
||||
main() {
|
||||
A a = new A();
|
||||
a.. ma().mb(0);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 186, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_const() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A(String p);
|
||||
}
|
||||
main() {
|
||||
const A(42);
|
||||
}''',
|
||||
[
|
||||
error(diag.argumentTypeNotAssignable, 52, 2),
|
||||
error(diag.constConstructorParamTypeMismatch, 52, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
// [diag.constConstructorParamTypeMismatch] A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_const_super() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A(String p);
|
||||
}
|
||||
class B extends A {
|
||||
const B() : super(42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 73, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_downcast() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
num y = 1;
|
||||
n(y);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'num' can't be assigned to the parameter type 'int'.
|
||||
}
|
||||
n(int x) {}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_downcast_nullableNonNullable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
int? y;
|
||||
n(y);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int?' can't be assigned to the parameter type 'int'.
|
||||
}
|
||||
n(int x) {}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_dynamicCast() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
dynamic i;
|
||||
n(i);
|
||||
@@ -233,22 +219,19 @@ n(int i) {}
|
||||
}
|
||||
|
||||
test_enumConstant() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(0);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
// [diag.constConstructorParamTypeMismatch] A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor.
|
||||
const E(String a);
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.argumentTypeNotAssignable, 13, 1),
|
||||
error(diag.constConstructorParamTypeMismatch, 13, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enumConstant_implicitDouble() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(0);
|
||||
const E(double a);
|
||||
@@ -257,7 +240,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_expressionFromConstructorTearoff_withoutTypeArgs() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {
|
||||
C(T a);
|
||||
}
|
||||
@@ -268,7 +251,7 @@ var x = g('Hello');
|
||||
}
|
||||
|
||||
test_expressionFromConstructorTearoff_withTypeArgs_assignable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {
|
||||
C(T a);
|
||||
}
|
||||
@@ -279,21 +262,20 @@ var x = g(0);
|
||||
}
|
||||
|
||||
test_expressionFromConstructorTearoff_withTypeArgs_notAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {
|
||||
C(T a);
|
||||
}
|
||||
|
||||
var g = C<int>.new;
|
||||
var x = g('Hello');
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 56, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_expressionFromFunctionTearoff_withoutTypeArgs() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T a) {}
|
||||
|
||||
var g = f;
|
||||
@@ -302,7 +284,7 @@ var x = g('Hello');
|
||||
}
|
||||
|
||||
test_expressionFromFunctionTearoff_withTypeArgs_assignable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T a) {}
|
||||
|
||||
var g = f<int>;
|
||||
@@ -311,20 +293,19 @@ var x = g(0);
|
||||
}
|
||||
|
||||
test_expressionFromFunctionTearoff_withTypeArgs_notAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T a) {}
|
||||
|
||||
var g = f<int>;
|
||||
var x = g('Hello');
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 45, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_for_element_type_inferred_from_rewritten_node() async {
|
||||
// See https://github.com/dart-lang/sdk/issues/39171
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(Iterable<T> Function() g, int Function(T) h) {
|
||||
[for (var x in g()) if (x is String) h(x)];
|
||||
}
|
||||
@@ -333,7 +314,7 @@ void f<T>(Iterable<T> Function() g, int Function(T) h) {
|
||||
|
||||
test_for_statement_type_inferred_from_rewritten_node() async {
|
||||
// See https://github.com/dart-lang/sdk/issues/39171
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(Iterable<T> Function() g, void Function(T) h) {
|
||||
for (var x in g()) {
|
||||
if (x is String) {
|
||||
@@ -345,32 +326,30 @@ void f<T>(Iterable<T> Function() g, void Function(T) h) {
|
||||
}
|
||||
|
||||
test_functionExpressionInvocation_required() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
(int x) {} ('');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 23, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_functionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
var a = new A();
|
||||
a.n(() => 0);
|
||||
// ^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'void Function()' can't be assigned to the parameter type 'void Function(int)'.
|
||||
}
|
||||
class A {
|
||||
n(void f(int i)) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 31, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_implicitCallReference() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void call(int p) {}
|
||||
}
|
||||
@@ -382,7 +361,7 @@ void g(A a) {
|
||||
}
|
||||
|
||||
test_implicitCallReference_named() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void call(int p) {}
|
||||
}
|
||||
@@ -395,7 +374,7 @@ void g(A a) {
|
||||
}
|
||||
|
||||
test_implicitCallReference_namedAndRequired() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void call(int p) {}
|
||||
}
|
||||
@@ -407,7 +386,7 @@ void g(A a) {
|
||||
}
|
||||
|
||||
test_implicitCallReference_this() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void call(int p) {}
|
||||
|
||||
@@ -420,243 +399,225 @@ class A {
|
||||
}
|
||||
|
||||
test_index_invalidRead() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int operator [](int index) => 0;
|
||||
}
|
||||
f(A a) {
|
||||
a['0'];
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 60, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_index_invalidRead_validWrite() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int operator [](int index) => 0;
|
||||
operator []=(String index, int value) {}
|
||||
}
|
||||
f(A a) {
|
||||
a['0'] += 0;
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
++a['0'];
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
a['0']++;
|
||||
}''',
|
||||
[
|
||||
error(diag.argumentTypeNotAssignable, 103, 3),
|
||||
error(diag.argumentTypeNotAssignable, 120, 3),
|
||||
error(diag.argumentTypeNotAssignable, 130, 3),
|
||||
],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_index_invalidWrite() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
operator []=(int index, int value) {}
|
||||
}
|
||||
f(A a) {
|
||||
a['0'] = 0;
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 65, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_index_validRead_invalidWrite() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int operator [](String index) => 0;
|
||||
operator []=(int index, int value) {}
|
||||
}
|
||||
f(A a) {
|
||||
a['0'] += 0;
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
++a['0'];
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
a['0']++;
|
||||
}''',
|
||||
[
|
||||
error(diag.argumentTypeNotAssignable, 103, 3),
|
||||
error(diag.argumentTypeNotAssignable, 120, 3),
|
||||
error(diag.argumentTypeNotAssignable, 130, 3),
|
||||
],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_interfaceType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
var i = '';
|
||||
n(i);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}
|
||||
n(int i) {}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_invocation_callParameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
call(int p) {}
|
||||
}
|
||||
f(A a) {
|
||||
a('0');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 42, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_callVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
call(int p) {}
|
||||
}
|
||||
main() {
|
||||
A a = new A();
|
||||
a('0');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 59, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_functionParameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
a(b(int p)) {
|
||||
b('0');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 18, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_functionParameter_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<K, V> {
|
||||
m(f(K k), V v) {
|
||||
f(v);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'V' can't be assigned to the parameter type 'K'.
|
||||
}
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 41, 1)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_functionTypes_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void acceptFunOptBool(void funNumOptBool([bool b])) {}
|
||||
void funBool(bool b) {}
|
||||
main() {
|
||||
acceptFunOptBool(funBool);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 107, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_functionTypes_optional_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void acceptFunOptBool(void funOptBool([bool b])) {}
|
||||
class C {
|
||||
static void funBool(bool b) {}
|
||||
}
|
||||
main() {
|
||||
acceptFunOptBool(C.funBool);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 125, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'void Function(bool)' can't be assigned to the parameter type 'void Function([bool])'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
m(T t) {}
|
||||
}
|
||||
f(A<String> a) {
|
||||
a.m(1);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 50, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_named() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f({String p = ''}) {}
|
||||
main() {
|
||||
f(p: 42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 38, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f([String p = '']) {}
|
||||
main() {
|
||||
f(42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 35, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_required() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(String p) {}
|
||||
main() {
|
||||
f(42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 28, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_typedef_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A<T>(T p);
|
||||
f(A<int> a) {
|
||||
a('1');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 37, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_typedef_local() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A(int p);
|
||||
A getA() => throw '';
|
||||
main() {
|
||||
A a = getA();
|
||||
a('1');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 69, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_invocation_typedef_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A(int p);
|
||||
f(A a) {
|
||||
a('1');
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 31, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_map_indexGet() async {
|
||||
// Any type may be passed to Map.operator[].
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
Map<int, int> m = <int, int>{};
|
||||
m['x'];
|
||||
@@ -666,94 +627,78 @@ main() {
|
||||
|
||||
test_map_indexSet() async {
|
||||
// The type passed to Map.operator[]= must match the key type.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
Map<int, int> m = <int, int>{};
|
||||
m['x'] = 0;
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 47, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_map_indexSet_ifNull() async {
|
||||
// The type passed to Map.operator[]= must match the key type.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
Map<int, int> m = <int, int>{};
|
||||
m['x'] ??= 0;
|
||||
// ^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 47, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_new_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
A(T p) {}
|
||||
}
|
||||
main() {
|
||||
new A<String>(42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 52, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_new_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([String p = '']) {}
|
||||
}
|
||||
main() {
|
||||
new A(42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 53, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_new_required() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(String p) {}
|
||||
}
|
||||
main() {
|
||||
new A(42);
|
||||
}''',
|
||||
[error(diag.argumentTypeNotAssignable, 46, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type 'String'.
|
||||
}''');
|
||||
}
|
||||
|
||||
void test_recordType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int a, int b) r) {}
|
||||
|
||||
void g() {
|
||||
f((a: 1, b: 2));
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type '({int a, int b})' can't be assigned to the parameter type '(int, int)'. Expected 2 positional arguments, but got 0 instead.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.argumentTypeNotAssignable,
|
||||
44,
|
||||
12,
|
||||
messageContains: [
|
||||
'Expected 2 positional arguments, but got 0 instead.',
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_recordType_namedArguments() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A = ({
|
||||
int b,
|
||||
int c,
|
||||
@@ -763,22 +708,14 @@ void f(A a){print(a);}
|
||||
|
||||
main() {
|
||||
f((bb:2, c:3));
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type '({int bb, int c})' can't be assigned to the parameter type 'A'. Unexpected named argument `bb` with type `int`.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.argumentTypeNotAssignable,
|
||||
74,
|
||||
11,
|
||||
messageContains: ['Unexpected named argument `bb` with type `int`.'],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_recordType_namedArguments_missing() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A = ({
|
||||
int b,
|
||||
int c,
|
||||
@@ -788,22 +725,14 @@ void f(A a){print(a);}
|
||||
|
||||
main() {
|
||||
f((b:2));
|
||||
// ^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type '({int b})' can't be assigned to the parameter type 'A'. Expected 2 named arguments, but got 1 instead.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.argumentTypeNotAssignable,
|
||||
74,
|
||||
5,
|
||||
messageContains: ['Expected 2 named arguments, but got 1 instead.'],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_recordType_positionalArguments() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A = (
|
||||
int b,
|
||||
int c,
|
||||
@@ -813,19 +742,10 @@ void f(A a){print(a);}
|
||||
|
||||
main() {
|
||||
f((3, 2, 1));
|
||||
// ^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type '(int, int, int)' can't be assigned to the parameter type 'A'. Expected 2 positional arguments, but got 3 instead.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.argumentTypeNotAssignable,
|
||||
72,
|
||||
9,
|
||||
messageContains: [
|
||||
'Expected 2 positional arguments, but got 3 instead.',
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
|
||||
+156
-187
@@ -2,10 +2,10 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -24,6 +24,7 @@ main() {
|
||||
defineReflectiveTests(
|
||||
ArgumentTypeNotAssignableToErrorHandler_StreamSubscriptionOnErrorTest,
|
||||
);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ main() {
|
||||
class ArgumentTypeNotAssignableToErrorHandler_FutureCatchErrorTest
|
||||
extends PubPackageResolutionTest {
|
||||
void test_firstParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(dynamic a) callback) {
|
||||
future.catchError(callback);
|
||||
}
|
||||
@@ -39,18 +40,17 @@ void f(Future<int> future, Future<int> Function(dynamic a) callback) {
|
||||
}
|
||||
|
||||
void test_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function({Object a}) callback) {
|
||||
future.catchError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function({Object a})' can't be assigned to the parameter type 'FutureOr<int> Function(Object)' or 'FutureOr<int> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 92, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_firstParameterIsOptional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function([Object a]) callback) {
|
||||
future.catchError(callback);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ void f(Future<int> future, Future<int> Function([Object a]) callback) {
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((dynamic a) {});
|
||||
}
|
||||
@@ -66,7 +66,7 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsImplicit() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((a) {});
|
||||
}
|
||||
@@ -74,18 +74,17 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError(({Object a = 1}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 50, 19)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNullableObject() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object? a) {});
|
||||
}
|
||||
@@ -93,7 +92,7 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsOptional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError(([Object a = 1]) {});
|
||||
}
|
||||
@@ -101,7 +100,7 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsUntyped() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((a) {});
|
||||
}
|
||||
@@ -109,18 +108,17 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_noParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError(() {});
|
||||
// ^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 50, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object a, dynamic b) {});
|
||||
}
|
||||
@@ -128,7 +126,7 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsImplicit() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object a, b) {});
|
||||
}
|
||||
@@ -136,18 +134,17 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object a, {required StackTrace b}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {required StackTrace b})' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 50, 38)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNullableStackTrace() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object a, StackTrace? b) {});
|
||||
}
|
||||
@@ -155,7 +152,7 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsUntyped() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object a, b) {});
|
||||
}
|
||||
@@ -163,51 +160,47 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_tooManyParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((a, b, c) {});
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(dynamic, dynamic, dynamic)' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 50, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_wrongFirstParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((String a) {});
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 50, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_wrongSecondParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((Object a, String b) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, String)' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 50, 23)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_noParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function() callback) {
|
||||
future.catchError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function()' can't be assigned to the parameter type 'FutureOr<int> Function(Object)' or 'FutureOr<int> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 82, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_okType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(Object, StackTrace) callback) {
|
||||
future.catchError(callback);
|
||||
}
|
||||
@@ -215,7 +208,7 @@ void f(Future<int> future, Future<int> Function(Object, StackTrace) callback) {
|
||||
}
|
||||
|
||||
void test_secondParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(Object a, dynamic b) callback) {
|
||||
future.catchError(callback);
|
||||
}
|
||||
@@ -223,47 +216,43 @@ void f(Future<int> future, Future<int> Function(Object a, dynamic b) callback) {
|
||||
}
|
||||
|
||||
void test_secondParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(Object a, {StackTrace b}) callback) {
|
||||
future.catchError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function(Object, {StackTrace b})' can't be assigned to the parameter type 'FutureOr<int> Function(Object)' or 'FutureOr<int> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 106, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_tooManyParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(int, int, int) callback) {
|
||||
future.catchError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function(int, int, int)' can't be assigned to the parameter type 'FutureOr<int> Function(Object)' or 'FutureOr<int> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 95, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_wrongFirstParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(String) callback) {
|
||||
future.catchError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function(String)' can't be assigned to the parameter type 'FutureOr<int> Function(Object)' or 'FutureOr<int> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 88, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_wrongSecondParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(Object, String) callback) {
|
||||
future.catchError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function(Object, String)' can't be assigned to the parameter type 'FutureOr<int> Function(Object)' or 'FutureOr<int> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 96, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +260,7 @@ void f(Future<int> future, Future<int> Function(Object, String) callback) {
|
||||
class ArgumentTypeNotAssignableToErrorHandler_FutureThenTest
|
||||
extends PubPackageResolutionTest {
|
||||
void test_firstParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, void Function(dynamic a) callback) {
|
||||
future.then((_) {}, onError: callback);
|
||||
}
|
||||
@@ -282,29 +271,27 @@ void f(Future<void> future, void Function(dynamic a) callback) {
|
||||
// `void` must be specified explicitly on `then()`; the inferred type from
|
||||
// `() {}` would otherwise be `Null`, and `void` (or `Future<void>`, or
|
||||
// `Future<int>`) would be an illegal return type for the `onError` handler.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, Future<void> Function({Object a}) callback) {
|
||||
future.then<void>((_) {}, onError: callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<void> Function({Object a})' can't be assigned to the parameter type 'FutureOr<void> Function(Object)' or 'FutureOr<void> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 111, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then((_) {}, onError: ({Object a = 1}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'FutureOr<Null> Function(Object)' or 'FutureOr<Null> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 61, 19)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNullableObject() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then((_) {}, onError: (Object? a) {});
|
||||
}
|
||||
@@ -312,29 +299,27 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_noParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then((_) {}, onError: () {});
|
||||
// ^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'FutureOr<Null> Function(Object)' or 'FutureOr<Null> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 61, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then((_) {}, onError: (Object a, {StackTrace? b}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'FutureOr<Null> Function(Object)' or 'FutureOr<Null> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 61, 30)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNullableStackTrace() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then((_) {}, onError: (Object a, StackTrace? b) {});
|
||||
}
|
||||
@@ -342,18 +327,17 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
void test_functionExpression_wrongFirstParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then((_) {}, onError: (String a) {});
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'FutureOr<Null> Function(Object)' or 'FutureOr<Null> Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 61, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, Function callback) {
|
||||
future.then((_) {}, onError: callback);
|
||||
}
|
||||
@@ -365,7 +349,7 @@ void f(Future<void> future, Function callback) {
|
||||
class ArgumentTypeNotAssignableToErrorHandler_StreamHandleErrorTest
|
||||
extends PubPackageResolutionTest {
|
||||
void test_firstParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream, void Function(dynamic a) callback) {
|
||||
stream.handleError(callback);
|
||||
}
|
||||
@@ -373,29 +357,27 @@ void f(Stream<void> stream, void Function(dynamic a) callback) {
|
||||
}
|
||||
|
||||
void test_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream, Future<int> Function({Object a}) callback) {
|
||||
stream.handleError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 94, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.handleError(({Object a = 1}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 51, 19)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNullableObject() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.handleError((Object? a) {});
|
||||
}
|
||||
@@ -403,29 +385,27 @@ void f(Stream<void> stream) {
|
||||
}
|
||||
|
||||
void test_functionExpression_noParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.handleError(() {});
|
||||
// ^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 51, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.handleError((Object a, {StackTrace? b}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 51, 30)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNullableStackTrace() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.handleError((Object a, StackTrace? b) {});
|
||||
}
|
||||
@@ -433,14 +413,13 @@ void f(Stream<void> stream) {
|
||||
}
|
||||
|
||||
void test_functionExpression_wrongFirstParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.handleError((String a) {});
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 51, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,7 +427,7 @@ void f(Stream<void> stream) {
|
||||
class ArgumentTypeNotAssignableToErrorHandler_StreamListenTest
|
||||
extends PubPackageResolutionTest {
|
||||
void test_firstParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream, void Function(dynamic a) callback) {
|
||||
stream.listen((_) {}, onError: callback);
|
||||
}
|
||||
@@ -456,29 +435,27 @@ void f(Stream<void> stream, void Function(dynamic a) callback) {
|
||||
}
|
||||
|
||||
void test_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream, Future<int> Function({Object a}) callback) {
|
||||
stream.listen((_) {}, onError: callback);
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 97, 17)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.listen((_) {}, onError: ({Object a = 1}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 54, 28)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNullableObject() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.listen((_) {}, onError: (Object? a) {});
|
||||
}
|
||||
@@ -486,29 +463,27 @@ void f(Stream<void> stream) {
|
||||
}
|
||||
|
||||
void test_functionExpression_noParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.listen((_) {}, onError: () {});
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 54, 14)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.listen((_) {}, onError: (Object a, {StackTrace? b}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 54, 39)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNullableStackTrace() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.listen((_) {}, onError: (Object a, StackTrace? b) {});
|
||||
}
|
||||
@@ -516,14 +491,13 @@ void f(Stream<void> stream) {
|
||||
}
|
||||
|
||||
void test_functionExpression_wrongFirstParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Stream<void> stream) {
|
||||
stream.listen((_) {}, onError: (String a) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 54, 22)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,7 +505,7 @@ void f(Stream<void> stream) {
|
||||
class ArgumentTypeNotAssignableToErrorHandler_StreamSubscriptionOnErrorTest
|
||||
extends PubPackageResolutionTest {
|
||||
void test_firstParameterIsDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(
|
||||
StreamSubscription<void> subscription, void Function(dynamic a) callback) {
|
||||
@@ -541,33 +515,31 @@ void f(
|
||||
}
|
||||
|
||||
void test_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(
|
||||
StreamSubscription<void> subscription,
|
||||
Future<int> Function({Object a}) callback) {
|
||||
subscription.onError(callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Future<int> Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 144, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(StreamSubscription<void> subscription) {
|
||||
subscription.onError(({Object a = 1}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function({Object a})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 92, 19)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_firstParameterIsNullableObject() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(StreamSubscription<void> subscription) {
|
||||
subscription.onError((Object? a) {});
|
||||
@@ -576,31 +548,29 @@ void f(StreamSubscription<void> subscription) {
|
||||
}
|
||||
|
||||
void test_functionExpression_noParameters() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(StreamSubscription<void> subscription) {
|
||||
subscription.onError(() {});
|
||||
// ^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function()' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 92, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(StreamSubscription<void> subscription) {
|
||||
subscription.onError((Object a, {StackTrace? b}) {});
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(Object, {StackTrace? b})' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 92, 30)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
void test_functionExpression_secondParameterIsNullableStackTrace() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(StreamSubscription<void> subscription) {
|
||||
subscription.onError((Object a, StackTrace? b) {});
|
||||
@@ -609,14 +579,13 @@ void f(StreamSubscription<void> subscription) {
|
||||
}
|
||||
|
||||
void test_functionExpression_wrongFirstParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(StreamSubscription<void> subscription) {
|
||||
subscription.onError((String a) {});
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.argumentTypeNotAssignableToErrorHandler] The argument type 'Null Function(String)' can't be assigned to the parameter type 'void Function(Object)' or 'void Function(Object, StackTrace)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignableToErrorHandler, 92, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,57 +2,55 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssertInRedirectingConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssertInRedirectingConstructorTest extends PubPackageResolutionTest {
|
||||
test_class_primary_assertBeforeRedirection() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
A.named() : this(0);
|
||||
this : assert(x > 0), this.named();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 64, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_primary_redirectionBeforeAssert() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
A.named() : this(0);
|
||||
this : this.named(), assert(x > 0);
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 49, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_typeName_assertBeforeRedirection() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int x) : assert(x > 0), this.name();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer.
|
||||
A.name() {}
|
||||
}
|
||||
''',
|
||||
[error(diag.assertInRedirectingConstructor, 23, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_typeName_justAssert() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int x) : assert(x > 0);
|
||||
A.name() {}
|
||||
@@ -61,7 +59,7 @@ class A {
|
||||
}
|
||||
|
||||
test_class_typeName_justRedirection() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int x) : this.name();
|
||||
A.name() {}
|
||||
@@ -70,77 +68,70 @@ class A {
|
||||
}
|
||||
|
||||
test_class_typeName_redirectionBeforeAssert() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int x) : this.name(), assert(x > 0);
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer.
|
||||
A.name() {}
|
||||
}
|
||||
''',
|
||||
[error(diag.assertInRedirectingConstructor, 36, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_primary_assertBeforeRedirection() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(int x) {
|
||||
v(0);
|
||||
const E.named() : this(0);
|
||||
// ^^^^^^^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
this : assert(x > -1), this.named();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstantConstructor, 32, 7),
|
||||
error(diag.primaryConstructorCannotRedirect, 78, 4),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_primary_redirectionBeforeAssert() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(int x) {
|
||||
v(0);
|
||||
const E.named() : this(0);
|
||||
// ^^^^^^^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
this : this.named(), assert(x > -1);
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstantConstructor, 32, 7),
|
||||
error(diag.primaryConstructorCannotRedirect, 62, 4),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_redirectionBeforeAssert() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(42);
|
||||
const E(int x) : this.name(), assert(x > 0);
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer.
|
||||
const E.name();
|
||||
}
|
||||
''',
|
||||
[error(diag.assertInRedirectingConstructor, 50, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_typeName_assertBeforeRedirection() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(42);
|
||||
const E(int x) : assert(x > 0), this.name();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.assertInRedirectingConstructor] A redirecting constructor can't have an 'assert' initializer.
|
||||
const E.name();
|
||||
}
|
||||
''',
|
||||
[error(diag.assertInRedirectingConstructor, 37, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_typeName_justAssert() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(42);
|
||||
const E(int x) : assert(x > 0);
|
||||
@@ -149,7 +140,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_enum_typeName_justRedirection() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(0);
|
||||
const E(int x) : this.name();
|
||||
|
||||
@@ -6,11 +6,13 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentOfDoNotStoreTest);
|
||||
defineReflectiveTests(AssignmentOfDoNotStoreInTestsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,7 +28,7 @@ class AssignmentOfDoNotStoreInTestsTest extends PubPackageResolutionTest {
|
||||
// Code that is in a test dir (the default for PubPackageResolutionTests)
|
||||
// should not trigger the hint.
|
||||
// (See:https://github.com/dart-lang/sdk/issues/45594)
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -54,7 +56,7 @@ class AssignmentOfDoNotStoreTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_cascadeExpression_assignment() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = A()..f = v;
|
||||
@@ -69,8 +71,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_class_containingInstanceGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@doNotStore
|
||||
class A {
|
||||
@@ -78,14 +79,13 @@ class A {
|
||||
}
|
||||
|
||||
String f = A().v;
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 91, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_containingInstanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@doNotStore
|
||||
class A {
|
||||
@@ -93,14 +93,13 @@ class A {
|
||||
}
|
||||
|
||||
String f = A().v();
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 89, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_containingStaticGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@doNotStore
|
||||
class A {
|
||||
@@ -108,14 +107,13 @@ class A {
|
||||
}
|
||||
|
||||
String f = A.v;
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 98, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_containingStaticMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@doNotStore
|
||||
class A {
|
||||
@@ -123,14 +121,13 @@ class A {
|
||||
}
|
||||
|
||||
String f = A.v();
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 96, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classMemberGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -140,17 +137,14 @@ class A {
|
||||
|
||||
class B {
|
||||
String f = A().v;
|
||||
// ^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentOfDoNotStore, 106, 5, messageContains: ["'v'"]),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_classStaticGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -160,14 +154,14 @@ class A {
|
||||
|
||||
class B {
|
||||
String f = A.v;
|
||||
// ^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 113, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionAssignment() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -180,8 +174,7 @@ class C {
|
||||
}
|
||||
|
||||
test_functionReturnValue() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -189,14 +182,14 @@ String getV() => '';
|
||||
|
||||
class A {
|
||||
final f = getV();
|
||||
// ^^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'getV' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 90, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localVariable_assignment() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -211,7 +204,7 @@ void f() {
|
||||
}
|
||||
|
||||
test_localVariable_declaration() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -225,8 +218,7 @@ void f() {
|
||||
}
|
||||
|
||||
test_methodReturnValue() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -236,15 +228,14 @@ class A {
|
||||
|
||||
class B {
|
||||
final f = A().getV();
|
||||
// ^^^^^^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'getV' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 106, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_containingInstanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@doNotStore
|
||||
mixin M {
|
||||
@@ -254,14 +245,14 @@ mixin M {
|
||||
abstract class A {
|
||||
M get m;
|
||||
late String f = m.v();
|
||||
// ^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 126, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_tearOff() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -274,8 +265,7 @@ class A {
|
||||
}
|
||||
|
||||
test_topLevelGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -283,15 +273,14 @@ String get v => '';
|
||||
|
||||
class A {
|
||||
final f = v;
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 89, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelGetter_binaryExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -299,13 +288,12 @@ String? get v => '';
|
||||
|
||||
class A {
|
||||
final f = v ?? v;
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentOfDoNotStore, 90, 1),
|
||||
error(diag.assignmentOfDoNotStore, 95, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
@FailingTest(reason: 'Not yet implemented')
|
||||
@@ -324,75 +312,65 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_assignment_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
String top = A().f;
|
||||
// ^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'f' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
|
||||
class A{
|
||||
@doNotStore
|
||||
String get f => '';
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentOfDoNotStore, 47, 5, messageContains: ["'f'"]),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_assignment_functionExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
String get _v => '';
|
||||
|
||||
var c = () => _v;
|
||||
// ^^
|
||||
// [diag.assignmentOfDoNotStore] '_v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
|
||||
String v = c();
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 82, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_assignment_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
String top = v;
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
|
||||
@doNotStore
|
||||
String get v => '';
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentOfDoNotStore, 47, 1, messageContains: ["'v'"]),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_assignment_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
String top = A().v();
|
||||
// ^^^^^^^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
|
||||
class A{
|
||||
@doNotStore
|
||||
String v() => '';
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentOfDoNotStore, 47, 7, messageContains: ["'v'"]),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_cascadeExpression_propertyAccess() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = A()..v;
|
||||
@@ -420,22 +398,20 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_conditionalExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
final f = 1 == 2 ? v : v;
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
|
||||
@doNotStore
|
||||
String get v => '';
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentOfDoNotStore, 65, 1),
|
||||
error(diag.assignmentOfDoNotStore, 69, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
@FailingTest(reason: 'Not yet implemented')
|
||||
@@ -456,7 +432,7 @@ class A {
|
||||
}
|
||||
|
||||
test_topLevelVariable_forElement() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = [for (var _ in [1]) v];
|
||||
@@ -467,7 +443,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_ifElement() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = [if (true) v];
|
||||
@@ -478,7 +454,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_instanceCreationExpression() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -493,7 +469,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_isExpression() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = v is int;
|
||||
@@ -513,20 +489,19 @@ import 'package:meta/meta.dart';
|
||||
final v = '';
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'library.dart';
|
||||
|
||||
class A {
|
||||
final f = v;
|
||||
// ^
|
||||
// [diag.assignmentOfDoNotStore] 'v' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentOfDoNotStore, 46, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_listLiteral() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = [v];
|
||||
@@ -537,7 +512,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_mapLiteral_key() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = {v: 1};
|
||||
@@ -548,7 +523,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_mapLiteral_value() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = {1: v};
|
||||
@@ -559,7 +534,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_nonAssignment_argToFunctionCall() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
var top = print(v);
|
||||
@@ -585,7 +560,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_nullAwareElement() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = [?v];
|
||||
@@ -596,7 +571,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_prefixExpression() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = -v;
|
||||
@@ -607,7 +582,7 @@ int get v => 1;
|
||||
}
|
||||
|
||||
test_topLevelVariable_recordLiteral_namedField() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = (a: v, );
|
||||
@@ -618,7 +593,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_recordLiteral_positionalField() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = (v, );
|
||||
@@ -629,7 +604,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_setLiteral() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = {v};
|
||||
@@ -640,7 +615,7 @@ String get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_spreadElement() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = [...v];
|
||||
@@ -669,7 +644,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_switchExpression_condition() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = switch (v) {
|
||||
@@ -683,7 +658,7 @@ String? get v => '';
|
||||
}
|
||||
|
||||
test_topLevelVariable_throwExpression() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final f = throw v;
|
||||
|
||||
@@ -2,83 +2,77 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToConstTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToConstTest extends PubPackageResolutionTest {
|
||||
test_instanceVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static const v = 0;
|
||||
}
|
||||
f() {
|
||||
A.v = 1;
|
||||
}''',
|
||||
[error(diag.assignmentToConst, 44, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_instanceVariable_plusEq() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static const v = 0;
|
||||
}
|
||||
f() {
|
||||
A.v += 1;
|
||||
}''',
|
||||
[error(diag.assignmentToConst, 44, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_localVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
const x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x = 1;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToConst, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_localVariable_inForEach() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
const x = 0;
|
||||
for (x in <int>[1, 2]) {
|
||||
// ^
|
||||
// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization.
|
||||
print(x);
|
||||
}
|
||||
}''',
|
||||
[error(diag.assignmentToConst, 28, 1)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_localVariable_plusEq() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
const x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x += 1;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToConst, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToConst] Constant variables can't be assigned a value after initialization.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,83 +2,77 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToFinalLocalTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToFinalLocalTest extends PubPackageResolutionTest {
|
||||
test_localVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x = 1;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_localVariable_forEach() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final i;
|
||||
for (i in [1, 2, 3]) {
|
||||
// ^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'i' can only be set once.
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToFinalLocal, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localVariable_inForEach() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
for (x in <int>[1, 2]) {
|
||||
// ^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
print(x);
|
||||
}
|
||||
}''',
|
||||
[error(diag.assignmentToFinalLocal, 28, 1)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_localVariable_plusEq() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x += 1;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
f(final x) {
|
||||
x = 1;
|
||||
}''',
|
||||
[error(diag.assignmentToFinalLocal, 31, 1)],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
/// See `10.6.1 Generative Constructors`.
|
||||
@@ -92,129 +86,114 @@ f(final x) {
|
||||
/// Note that it says 'final local variable', regardless whether the instance
|
||||
/// variable is final.
|
||||
test_parameter_fieldFormal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int x;
|
||||
final Object y;
|
||||
A(this.x) : y = (() {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToFinalLocal, 65, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_superFormal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int a);
|
||||
}
|
||||
class B extends A {
|
||||
var x;
|
||||
B(super.a) : x = (() { a = 0; });
|
||||
// ^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'a' can only be set once.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToFinalLocal, 78, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_patternVariable_final() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
final (a) = 0;
|
||||
a = 1;
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'a' can only be set once.
|
||||
a;
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToFinalLocal, 30, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_postfixMinusMinus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x--;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_postfixPlusPlus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x++;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_prefixMinusMinus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
--x;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 25, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_prefixPlusPlus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
++x;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 25, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_suffixMinusMinus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x--;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_suffixPlusPlus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
final x = 0;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'x' isn't used.
|
||||
x++;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 14, 1),
|
||||
error(diag.assignmentToFinalLocal, 23, 1),
|
||||
],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFinalLocal] The final variable 'x' can only be set once.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,131 +2,132 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToFinalNoSetterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToFinalNoSetterTest extends PubPackageResolutionTest {
|
||||
test_prefixedIdentifier_class_instanceGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get x => 0;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
a.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
a.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
++a.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
a.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinalNoSetter, 49, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 60, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 74, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 81, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_class_instanceGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get x => 0;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
(a).x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
(a).x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
++(a).x;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
(a).x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinalNoSetter, 51, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 64, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 80, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 89, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_extension_instanceGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {
|
||||
int get x => 0;
|
||||
}
|
||||
|
||||
void f() {
|
||||
0.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'.
|
||||
0.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'.
|
||||
++0.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'.
|
||||
0.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'E'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinalNoSetter, 57, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 68, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 82, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 89, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_class_instanceGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get x => 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinalNoSetter, 46, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 57, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 71, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 78, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_class_staticGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int get x => 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinalNoSetter] There isn't a setter named 'x' in class 'A'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinalNoSetter, 53, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 64, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 78, 1),
|
||||
error(diag.assignmentToFinalNoSetter, 85, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToFinalTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToFinalTest extends PubPackageResolutionTest {
|
||||
test_prefixedIdentifier_instanceField() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
var x = 0;
|
||||
}
|
||||
@@ -31,7 +32,7 @@ void f(A a) {
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_abstract() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
}
|
||||
@@ -46,30 +47,30 @@ void f(A a) {
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_abstractFinal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
a.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++a.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 64, 1),
|
||||
error(diag.assignmentToFinal, 75, 1),
|
||||
error(diag.assignmentToFinal, 89, 1),
|
||||
error(diag.assignmentToFinal, 96, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_external() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
external int x;
|
||||
}
|
||||
@@ -84,53 +85,53 @@ void f(A a) {
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_externalFinal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
external final int x;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
a.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++a.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 64, 1),
|
||||
error(diag.assignmentToFinal, 75, 1),
|
||||
error(diag.assignmentToFinal, 89, 1),
|
||||
error(diag.assignmentToFinal, 96, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_final() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
final x = 0;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
a.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++a.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 46, 1),
|
||||
error(diag.assignmentToFinal, 57, 1),
|
||||
error(diag.assignmentToFinal, 71, 1),
|
||||
error(diag.assignmentToFinal, 78, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_lateFinal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
late final int x;
|
||||
}
|
||||
@@ -145,53 +146,53 @@ void f(A a) {
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceField_lateFinal_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
late final int x = 0;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
a.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++a.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
a.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 64, 1),
|
||||
error(diag.assignmentToFinal, 75, 1),
|
||||
error(diag.assignmentToFinal, 89, 1),
|
||||
error(diag.assignmentToFinal, 96, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_staticField_externalFinal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
external static final int x;
|
||||
}
|
||||
|
||||
void f() {
|
||||
A.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
A.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++A.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
A.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 68, 1),
|
||||
error(diag.assignmentToFinal, 79, 1),
|
||||
error(diag.assignmentToFinal, 93, 1),
|
||||
error(diag.assignmentToFinal, 100, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_staticField_lateFinal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
static late final int x;
|
||||
}
|
||||
@@ -206,30 +207,30 @@ void f() {
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_staticField_lateFinal_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
static late final int x = 0;
|
||||
}
|
||||
|
||||
void f() {
|
||||
A.x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
A.x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++A.x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
A.x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 68, 1),
|
||||
error(diag.assignmentToFinal, 79, 1),
|
||||
error(diag.assignmentToFinal, 93, 1),
|
||||
error(diag.assignmentToFinal, 100, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_instanceField_lateFinal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
late final int x;
|
||||
}
|
||||
@@ -244,31 +245,30 @@ void f(A a) {
|
||||
}
|
||||
|
||||
test_propertyAccess_instanceField_lateFinal_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
late final int x = 0;
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
(a).x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
(a).x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++(a).x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
(a).x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 66, 1),
|
||||
error(diag.assignmentToFinal, 79, 1),
|
||||
error(diag.assignmentToFinal, 95, 1),
|
||||
error(diag.assignmentToFinal, 104, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_inheritedSetter_shadowedBy_topLevelGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void set foo(int _) {}
|
||||
}
|
||||
@@ -278,15 +278,15 @@ int get foo => 0;
|
||||
class B extends A {
|
||||
void bar() {
|
||||
foo = 0;
|
||||
// ^^^
|
||||
// [diag.assignmentToFinal] 'foo' can't be used as a setter because it's final.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToFinal, 96, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_instanceField_lateFinal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
late final int x;
|
||||
|
||||
@@ -301,30 +301,30 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_simpleIdentifier_instanceField_lateFinal_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
late final int x = 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 61, 1),
|
||||
error(diag.assignmentToFinal, 72, 1),
|
||||
error(diag.assignmentToFinal, 86, 1),
|
||||
error(diag.assignmentToFinal, 93, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_staticField_lateFinal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
static late final int x;
|
||||
|
||||
@@ -339,51 +339,51 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_simpleIdentifier_staticField_lateFinal_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
static late final int x = 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x += 0;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x++;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 68, 1),
|
||||
error(diag.assignmentToFinal, 79, 1),
|
||||
error(diag.assignmentToFinal, 93, 1),
|
||||
error(diag.assignmentToFinal, 100, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int get x => 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x += 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x++;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 30, 1),
|
||||
error(diag.assignmentToFinal, 39, 1),
|
||||
error(diag.assignmentToFinal, 51, 1),
|
||||
error(diag.assignmentToFinal, 56, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelVariable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var x = 0;
|
||||
|
||||
void f() {
|
||||
@@ -396,7 +396,7 @@ void f() {
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelVariable_external() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
external int x;
|
||||
|
||||
void f() {
|
||||
@@ -409,49 +409,49 @@ void f() {
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelVariable_externalFinal() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
external final x;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x += 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x++;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 32, 1),
|
||||
error(diag.assignmentToFinal, 41, 1),
|
||||
error(diag.assignmentToFinal, 53, 1),
|
||||
error(diag.assignmentToFinal, 58, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelVariable_final() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final x = 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x += 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x++;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 27, 1),
|
||||
error(diag.assignmentToFinal, 36, 1),
|
||||
error(diag.assignmentToFinal, 48, 1),
|
||||
error(diag.assignmentToFinal, 53, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelVariable_lateFinal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
late final int x;
|
||||
|
||||
void f() {
|
||||
@@ -464,23 +464,23 @@ void f() {
|
||||
}
|
||||
|
||||
test_simpleIdentifier_topLevelVariable_lateFinal_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
late final int x = 0;
|
||||
|
||||
void f() {
|
||||
x = 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x += 0;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
++x;
|
||||
// ^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
x++;
|
||||
//^
|
||||
// [diag.assignmentToFinal] 'x' can't be used as a setter because it's final.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToFinal, 36, 1),
|
||||
error(diag.assignmentToFinal, 45, 1),
|
||||
error(diag.assignmentToFinal, 57, 1),
|
||||
error(diag.assignmentToFinal, 62, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToFunctionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToFunctionTest extends PubPackageResolutionTest {
|
||||
test_function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {}
|
||||
main() {
|
||||
f = null;
|
||||
}''',
|
||||
[error(diag.assignmentToFunction, 18, 1)],
|
||||
);
|
||||
//^
|
||||
// [diag.assignmentToFunction] Functions can't be assigned a value.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToMethodTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToMethodTest extends PubPackageResolutionTest {
|
||||
test_instance_extendedHasMethod_extensionHasSetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -28,69 +28,69 @@ extension E on C {
|
||||
|
||||
void f(C c) {
|
||||
c.foo = 0;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
c.foo += 1;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
c.foo++;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
--c.foo;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToMethod, 94, 3),
|
||||
error(diag.assignmentToMethod, 107, 3),
|
||||
error(diag.assignmentToMethod, 121, 3),
|
||||
error(diag.assignmentToMethod, 134, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixedIdentifier_instanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
a.foo = 0;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
a.foo += 1;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
a.foo++;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
++a.foo;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToMethod, 47, 3),
|
||||
error(diag.assignmentToMethod, 60, 3),
|
||||
error(diag.assignmentToMethod, 74, 3),
|
||||
error(diag.assignmentToMethod, 87, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_instanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
|
||||
void f(A a) {
|
||||
(a).foo = 0;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
(a).foo += 1;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
(a).foo++;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
++(a).foo;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToMethod, 49, 3),
|
||||
error(diag.assignmentToMethod, 64, 3),
|
||||
error(diag.assignmentToMethod, 80, 3),
|
||||
error(diag.assignmentToMethod, 95, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_this_extendedHasMethod_extensionHasSetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -100,10 +100,10 @@ extension E on C {
|
||||
|
||||
f() {
|
||||
this.foo = 0;
|
||||
// ^^^
|
||||
// [diag.assignmentToMethod] Methods can't be assigned a value.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToMethod, 91, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+87
-108
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToPrimaryConstructorParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,169 +18,153 @@ main() {
|
||||
class AssignmentToPrimaryConstructorParameterTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_fieldInitializer_late() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
late int y = x = 0;
|
||||
// ^
|
||||
// [diag.undefinedIdentifier] Undefined name 'x'.
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedIdentifier, 32, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y = x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_closure() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
var f = () {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_nullAware() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int? x) {
|
||||
int y = x ??= 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 28, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_list() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
List<int> y = [x] = [2];
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_logicalAnd() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x, int z) {
|
||||
int y = (x && z) = 2;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToPrimaryConstructorParameter, 35, 1),
|
||||
error(diag.assignmentToPrimaryConstructorParameter, 40, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_map() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
Map<int?, int> y = {null: x} = {null: 2};
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 45, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_nullAssert() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int? x) {
|
||||
int y = (x!) = 2;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
// ^
|
||||
// [diag.unnecessaryNullAssertPattern] The null-assert pattern will have no effect because the matched type isn't nullable.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.assignmentToPrimaryConstructorParameter, 29, 1),
|
||||
error(diag.unnecessaryNullAssertPattern, 30, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_object() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
Object y = int(sign: x) = 2;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_parenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y = (x) = 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 28, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_pattern_record() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
(int, {bool name}) y = (x, name: _) = (2, name: true);
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_plusEq() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y = x += 1;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_postfix() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y = x++;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldInitializer_notLate_prefix() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y = ++x;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 29, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_body() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
this {
|
||||
x = 0;
|
||||
@@ -189,76 +174,70 @@ class A(int x) {
|
||||
}
|
||||
|
||||
test_primaryConstructor_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y;
|
||||
this : y = x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 39, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_initializer_closure() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
var f;
|
||||
this : f = (() {
|
||||
x = 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 49, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_initializer_nullAware() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int? x) {
|
||||
int y;
|
||||
this : y = x ??= 0;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_initializer_plusEq() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y;
|
||||
this : y = x += 1;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 39, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_initializer_postfix() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y;
|
||||
this : y = x++;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 39, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_initializer_prefix() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A(int x) {
|
||||
int y;
|
||||
this : y = ++x;
|
||||
// ^
|
||||
// [diag.assignmentToPrimaryConstructorParameter] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToPrimaryConstructorParameter, 41, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,89 +2,84 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AssignmentToTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AssignmentToTypeTest extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {}
|
||||
main() {
|
||||
C = null;
|
||||
//^
|
||||
// [diag.assignmentToType] Types can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToType, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
dynamic = 1;
|
||||
//^^^^^^^
|
||||
// [diag.assignmentToType] Types can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToType, 13, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E { e }
|
||||
main() {
|
||||
E = null;
|
||||
//^
|
||||
// [diag.assignmentToType] Types can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToType, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_functionType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef void F();
|
||||
main() {
|
||||
F = null;
|
||||
//^
|
||||
// [diag.assignmentToType] Types can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToType, 29, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_interfaceType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F = List<int>;
|
||||
|
||||
void f() {
|
||||
F = null;
|
||||
//^
|
||||
// [diag.assignmentToType] Types can't be assigned a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToType, 37, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {
|
||||
f() {
|
||||
T = null;
|
||||
// ^
|
||||
// [diag.assignmentToType] Types can't be assigned a value.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.assignmentToType, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,30 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AsyncForInWrongContextTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AsyncForInWrongContextTest extends PubPackageResolutionTest {
|
||||
test_syncFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(list) {
|
||||
await for (var e in list) {
|
||||
//^^^^^
|
||||
// [diag.asyncForInWrongContext] The async for-in loop can only be used in an async function.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncForInWrongContext, 12, 5),
|
||||
error(diag.unusedLocalVariable, 27, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,113 +2,95 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AsyncKeywordUsedAsIdentifierTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AsyncKeywordUsedAsIdentifierTest extends PubPackageResolutionTest {
|
||||
test_async_async() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() async {
|
||||
int async;
|
||||
// ^^^^^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'async' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 32, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_await_async() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async {
|
||||
var await = 1;
|
||||
// ^^^^^
|
||||
// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function.
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncKeywordUsedAsIdentifier, 18, 5),
|
||||
error(diag.unusedLocalVariable, 18, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_await_asyncStar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async* {
|
||||
var await = 1;
|
||||
// ^^^^^
|
||||
// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function.
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncKeywordUsedAsIdentifier, 19, 5),
|
||||
error(diag.unusedLocalVariable, 19, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_await_syncStar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() sync* {
|
||||
var await = 1;
|
||||
// ^^^^^
|
||||
// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function.
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'await' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncKeywordUsedAsIdentifier, 18, 5),
|
||||
error(diag.unusedLocalVariable, 18, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_yield_async() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async {
|
||||
var yield = 1;
|
||||
// ^^^^^
|
||||
// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function.
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncKeywordUsedAsIdentifier, 18, 5),
|
||||
error(diag.unusedLocalVariable, 18, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_yield_asyncStar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async* {
|
||||
var yield = 1;
|
||||
// ^^^^^
|
||||
// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function.
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncKeywordUsedAsIdentifier, 19, 5),
|
||||
error(diag.unusedLocalVariable, 19, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_yield_syncStar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() sync* {
|
||||
var yield = 1;
|
||||
// ^^^^^
|
||||
// [diag.asyncKeywordUsedAsIdentifier] The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function.
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'yield' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.asyncKeywordUsedAsIdentifier, 18, 5),
|
||||
error(diag.unusedLocalVariable, 18, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+213
-441
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationOfDifferentDeclarationKindTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,143 +18,87 @@ main() {
|
||||
class AugmentationOfDifferentDeclarationKindTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_augments_enum() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A {v}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 5, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a enum with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_extension() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A on int {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
22,
|
||||
7,
|
||||
contextMessages: [message(testFile, 10, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a extension with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_extensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(int it) {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
28,
|
||||
7,
|
||||
contextMessages: [message(testFile, 15, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a extension type with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class foo {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
14,
|
||||
7,
|
||||
contextMessages: [message(testFile, 5, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a function with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int get foo => 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class foo {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
18,
|
||||
7,
|
||||
contextMessages: [message(testFile, 8, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a getter with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_mixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a mixin with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
set foo(int _) {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class foo {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
18,
|
||||
7,
|
||||
contextMessages: [message(testFile, 4, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a setter with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_augments_variable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int foo = 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class foo {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
13,
|
||||
7,
|
||||
contextMessages: [message(testFile, 4, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a top level variable with a class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_constructor_augments_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.foo();
|
||||
}
|
||||
@@ -164,49 +109,37 @@ augment class A {
|
||||
}
|
||||
|
||||
test_class_constructor_augments_staticField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int foo = 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment A.foo();
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
54,
|
||||
7,
|
||||
contextMessages: [message(testFile, 23, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_constructor_augments_staticMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment A.foo();
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
55,
|
||||
7,
|
||||
contextMessages: [message(testFile, 24, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceField_augments_instanceField() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo = 0;
|
||||
}
|
||||
@@ -217,34 +150,25 @@ augment class A {
|
||||
}
|
||||
|
||||
test_class_instanceField_augments_instanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
// [context 2] The first definition of this name.
|
||||
}
|
||||
augment class A {
|
||||
augment int foo = 0;
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a field.
|
||||
// ^^^
|
||||
// [diag.duplicateDefinition][context 2] The name 'foo' is already defined.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
48,
|
||||
7,
|
||||
contextMessages: [message(testFile, 17, 3)],
|
||||
),
|
||||
error(
|
||||
diag.duplicateDefinition,
|
||||
60,
|
||||
3,
|
||||
contextMessages: [message(testFile, 17, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceGetter_augments_instanceField() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo = 0;
|
||||
}
|
||||
@@ -255,70 +179,52 @@ augment class A {
|
||||
}
|
||||
|
||||
test_class_instanceGetter_augments_instanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment int get foo => 0;
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a getter.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
48,
|
||||
7,
|
||||
contextMessages: [message(testFile, 17, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceMethod_augments_instanceField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo = 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
47,
|
||||
7,
|
||||
contextMessages: [message(testFile, 16, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceMethod_augments_instanceGetter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a getter with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
52,
|
||||
7,
|
||||
contextMessages: [message(testFile, 20, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceMethod_augments_instanceMethod() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -329,28 +235,22 @@ augment class A {
|
||||
}
|
||||
|
||||
test_class_instanceMethod_augments_instanceSetter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set foo(int _) {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a setter with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
52,
|
||||
7,
|
||||
contextMessages: [message(testFile, 16, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceSetter_augments_instanceField() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo = 0;
|
||||
}
|
||||
@@ -361,262 +261,186 @@ augment class A {
|
||||
}
|
||||
|
||||
test_class_instanceSetter_augments_instanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment set foo(int _) {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a setter.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
48,
|
||||
7,
|
||||
contextMessages: [message(testFile, 17, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticField_augments_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.foo();
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
// [diag.conflictingConstructorAndStaticField] 'foo' can't be used to name both a constructor and a static field in this class.
|
||||
}
|
||||
augment class A {
|
||||
augment static int foo = 0;
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a field.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.conflictingConstructorAndStaticField, 14, 3),
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
43,
|
||||
7,
|
||||
contextMessages: [message(testFile, 14, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticField_augments_staticMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
// [context 2] The first definition of this name.
|
||||
}
|
||||
augment class A {
|
||||
augment static int foo = 0;
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a field.
|
||||
// ^^^
|
||||
// [diag.duplicateDefinition][context 2] The name 'foo' is already defined.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
55,
|
||||
7,
|
||||
contextMessages: [message(testFile, 24, 3)],
|
||||
),
|
||||
error(
|
||||
diag.duplicateDefinition,
|
||||
74,
|
||||
3,
|
||||
contextMessages: [message(testFile, 24, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticGetter_augments_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.foo();
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static int get foo => 0;
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a getter.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
43,
|
||||
7,
|
||||
contextMessages: [message(testFile, 14, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticGetter_augments_staticMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static int get foo => 0;
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a getter.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
55,
|
||||
7,
|
||||
contextMessages: [message(testFile, 24, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticMethod_augments_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.foo();
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
43,
|
||||
7,
|
||||
contextMessages: [message(testFile, 14, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticMethod_augments_staticField() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int foo = 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
54,
|
||||
7,
|
||||
contextMessages: [message(testFile, 23, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticMethod_augments_staticGetter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int get foo => 0;
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a getter with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
59,
|
||||
7,
|
||||
contextMessages: [message(testFile, 27, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticMethod_augments_staticSetter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static set foo(int _) {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a setter with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
59,
|
||||
7,
|
||||
contextMessages: [message(testFile, 23, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticSetter_augments_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.foo();
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static set foo(int _) {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a setter.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
43,
|
||||
7,
|
||||
contextMessages: [message(testFile, 14, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_staticSetter_augments_staticMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment class A {
|
||||
augment static set foo(int _) {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a setter.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
55,
|
||||
7,
|
||||
contextMessages: [message(testFile, 24, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment enum A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a enum.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_constant_augments_constant() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A {
|
||||
foo
|
||||
}
|
||||
@@ -627,153 +451,101 @@ augment enum A {
|
||||
}
|
||||
|
||||
test_enum_constant_augments_instanceMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A {
|
||||
v;
|
||||
void foo() {}
|
||||
}
|
||||
augment enum A {
|
||||
augment foo(),
|
||||
//^^^^^^^
|
||||
// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist.
|
||||
// ^^^
|
||||
// [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.augmentationWithoutDeclaration, 51, 7),
|
||||
error(diag.conflictingStaticAndInstance, 59, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_staticMethod_augments_constant() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A {
|
||||
foo
|
||||
//^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
}
|
||||
augment enum A {;
|
||||
augment static void foo() {}
|
||||
//^^^^^^^
|
||||
// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a field with a method.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
37,
|
||||
7,
|
||||
contextMessages: [message(testFile, 11, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment extension A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a extension.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment extension type A(int it) {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a extension type.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void A() {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a function.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment mixin A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment typedef A = int;
|
||||
''',
|
||||
[error(diag.typedefAugmentation, 11, 7)],
|
||||
);
|
||||
// [diag.typedefAugmentation][column 1][length 7] Type aliases can't be augmented.
|
||||
''');
|
||||
}
|
||||
|
||||
test_variable_augments_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment int A = 0;
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
11,
|
||||
7,
|
||||
contextMessages: [message(testFile, 6, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a top level variable.
|
||||
''');
|
||||
}
|
||||
|
||||
test_variable_augments_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void foo() {}
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment int foo = 0;
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
14,
|
||||
7,
|
||||
contextMessages: [message(testFile, 5, 3)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a function with a top level variable.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+7
-13
@@ -2,35 +2,29 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationOfMixinApplicationClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AugmentationOfMixinApplicationClassTest extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin M {}
|
||||
class C = A with M;
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment class C {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.augmentationOfMixinApplicationClass,
|
||||
42,
|
||||
7,
|
||||
contextMessages: [message(testFile, 28, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
// [diag.augmentationOfMixinApplicationClass][column 1][length 7][context 1] Mixin application classes can't be augmented.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,45 +2,44 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationTypeParameterBoundTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AugmentationTypeParameterBoundTest extends PubPackageResolutionTest {
|
||||
test_class_method_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo<T>() {}
|
||||
augment void foo<T extends num>();
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 58, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo<T extends num>() {}
|
||||
augment void foo<T extends int>();
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 70, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo<T extends num>() {}
|
||||
augment void foo<T>();
|
||||
@@ -49,41 +48,39 @@ class A {
|
||||
}
|
||||
|
||||
test_class_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
augment class A<T extends num> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 40, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends num> {}
|
||||
augment class A<T extends int> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 52, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends num> {}
|
||||
augment class A<T> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_num_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends num> {}
|
||||
augment class A<T extends num> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_num_num_viaTypeAlias() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef N = num;
|
||||
|
||||
class A<T extends num> {}
|
||||
@@ -92,7 +89,7 @@ augment class A<T extends N> {}
|
||||
}
|
||||
|
||||
test_class_num_num_withImportPrefix() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:core';
|
||||
import 'dart:core' as core;
|
||||
|
||||
@@ -102,180 +99,169 @@ augment class A<T extends core.num> {}
|
||||
}
|
||||
|
||||
test_class_num_Object() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends num> {}
|
||||
augment class A<T extends Object> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 52, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T> {v}
|
||||
augment enum A<T extends num> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 39, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T extends num> {v}
|
||||
augment enum A<T extends int> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 51, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T extends num> {v}
|
||||
augment enum A<T> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_num_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T extends num> {v}
|
||||
augment enum A<T extends num> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T> on int {}
|
||||
augment extension A<T extends num> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 55, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T extends num> on int {}
|
||||
augment extension A<T extends int> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 67, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T extends num> on int {}
|
||||
augment extension A<T> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_num_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T extends num> on int {}
|
||||
augment extension A<T extends num> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(int it) {}
|
||||
augment extension type A<T extends num>(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 66, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T extends num>(int it) {}
|
||||
augment extension type A<T extends int>(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 78, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T extends num>(int it) {}
|
||||
augment extension type A<T>(int it) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_num_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T extends num>(int it) {}
|
||||
augment extension type A<T extends num>(int it) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T> {}
|
||||
augment mixin A<T extends num> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 40, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T extends num> {}
|
||||
augment mixin A<T extends int> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 52, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T extends num> {}
|
||||
augment mixin A<T> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_num_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T extends num> {}
|
||||
augment mixin A<T extends num> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_nothing_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void foo<T>() {}
|
||||
augment void foo<T extends num>();
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 44, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_num_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void foo<T extends num>() {}
|
||||
augment void foo<T extends int>();
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterBound, 56, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_num_nothing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void foo<T extends num>() {}
|
||||
augment void foo<T>();
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_num_num_viaTypeAlias() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef N = num;
|
||||
|
||||
void foo<T extends num>() {}
|
||||
@@ -284,7 +270,7 @@ augment void foo<T extends N>();
|
||||
}
|
||||
|
||||
test_topLevelFunction_num_num_withImportPrefix() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:core';
|
||||
import 'dart:core' as core;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
@@ -18,13 +17,12 @@ main() {
|
||||
@reflectiveTest
|
||||
class AugmentationTypeParameterCountTest extends PubPackageResolutionTest {
|
||||
test_class_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment class A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 27, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.classDeclaration('augment class A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ClassDeclaration
|
||||
@@ -48,13 +46,12 @@ ClassDeclaration
|
||||
}
|
||||
|
||||
test_class_1_0() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
augment class A {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.classDeclaration('augment class A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ClassDeclaration
|
||||
@@ -70,7 +67,7 @@ ClassDeclaration
|
||||
}
|
||||
|
||||
test_class_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
augment class A<T> {}
|
||||
''');
|
||||
@@ -97,13 +94,12 @@ ClassDeclaration
|
||||
}
|
||||
|
||||
test_class_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
augment class A<T, U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.classDeclaration('augment class A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ClassDeclaration
|
||||
@@ -131,13 +127,12 @@ ClassDeclaration
|
||||
}
|
||||
|
||||
test_class_1_3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
augment class A<T, U, V> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.classDeclaration('augment class A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ClassDeclaration
|
||||
@@ -169,13 +164,12 @@ ClassDeclaration
|
||||
}
|
||||
|
||||
test_class_2_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T, U> {}
|
||||
augment class A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.classDeclaration('augment class A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ClassDeclaration
|
||||
@@ -199,17 +193,16 @@ ClassDeclaration
|
||||
}
|
||||
|
||||
test_class_method_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
augment class A {
|
||||
augment void foo<T>();
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 65, 1)],
|
||||
);
|
||||
''');
|
||||
var node = findNode.methodDeclaration('augment void foo');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MethodDeclaration
|
||||
@@ -239,7 +232,7 @@ MethodDeclaration
|
||||
}
|
||||
|
||||
test_class_method_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo<T>() {}
|
||||
}
|
||||
@@ -276,17 +269,16 @@ MethodDeclaration
|
||||
}
|
||||
|
||||
test_class_method_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo<T>() {}
|
||||
}
|
||||
augment class A {
|
||||
augment void foo<T, U>();
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 71, 1)],
|
||||
);
|
||||
''');
|
||||
var node = findNode.methodDeclaration('augment void foo');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MethodDeclaration
|
||||
@@ -320,13 +312,12 @@ MethodDeclaration
|
||||
}
|
||||
|
||||
test_enum_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A {v}
|
||||
augment enum A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 26, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.enumDeclaration('augment enum A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
EnumDeclaration
|
||||
@@ -350,13 +341,12 @@ EnumDeclaration
|
||||
}
|
||||
|
||||
test_enum_1_0() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T> {v}
|
||||
augment enum A {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 27, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.enumDeclaration('augment enum A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
EnumDeclaration
|
||||
@@ -372,7 +362,7 @@ EnumDeclaration
|
||||
}
|
||||
|
||||
test_enum_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T> {v}
|
||||
augment enum A <T>{}
|
||||
''');
|
||||
@@ -399,13 +389,12 @@ EnumDeclaration
|
||||
}
|
||||
|
||||
test_enum_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T> {v}
|
||||
augment enum A<T, U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 32, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.enumDeclaration('augment enum A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
EnumDeclaration
|
||||
@@ -433,13 +422,12 @@ EnumDeclaration
|
||||
}
|
||||
|
||||
test_enum_2_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T, U> {v}
|
||||
augment enum A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.enumDeclaration('augment enum A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
EnumDeclaration
|
||||
@@ -463,13 +451,12 @@ EnumDeclaration
|
||||
}
|
||||
|
||||
test_extension_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A on int {}
|
||||
augment extension A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionDeclaration('augment extension A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionDeclaration
|
||||
@@ -492,13 +479,12 @@ ExtensionDeclaration
|
||||
}
|
||||
|
||||
test_extension_1_0() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T> on int {}
|
||||
augment extension A {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 43, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionDeclaration('augment extension A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionDeclaration
|
||||
@@ -513,7 +499,7 @@ ExtensionDeclaration
|
||||
}
|
||||
|
||||
test_extension_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T> on int {}
|
||||
augment extension A<T> {}
|
||||
''');
|
||||
@@ -539,13 +525,12 @@ ExtensionDeclaration
|
||||
}
|
||||
|
||||
test_extension_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T> on int {}
|
||||
augment extension A<T, U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 48, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionDeclaration('augment extension A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionDeclaration
|
||||
@@ -572,13 +557,12 @@ ExtensionDeclaration
|
||||
}
|
||||
|
||||
test_extension_2_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T, U> on int {}
|
||||
augment extension A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 49, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionDeclaration('augment extension A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionDeclaration
|
||||
@@ -601,13 +585,12 @@ ExtensionDeclaration
|
||||
}
|
||||
|
||||
test_extensionType_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(int it) {}
|
||||
augment extension type A<T>(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 53, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionTypeDeclaration('augment extension type A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
@@ -648,13 +631,12 @@ ExtensionTypeDeclaration
|
||||
}
|
||||
|
||||
test_extensionType_1_0() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(int it) {}
|
||||
augment extension type A(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 54, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionTypeDeclaration('augment extension type A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
@@ -687,7 +669,7 @@ ExtensionTypeDeclaration
|
||||
}
|
||||
|
||||
test_extensionType_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(int it) {}
|
||||
augment extension type A<T>(int it) {}
|
||||
''');
|
||||
@@ -731,13 +713,12 @@ ExtensionTypeDeclaration
|
||||
}
|
||||
|
||||
test_extensionType_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(int it) {}
|
||||
augment extension type A<T, U>(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 59, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionTypeDeclaration('augment extension type A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
@@ -782,13 +763,12 @@ ExtensionTypeDeclaration
|
||||
}
|
||||
|
||||
test_extensionType_2_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T, U>(int it) {}
|
||||
augment extension type A<T>(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 60, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.extensionTypeDeclaration('augment extension type A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
@@ -829,13 +809,12 @@ ExtensionTypeDeclaration
|
||||
}
|
||||
|
||||
test_mixin_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
augment mixin A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 27, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.mixinDeclaration('augment mixin A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MixinDeclaration
|
||||
@@ -858,13 +837,12 @@ MixinDeclaration
|
||||
}
|
||||
|
||||
test_mixin_1_0() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T> {}
|
||||
augment mixin A {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.mixinDeclaration('augment mixin A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MixinDeclaration
|
||||
@@ -879,7 +857,7 @@ MixinDeclaration
|
||||
}
|
||||
|
||||
test_mixin_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T> {}
|
||||
augment mixin A<T> {}
|
||||
''');
|
||||
@@ -905,13 +883,12 @@ MixinDeclaration
|
||||
}
|
||||
|
||||
test_mixin_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T> {}
|
||||
augment mixin A<T, U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.mixinDeclaration('augment mixin A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MixinDeclaration
|
||||
@@ -938,13 +915,12 @@ MixinDeclaration
|
||||
}
|
||||
|
||||
test_mixin_2_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T, U> {}
|
||||
augment mixin A<T> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.mixinDeclaration('augment mixin A');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MixinDeclaration
|
||||
@@ -967,13 +943,12 @@ MixinDeclaration
|
||||
}
|
||||
|
||||
test_topLevelFunction_0_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {}
|
||||
augment void f<T>();
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 27, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.functionDeclaration('augment void f');
|
||||
assertResolvedNodeText(node, r'''
|
||||
FunctionDeclaration
|
||||
@@ -1008,7 +983,7 @@ FunctionDeclaration
|
||||
}
|
||||
|
||||
test_topLevelFunction_1_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>() {}
|
||||
augment void f<T>();
|
||||
''');
|
||||
@@ -1046,13 +1021,12 @@ FunctionDeclaration
|
||||
}
|
||||
|
||||
test_topLevelFunction_1_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>() {}
|
||||
augment void f<T, U>();
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterCount, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration.
|
||||
''');
|
||||
var node = findNode.functionDeclaration('augment void f');
|
||||
assertResolvedNodeText(node, r'''
|
||||
FunctionDeclaration
|
||||
|
||||
@@ -2,101 +2,93 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationTypeParameterNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AugmentationTypeParameterNameTest extends PubPackageResolutionTest {
|
||||
test_class_method_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo<T>() {}
|
||||
augment void foo<U>();
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 48, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
augment class A<U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 30, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_TU_UT() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T, U> {}
|
||||
augment class A<U, T> {}
|
||||
''',
|
||||
[
|
||||
error(diag.augmentationTypeParameterName, 33, 1),
|
||||
error(diag.augmentationTypeParameterName, 36, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum A<T> {v}
|
||||
augment enum A<U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 29, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension A<T> on int {}
|
||||
augment extension A<U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 45, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(int it) {}
|
||||
augment extension type A<U>(int it) {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 56, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T> {}
|
||||
augment mixin A<U> {}
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 30, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_T_U() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void foo<T>() {}
|
||||
augment void foo<U>();
|
||||
''',
|
||||
[error(diag.augmentationTypeParameterName, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+14
-17
@@ -2,50 +2,47 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AwaitInLateLocalVariableInitializerTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AwaitInLateLocalVariableInitializerTest extends PubPackageResolutionTest {
|
||||
static const _errorCode = diag.awaitInLateLocalVariableInitializer;
|
||||
|
||||
test_closure_late_await() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
var v = () async {
|
||||
late var v2 = await 42;
|
||||
// ^^^^^
|
||||
// [diag.awaitInLateLocalVariableInitializer] The 'await' expression can't be used in a 'late' local variable's initializer.
|
||||
print(v2);
|
||||
};
|
||||
print(v);
|
||||
}
|
||||
''',
|
||||
[error(_errorCode, 48, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_late_await() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() async {
|
||||
late var v = await 42;
|
||||
// ^^^^^
|
||||
// [diag.awaitInLateLocalVariableInitializer] The 'await' expression can't be used in a 'late' local variable's initializer.
|
||||
print(v);
|
||||
}
|
||||
''',
|
||||
[error(_errorCode, 30, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_late_await_inClosure_blockBody() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() async {
|
||||
late var v = () async {
|
||||
await 42;
|
||||
@@ -56,7 +53,7 @@ main() async {
|
||||
}
|
||||
|
||||
test_late_await_inClosure_expressionBody() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() async {
|
||||
late var v = () async => await 42;
|
||||
print(v);
|
||||
@@ -65,7 +62,7 @@ main() async {
|
||||
}
|
||||
|
||||
test_no_await() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() async {
|
||||
late var v = 42;
|
||||
print(v);
|
||||
@@ -74,7 +71,7 @@ main() async {
|
||||
}
|
||||
|
||||
test_not_late() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() async {
|
||||
var v = await 42;
|
||||
print(v);
|
||||
|
||||
@@ -2,38 +2,37 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AwaitInWrongContextTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AwaitInWrongContextTest extends PubPackageResolutionTest {
|
||||
test_sync() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x) {
|
||||
return await x;
|
||||
// ^^^^^
|
||||
// [diag.awaitInWrongContext] The await expression can only be used in an async function.
|
||||
}
|
||||
''',
|
||||
[error(diag.awaitInWrongContext, 16, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_syncStar() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x) sync* {
|
||||
yield await x;
|
||||
// ^^^^^
|
||||
// [diag.awaitInWrongContext] The await expression can only be used in an async function.
|
||||
}
|
||||
''',
|
||||
[error(diag.awaitInWrongContext, 21, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AwaitOfExtensionTypeNotFutureTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AwaitOfExtensionTypeNotFutureTest extends PubPackageResolutionTest {
|
||||
test_extensionType_implementsFuture() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(Future<int> it) implements Future<int> {}
|
||||
|
||||
void f(A a) async {
|
||||
@@ -26,20 +27,19 @@ void f(A a) async {
|
||||
}
|
||||
|
||||
test_extensionType_notImplementsFuture() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(int it) {}
|
||||
|
||||
void f(A a) async {
|
||||
await a;
|
||||
//^^^^^
|
||||
// [diag.awaitOfIncompatibleType] The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'.
|
||||
}
|
||||
''',
|
||||
[error(diag.awaitOfIncompatibleType, 51, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_bound_extensionType_implementsFuture() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(Future<int> it) implements Future<int> {}
|
||||
|
||||
void f<T extends A>(T a) async {
|
||||
@@ -49,20 +49,19 @@ void f<T extends A>(T a) async {
|
||||
}
|
||||
|
||||
test_typeParameter_bound_extensionType_notImplementsFuture() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(Future<int> it) {}
|
||||
|
||||
void f<T extends A>(T a) async {
|
||||
await a;
|
||||
//^^^^^
|
||||
// [diag.awaitOfIncompatibleType] The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'.
|
||||
}
|
||||
''',
|
||||
[error(diag.awaitOfIncompatibleType, 72, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_promotedBound_extensionType_implementsFuture() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(Future<int> it) implements Future<int> {}
|
||||
|
||||
void f<T>(T a) async {
|
||||
@@ -74,17 +73,16 @@ void f<T>(T a) async {
|
||||
}
|
||||
|
||||
test_typeParameter_promotedBound_extensionType_notImplementsFuture() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(Future<int> it) {}
|
||||
|
||||
void f<T>(T a) async {
|
||||
if (a is A) {
|
||||
await a;
|
||||
// ^^^^^
|
||||
// [diag.awaitOfIncompatibleType] The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.awaitOfIncompatibleType, 80, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+46
-54
@@ -7,10 +7,12 @@ import 'package:analyzer_testing/analysis_rule/analysis_rule.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BaseClassImplementedOutsideOfLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +20,7 @@ main() {
|
||||
class BaseClassImplementedOutsideOfLibraryTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class Foo {}
|
||||
base class Bar implements Foo {}
|
||||
''');
|
||||
@@ -29,13 +31,12 @@ base class Bar implements Foo {}
|
||||
base class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base class Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 45, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_outside_sealed() async {
|
||||
@@ -111,14 +112,13 @@ class C implements B {}
|
||||
base class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
base class B extends A {}
|
||||
base class C implements B {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 67, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'A' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_outside_viaTypedef_inside() async {
|
||||
@@ -127,13 +127,12 @@ base class Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base class Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 45, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_outside_viaTypedef_outside() async {
|
||||
@@ -141,18 +140,17 @@ base class Bar implements FooTypedef {}
|
||||
base class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
base class Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 71, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
sealed class B extends A {}
|
||||
mixin M {}
|
||||
@@ -195,7 +193,7 @@ base class C = Object with M implements B;
|
||||
}
|
||||
|
||||
test_enum_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class Foo {}
|
||||
enum Bar implements Foo { bar }
|
||||
''');
|
||||
@@ -206,13 +204,12 @@ enum Bar implements Foo { bar }
|
||||
base class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
enum Bar implements Foo { bar }
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 39, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_outside_viaTypedef_inside() async {
|
||||
@@ -221,13 +218,12 @@ base class Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
enum Bar implements FooTypedef { bar }
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 39, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_outside_viaTypedef_outside() async {
|
||||
@@ -235,18 +231,17 @@ enum Bar implements FooTypedef { bar }
|
||||
base class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
enum Bar implements FooTypedef { bar }
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 65, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class Foo {}
|
||||
base mixin Bar implements Foo {}
|
||||
''');
|
||||
@@ -257,13 +252,12 @@ base mixin Bar implements Foo {}
|
||||
base class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base mixin Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 45, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_outside_viaTypedef_inside() async {
|
||||
@@ -272,13 +266,12 @@ base class Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base mixin Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 45, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_outside_viaTypedef_outside() async {
|
||||
@@ -286,13 +279,12 @@ base mixin Bar implements FooTypedef {}
|
||||
base class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
base mixin Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseClassImplementedOutsideOfLibrary, 71, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseClassImplementedOutsideOfLibrary] The class 'Foo' can't be implemented outside of its library because it's a base class.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+41
-48
@@ -6,10 +6,12 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BaseMixinImplementedOutsideOfLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +19,7 @@ main() {
|
||||
class BaseMixinImplementedOutsideOfLibraryTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin Foo {}
|
||||
base class Bar implements Foo {}
|
||||
''');
|
||||
@@ -28,13 +30,12 @@ base class Bar implements Foo {}
|
||||
base mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base class Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 45, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_outside_viaExtends() async {
|
||||
@@ -66,13 +67,12 @@ base mixin Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base class Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 45, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_outside_viaTypedef_outside() async {
|
||||
@@ -80,18 +80,17 @@ base class Bar implements FooTypedef {}
|
||||
base mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
base class Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 71, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin Foo {}
|
||||
enum Bar implements Foo { bar }
|
||||
''');
|
||||
@@ -102,13 +101,12 @@ enum Bar implements Foo { bar }
|
||||
base mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
enum Bar implements Foo { bar }
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 39, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_outside_viaTypedef_inside() async {
|
||||
@@ -117,13 +115,12 @@ base mixin Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
enum Bar implements FooTypedef { bar }
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 39, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_outside_viaTypedef_outside() async {
|
||||
@@ -131,18 +128,17 @@ enum Bar implements FooTypedef { bar }
|
||||
base mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
enum Bar implements FooTypedef { bar }
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 65, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin Foo {}
|
||||
base mixin Bar implements Foo {}
|
||||
''');
|
||||
@@ -153,13 +149,12 @@ base mixin Bar implements Foo {}
|
||||
base mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base mixin Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 45, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_outside_viaTypedef_inside() async {
|
||||
@@ -168,13 +163,12 @@ base mixin Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base mixin Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 45, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_outside_viaTypedef_outside() async {
|
||||
@@ -182,13 +176,12 @@ base mixin Bar implements FooTypedef {}
|
||||
base mixin Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
base mixin Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.baseMixinImplementedOutsideOfLibrary, 71, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.baseMixinImplementedOutsideOfLibrary] The mixin 'Foo' can't be implemented outside of its library because it's a base mixin.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,32 +2,32 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BinaryOperatorWrittenOutTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BinaryOperatorWrittenOutTest extends PubPackageResolutionTest {
|
||||
test_using_and() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x, y) {
|
||||
return x and y;
|
||||
// ^^^
|
||||
// [diag.binaryOperatorWrittenOut] Binary operator 'and' is written as '&' instead of the written out word.
|
||||
}
|
||||
''',
|
||||
[error(diag.binaryOperatorWrittenOut, 21, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_using_and_no_error() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x, y) {
|
||||
return x & y;
|
||||
}
|
||||
@@ -35,18 +35,17 @@ f(x, y) {
|
||||
}
|
||||
|
||||
test_using_or() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x, y) {
|
||||
return x or y;
|
||||
// ^^
|
||||
// [diag.binaryOperatorWrittenOut] Binary operator 'or' is written as '|' instead of the written out word.
|
||||
}
|
||||
''',
|
||||
[error(diag.binaryOperatorWrittenOut, 21, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_using_or_no_error() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x, y) {
|
||||
return x | y;
|
||||
}
|
||||
@@ -54,18 +53,17 @@ f(x, y) {
|
||||
}
|
||||
|
||||
test_using_shl() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x) {
|
||||
return x shl 2;
|
||||
// ^^^
|
||||
// [diag.binaryOperatorWrittenOut] Binary operator 'shl' is written as '<<' instead of the written out word.
|
||||
}
|
||||
''',
|
||||
[error(diag.binaryOperatorWrittenOut, 18, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_using_shl_no_error() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x) {
|
||||
return x << 2;
|
||||
}
|
||||
@@ -73,18 +71,17 @@ f(x) {
|
||||
}
|
||||
|
||||
test_using_shr() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x) {
|
||||
return x shr 2;
|
||||
// ^^^
|
||||
// [diag.binaryOperatorWrittenOut] Binary operator 'shr' is written as '>>' instead of the written out word.
|
||||
}
|
||||
''',
|
||||
[error(diag.binaryOperatorWrittenOut, 18, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_using_shr_no_error() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x) {
|
||||
return x >> 2;
|
||||
}
|
||||
@@ -92,18 +89,17 @@ f(x) {
|
||||
}
|
||||
|
||||
test_using_xor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x, y) {
|
||||
return x xor y;
|
||||
// ^^^
|
||||
// [diag.binaryOperatorWrittenOut] Binary operator 'xor' is written as '^' instead of the written out word.
|
||||
}
|
||||
''',
|
||||
[error(diag.binaryOperatorWrittenOut, 21, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_using_xor_no_error() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(x, y) {
|
||||
return x ^ y;
|
||||
}
|
||||
|
||||
+18
-20
@@ -2,21 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BodyMayCompleteNormallyCatchErrorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BodyMayCompleteNormallyCatchErrorTest extends PubPackageResolutionTest {
|
||||
test_alwaysReturn() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) {
|
||||
return 7;
|
||||
@@ -26,7 +27,7 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_noReturn_futureOrVoidReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(Future<FutureOr<void>> future) {
|
||||
future.catchError((e, st) {});
|
||||
@@ -35,40 +36,37 @@ void f(Future<FutureOr<void>> future) {
|
||||
}
|
||||
|
||||
test_noReturn_namedBeforePositional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError(test: (_) => false, (e, st) {});
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormallyCatchError] This 'onError' handler must return a value assignable to 'int', but ends without returning a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormallyCatchError, 77, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noReturn_nonNullableReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) {});
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormallyCatchError] This 'onError' handler must return a value assignable to 'int', but ends without returning a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormallyCatchError, 57, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noReturn_nullableReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int?> future) {
|
||||
future.catchError((e, st) {});
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormallyCatchError] This 'onError' handler must return a value assignable to 'int?', but ends without returning a value.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormallyCatchError, 58, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noReturn_nullReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<Null> future) {
|
||||
future.catchError((e, st) {});
|
||||
}
|
||||
@@ -76,7 +74,7 @@ void f(Future<Null> future) {
|
||||
}
|
||||
|
||||
test_noReturn_voidReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((e, st) {});
|
||||
}
|
||||
|
||||
@@ -2,45 +2,45 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BodyMightCompleteNormallyNullableTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BodyMightCompleteNormallyNullableTest extends PubPackageResolutionTest {
|
||||
test_function_async_block_futureOrIntQuestion() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
FutureOr<int?> f(Future f) async {}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormallyNullable, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormallyNullable] This function has a nullable return type of 'FutureOr<int?>', but ends without returning a value.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_futureOrVoid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
FutureOr<void> f(Future f) async {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(Future f) async {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_switchStatement_exhaustive_extensionType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E { a, b }
|
||||
|
||||
extension type EE(E it) {}
|
||||
@@ -57,22 +57,21 @@ int f(EE e) {
|
||||
}
|
||||
|
||||
test_function_sync_block_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
dynamic f() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_intQuestion() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int? f() {}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormallyNullable, 5, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormallyNullable] This function has a nullable return type of 'int?', but ends without returning a value.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_intQuestion_definiteReturn() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int? f() {
|
||||
return null;
|
||||
}
|
||||
@@ -80,13 +79,13 @@ int? f() {
|
||||
}
|
||||
|
||||
test_function_sync_block_Null() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Null f() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {}
|
||||
''');
|
||||
}
|
||||
|
||||
@@ -6,11 +6,13 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BodyMayCompleteNormallyTest);
|
||||
defineReflectiveTests(BodyMayCompleteNormallyTest_Language219);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +34,7 @@ mixin BodyMayCompleteNormallyTestCases on PubPackageResolutionTest {
|
||||
bool get _arePatternsEnabled;
|
||||
|
||||
test_enum_method_nonNullable_blockBody_switchStatement_notNullable_exhaustive() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a;
|
||||
|
||||
@@ -74,74 +76,69 @@ enum E {
|
||||
}
|
||||
|
||||
test_factoryConstructor_named_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A.named() {}
|
||||
// ^^^^^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'A', is a potentially non-nullable type.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 20, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factoryConstructor_unnamed_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() {}
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'A', is a potentially non-nullable type.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_future_int_blockBody_async() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> foo() async {}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 12, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr<int>', is a potentially non-nullable type.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_future_void_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<void> foo() {}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 13, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'Future<void>', is a potentially non-nullable type.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_future_void_blockBody_async() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<void> foo() async {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int foo() {}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 4, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody_generator_async() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Stream<int> foo() async* {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody_generator_sync() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Iterable<int> foo() sync* {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody_switchStatement_notNullable_exhaustive() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum Foo { a, b }
|
||||
|
||||
int f(Foo foo) {
|
||||
@@ -156,7 +153,7 @@ int f(Foo foo) {
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody_switchStatement_notNullable_exhaustive_enhanced() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a;
|
||||
|
||||
@@ -176,7 +173,7 @@ int f(E e) {
|
||||
test_function_nonNullable_blockBody_switchStatement_notNullable_exhaustive_parenthesis() async {
|
||||
// TODO(johnniwinther): Re-enable this test for the patterns feature.
|
||||
if (_arePatternsEnabled) return;
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum Foo { a, b }
|
||||
|
||||
int f(Foo foo) {
|
||||
@@ -239,7 +236,7 @@ int f(E e) {
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody_switchStatement_nullable_exhaustive_default() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum Foo { a, b }
|
||||
|
||||
int f(Foo? foo) {
|
||||
@@ -256,7 +253,7 @@ int f(Foo? foo) {
|
||||
}
|
||||
|
||||
test_function_nonNullable_blockBody_switchStatement_nullable_exhaustive_null() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum Foo { a, b }
|
||||
|
||||
int f(Foo? foo) {
|
||||
@@ -297,7 +294,7 @@ int f(Foo? foo) {
|
||||
}
|
||||
|
||||
test_function_nullable_blockBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int foo() {
|
||||
return 0;
|
||||
}
|
||||
@@ -305,31 +302,29 @@ int foo() {
|
||||
}
|
||||
|
||||
test_functionExpression_future_int_blockBody_async() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
Future<int> Function() foo = () async {};
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr<int>', is a potentially non-nullable type.
|
||||
foo;
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 51, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionExpression_future_void_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
Future<void> Function() foo = () {};
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'Future<void>', is a potentially non-nullable type.
|
||||
foo;
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 46, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionExpression_future_void_blockBody_async() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
Future<void> Function() foo = () async {};
|
||||
foo;
|
||||
@@ -338,20 +333,19 @@ main() {
|
||||
}
|
||||
|
||||
test_functionExpression_notNullable_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
int Function() foo = () {
|
||||
// ^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type.
|
||||
};
|
||||
foo;
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 37, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionExpression_notNullable_blockBody_return() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
int Function() foo = () {
|
||||
return 0;
|
||||
@@ -362,7 +356,7 @@ main() {
|
||||
}
|
||||
|
||||
test_generativeConstructor_blockBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
@@ -370,7 +364,7 @@ class A {
|
||||
}
|
||||
|
||||
test_generativeConstructor_emptyBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A();
|
||||
}
|
||||
@@ -378,29 +372,27 @@ class A {
|
||||
}
|
||||
|
||||
test_method_future_int_blockBody_async() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
Future<int> foo() async {}
|
||||
// ^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr<int>', is a potentially non-nullable type.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 24, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_future_void_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
Future<void> foo() {}
|
||||
// ^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'Future<void>', is a potentially non-nullable type.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 25, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_future_void_blockBody_async() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
Future<void> foo() async {}
|
||||
}
|
||||
@@ -408,18 +400,17 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo() {}
|
||||
// ^^^
|
||||
// [diag.bodyMightCompleteNormally] The body might complete normally, causing 'null' to be returned, but the return type, 'int', is a potentially non-nullable type.
|
||||
}
|
||||
''',
|
||||
[error(diag.bodyMightCompleteNormally, 16, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_nonNullable_blockBody_generator_async() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
Stream<int> foo() async* {
|
||||
yield 0;
|
||||
@@ -429,7 +420,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_blockBody_generator_sync() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
Iterable<int> foo() sync* {
|
||||
yield 0;
|
||||
@@ -439,7 +430,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_blockBody_return() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo() {
|
||||
return 0;
|
||||
@@ -449,7 +440,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_blockBody_throw() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo() {
|
||||
throw 0;
|
||||
@@ -459,7 +450,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_emptyBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
int foo();
|
||||
}
|
||||
@@ -467,7 +458,7 @@ abstract class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_expressionBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo() => 0;
|
||||
}
|
||||
@@ -475,7 +466,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nonNullable_expressionBody_throw() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo() => throw 0;
|
||||
}
|
||||
@@ -483,7 +474,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_nullable_blockBody_return() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int? foo() {
|
||||
return 0;
|
||||
@@ -496,11 +487,9 @@ class A {
|
||||
// Even though this code has an illegal return type for a setter, do not
|
||||
// use the invalid return type to report BODY_MIGHT_COMPLETE_NORMALLY for
|
||||
// setters.
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool set s(int value) {}
|
||||
''',
|
||||
[error(diag.nonVoidReturnForSetter, 0, 4)],
|
||||
);
|
||||
// [diag.nonVoidReturnForSetter][column 1][length 4] The return type of the setter must be 'void' or absent.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,38 +2,37 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BreakLabelOnSwitchMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BreakLabelOnSwitchMemberTest extends PubPackageResolutionTest {
|
||||
test_it() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
L: case 0:
|
||||
break;
|
||||
case 1:
|
||||
break L;
|
||||
// ^
|
||||
// [diag.breakLabelOnSwitchMember] A break label resolves to the 'case' or 'default' statement.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.breakLabelOnSwitchMember, 83, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_it_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.19
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
@@ -41,10 +40,10 @@ void f(int x) {
|
||||
break;
|
||||
case 1:
|
||||
break L;
|
||||
// ^
|
||||
// [diag.breakLabelOnSwitchMember] A break label resolves to the 'case' or 'default' statement.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.breakLabelOnSwitchMember, 99, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,64 +2,61 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BuiltInIdentifierAsExtensionNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BuiltInIdentifierAsExtensionNameTest extends PubPackageResolutionTest {
|
||||
test_as() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension as on Object {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionName, 10, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'as' can't be used as an extension name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension Function on Object {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionName, 10, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'Function' can't be used as an extension name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension inout on Object {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionName, 10, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'inout' can't be used as an extension name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
extension inout on Object {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension out on Object {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionName, 10, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'out' can't be used as an extension name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
extension out on Object {}
|
||||
''');
|
||||
|
||||
+20
-23
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BuiltInIdentifierAsExtensionTypeNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,50 +18,46 @@ main() {
|
||||
class BuiltInIdentifierAsExtensionTypeNameTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_as() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type as(int it) {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionTypeName, 15, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'as' can't be used as an extension type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type Function(int it) {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionTypeName, 15, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'Function' can't be used as an extension type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type inout(int it) {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionTypeName, 15, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'inout' can't be used as an extension type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
extension type inout(int it) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type out(int it) {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsExtensionTypeName, 15, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'out' can't be used as an extension type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
extension type out(int it) {}
|
||||
''');
|
||||
|
||||
@@ -2,84 +2,75 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BuiltInIdentifierAsPrefixNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BuiltInIdentifierAsPrefixNameTest extends PubPackageResolutionTest {
|
||||
test_abstract() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async' as abstract;
|
||||
''',
|
||||
[
|
||||
error(diag.unusedImport, 7, 12),
|
||||
error(diag.builtInIdentifierAsPrefixName, 23, 8),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:async'.
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'abstract' can't be used as a prefix name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_Function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async' as Function;
|
||||
''',
|
||||
[
|
||||
error(diag.unusedImport, 7, 12),
|
||||
error(diag.builtInIdentifierAsPrefixName, 23, 8),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:async'.
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'Function' can't be used as a prefix name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async' as inout;
|
||||
''',
|
||||
[
|
||||
error(diag.unusedImport, 7, 12),
|
||||
error(diag.builtInIdentifierAsPrefixName, 23, 5),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:async'.
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'inout' can't be used as a prefix name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_inout_language310() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
import 'dart:async' as inout;
|
||||
''',
|
||||
[error(diag.unusedImport, 23, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:async'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async' as out;
|
||||
''',
|
||||
[
|
||||
error(diag.unusedImport, 7, 12),
|
||||
error(diag.builtInIdentifierAsPrefixName, 23, 3),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:async'.
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'out' can't be used as a prefix name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_out_language310() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
import 'dart:async' as out;
|
||||
''',
|
||||
[error(diag.unusedImport, 23, 12)],
|
||||
);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.unusedImport] Unused import: 'dart:async'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,148 +2,139 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BuiltInIdentifierAsTypeNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BuiltInIdentifierAsTypeNameTest extends PubPackageResolutionTest {
|
||||
test_class_as() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class as {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'as' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_Function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class Function {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'Function' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class inout {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
class inout {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class out {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
class out {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_as() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum as {
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'as' can't be used as a type name.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 5, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum inout {v}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 5, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
enum inout {v}
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum out {v}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 5, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
enum out {v}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_as() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin as {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'as' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_Function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin Function {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'Function' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin inout {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
mixin inout {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_OK_on() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
mixin on on A {}
|
||||
@@ -159,16 +150,15 @@ class D = Object with M2;
|
||||
}
|
||||
|
||||
test_mixin_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin out {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeName, 6, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
mixin out {}
|
||||
''');
|
||||
|
||||
+44
-53
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BuiltInIdentifierAsTypeParameterNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,106 +18,96 @@ main() {
|
||||
class BuiltInIdentifierAsTypeParameterNameTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_as() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<as> {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 8, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_Function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<Function> {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 8, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'Function' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<inout> {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 8, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
class A<inout> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<out> {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 8, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
class A<out> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_as() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension <as> on List {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 11, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension <inout> on List {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 11, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension <out> on List {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 11, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_as() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<as>() {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 7, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<inout>() {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 7, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<out>() {}
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypeParameterName, 7, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,43 +2,42 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(BuiltInIdentifierAsTypedefNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BuiltInIdentifierAsTypedefNameTest extends PubPackageResolutionTest {
|
||||
test_classTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin B {}
|
||||
class as = A with B;
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 28, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin B {}
|
||||
class inout = A with B;
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 28, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
class A {}
|
||||
mixin B {}
|
||||
@@ -47,18 +46,17 @@ class inout = A with B;
|
||||
}
|
||||
|
||||
test_classTypeAlias_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin B {}
|
||||
class out = A with B;
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 28, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
class A {}
|
||||
mixin B {}
|
||||
@@ -67,126 +65,107 @@ class out = A with B;
|
||||
}
|
||||
|
||||
test_typedef_classic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef void as();
|
||||
''',
|
||||
[
|
||||
error(diag.expectedIdentifierButGotKeyword, 13, 2),
|
||||
error(diag.builtInIdentifierAsTypedefName, 13, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword.
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_classic_as() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef void as();
|
||||
''',
|
||||
[
|
||||
error(diag.expectedIdentifierButGotKeyword, 13, 2),
|
||||
error(diag.builtInIdentifierAsTypedefName, 13, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword.
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_classic_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef void inout();
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 13, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_classic_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
typedef void inout();
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_classic_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef void out();
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 13, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_classic_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
typedef void out();
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_generic_as() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef as = void Function();
|
||||
''',
|
||||
[
|
||||
error(diag.builtInIdentifierAsTypedefName, 8, 2),
|
||||
error(diag.expectedIdentifierButGotKeyword, 8, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword.
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_generic_inout() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef inout = void Function();
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 8, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_generic_inout_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
typedef inout = void Function();
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_generic_out() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef out = void Function();
|
||||
''',
|
||||
[error(diag.builtInIdentifierAsTypedefName, 8, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_generic_out_language310() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
typedef out = void Function();
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_interfaceType_as() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef as = List<int>;
|
||||
''',
|
||||
[
|
||||
error(diag.builtInIdentifierAsTypedefName, 8, 2),
|
||||
error(diag.expectedIdentifierButGotKeyword, 8, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.expectedIdentifierButGotKeyword] 'as' can't be used as an identifier because it's a keyword.
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'as' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_interfaceType_Function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef Function = List<int>;
|
||||
''',
|
||||
[
|
||||
error(diag.builtInIdentifierAsTypedefName, 8, 8),
|
||||
error(diag.expectedIdentifierButGotKeyword, 8, 8),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.expectedIdentifierButGotKeyword] 'Function' can't be used as an identifier because it's a keyword.
|
||||
// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'Function' can't be used as a typedef name.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user