CQ. Migrate diagnostics tests to resolveTestCodeWithDiagnostics. RST.
Change-Id: I5a8ad5b98e5a6c73b2ee4a0d51a9b51e875f47e8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503280 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
a33c0ccf84
commit
1c58533fae
+62
-75
@@ -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(RecordLiteralOnePositionalNoTrailingCommaTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,40 +18,37 @@ main() {
|
||||
class RecordLiteralOnePositionalNoTrailingCommaTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_argument_invalid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) i) {
|
||||
f((''));
|
||||
// ^^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type '(int,)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 24, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_argument_notParenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) i) {
|
||||
f(1);
|
||||
// ^
|
||||
// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type '(int,)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.argumentTypeNotAssignable, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_argument_parenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) i) {
|
||||
f((1));
|
||||
// ^^^
|
||||
// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma.
|
||||
}
|
||||
''',
|
||||
[error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 23, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_argument_valid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) i) {
|
||||
f((1,));
|
||||
}
|
||||
@@ -58,40 +56,37 @@ void f((int,) i) {
|
||||
}
|
||||
|
||||
test_assignment_invalid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) r) {
|
||||
r = ('');
|
||||
// ^^^^
|
||||
// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type '(int,)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidAssignment, 25, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_assignment_notParenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) r) {
|
||||
r = 1;
|
||||
// ^
|
||||
// [diag.invalidAssignment] A value of type 'int' can't be assigned to a variable of type '(int,)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.invalidAssignment, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_assignment_parenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) r) {
|
||||
r = (1);
|
||||
// ^^^
|
||||
// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma.
|
||||
}
|
||||
''',
|
||||
[error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 25, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_assignment_valid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((int,) r) {
|
||||
r = (1,);
|
||||
}
|
||||
@@ -99,89 +94,81 @@ void f((int,) r) {
|
||||
}
|
||||
|
||||
test_declaration() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) r = (1);
|
||||
''',
|
||||
[error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 11, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma.
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaration_invalid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) r = ('');
|
||||
''',
|
||||
[error(diag.invalidAssignment, 12, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type '(int,)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaration_valid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) r = (1,);
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_blockBody_notParenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() {
|
||||
return 1;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of '(int,)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_blockBody_parenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() {
|
||||
return (1);
|
||||
// ^^^
|
||||
// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma.
|
||||
}
|
||||
''',
|
||||
[error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 22, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_expressionBody_invalid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() => ('');
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 14, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of '(int,)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_expressionBody_notParenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() => 1;
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 14, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of '(int,)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_expressionBody_parenthesized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() => (1);
|
||||
''',
|
||||
[error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 14, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma.
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_invalid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() { return (''); }
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 20, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of '(int,)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_valid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
(int,) f() { return (1,); }
|
||||
''');
|
||||
}
|
||||
|
||||
@@ -2,73 +2,67 @@
|
||||
// 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(RecursiveCompileTimeConstantTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RecursiveCompileTimeConstantTest extends PubPackageResolutionTest {
|
||||
test_cycle() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const x = y + 1;
|
||||
// ^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
const y = x + 1;
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveCompileTimeConstant, 6, 1),
|
||||
error(diag.recursiveCompileTimeConstant, 23, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_constant_values() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v(values);
|
||||
//^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
const E(Object a);
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveCompileTimeConstant, 11, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_constants() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v1(v2), v2(v1);
|
||||
//^^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
// ^^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
const E(E other);
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveCompileTimeConstant, 11, 2),
|
||||
error(diag.recursiveCompileTimeConstant, 19, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_fields() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
static const x = y + 1;
|
||||
// ^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
static const y = x + 1;
|
||||
// ^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveCompileTimeConstant, 29, 1),
|
||||
error(diag.recursiveCompileTimeConstant, 55, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromMapLiteral() async {
|
||||
@@ -77,31 +71,29 @@ const int x = y;
|
||||
const int y = x;
|
||||
''');
|
||||
// No errors, because the cycle is not in this source.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'constants.dart';
|
||||
final z = {x: 0, y: 1};
|
||||
''');
|
||||
}
|
||||
|
||||
test_singleVariable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const x = x;
|
||||
''',
|
||||
[error(diag.recursiveCompileTimeConstant, 6, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
''');
|
||||
}
|
||||
|
||||
test_singleVariable_fromConstList() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const elems = const [
|
||||
// ^^^^^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
const [
|
||||
1, elems, 3,
|
||||
],
|
||||
];
|
||||
''',
|
||||
[error(diag.recursiveCompileTimeConstant, 6, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,103 +2,94 @@
|
||||
// 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(RecursiveConstantConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RecursiveConstantConstructorTest extends PubPackageResolutionTest {
|
||||
test_newHead_named_redirectingConstructorInvocation() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const new named() : this.named();
|
||||
// ^^^^^^^^^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstantConstructor, 18, 9),
|
||||
error(diag.recursiveConstructorRedirect, 32, 12),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_newHead_unnamed_redirectingConstructorInvocation() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const new () : this();
|
||||
// ^^^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
// ^^^^^^
|
||||
// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstantConstructor, 18, 3),
|
||||
error(diag.recursiveConstructorRedirect, 27, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A();
|
||||
// ^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
final m = const A();
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveConstantConstructor, 18, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_initializer_after_toplevel_var() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const y = const C();
|
||||
// ^
|
||||
// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself.
|
||||
class C {
|
||||
const C() : x = y;
|
||||
// ^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
final x;
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveCompileTimeConstant, 6, 1),
|
||||
error(diag.recursiveConstantConstructor, 39, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_initializer_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
final A a;
|
||||
const A() : a = const A();
|
||||
// ^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveConstantConstructor, 31, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_initializer_field_multipleClasses() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B {
|
||||
final A a;
|
||||
const B() : a = const A();
|
||||
// ^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
}
|
||||
class A {
|
||||
final B b;
|
||||
const A() : b = const B();
|
||||
// ^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstantConstructor, 31, 1),
|
||||
error(diag.recursiveConstantConstructor, 85, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,47 +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(RecursiveConstructorRedirectTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RecursiveConstructorRedirectTest extends PubPackageResolutionTest {
|
||||
test_directSelfReference() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() : this();
|
||||
// ^^^^^^
|
||||
// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveConstructorRedirect, 18, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_recursive() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.a() : this.b();
|
||||
// ^^^^^^^^
|
||||
// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
A.b() : this.a();
|
||||
// ^^^^^^^^
|
||||
// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstructorRedirect, 20, 8),
|
||||
error(diag.recursiveConstructorRedirect, 40, 8),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_valid_redirect() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.a() : this.b();
|
||||
A.b() : this.c();
|
||||
|
||||
@@ -2,146 +2,152 @@
|
||||
// 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(RecursiveFactoryRedirectTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RecursiveFactoryRedirectTest extends PubPackageResolutionTest {
|
||||
test_directSelfReference() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() = A;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveFactoryRedirect, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_diverging() async {
|
||||
// Analysis should terminate even though the redirections don't reach a
|
||||
// fixed point. (C<int> redirects to C<C<int>>, then to C<C<C<int>>>, and
|
||||
// so on).
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {
|
||||
const factory C() = C<C<T>>;
|
||||
// ^^^^^^^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
main() {
|
||||
const C<int>();
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveFactoryRedirect, 35, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_generic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> implements B<T> {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A.
|
||||
factory A() = C;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class B<T> implements C<T> {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A.
|
||||
factory B() = A;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class C<T> implements A<T> {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A.
|
||||
factory C() = B;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveFactoryRedirect, 45, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 56, 1),
|
||||
error(diag.recursiveFactoryRedirect, 95, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 106, 1),
|
||||
error(diag.recursiveFactoryRedirect, 145, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_loop() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A.
|
||||
factory A() = C;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class B implements C {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A.
|
||||
factory B() = A;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class C implements A {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A.
|
||||
factory C() = B;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveFactoryRedirect, 39, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 50, 1),
|
||||
error(diag.recursiveFactoryRedirect, 83, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 94, 1),
|
||||
error(diag.recursiveFactoryRedirect, 127, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A.
|
||||
factory A.nameA() = C.nameC;
|
||||
// ^^^^^^^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class B implements C {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A.
|
||||
factory B.nameB() = A.nameA;
|
||||
// ^^^^^^^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class C implements A {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A.
|
||||
factory C.nameC() = B.nameB;
|
||||
// ^^^^^^^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveFactoryRedirect, 45, 7),
|
||||
error(diag.recursiveInterfaceInheritance, 62, 1),
|
||||
error(diag.recursiveFactoryRedirect, 101, 7),
|
||||
error(diag.recursiveInterfaceInheritance, 118, 1),
|
||||
error(diag.recursiveFactoryRedirect, 157, 7),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_outsideCycle() async {
|
||||
// "A" references "C" which has cycle with "B". But we should not report
|
||||
// problem for "A" - it is not the part of a cycle.
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() = C;
|
||||
// ^
|
||||
// [diag.redirectToInvalidReturnType] The return type 'C' of the redirected constructor isn't a subtype of 'A'.
|
||||
}
|
||||
class B implements C {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B.
|
||||
factory B() = C;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
class C implements A, B {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B.
|
||||
factory C() = B;
|
||||
// ^
|
||||
// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.redirectToInvalidReturnType, 26, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 37, 1),
|
||||
error(diag.recursiveFactoryRedirect, 70, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 81, 1),
|
||||
error(diag.recursiveFactoryRedirect, 117, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_valid_redirect() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() = B;
|
||||
}
|
||||
|
||||
+12
-16
@@ -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(RecursiveInterfaceInheritanceExtendsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,34 +18,29 @@ main() {
|
||||
class RecursiveInterfaceInheritanceExtendsTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A extends A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceExtends, 6, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceExtends] 'A' can't extend itself.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_abstract() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C extends C {
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceExtends] 'C' can't extend itself.
|
||||
var foo = 0;
|
||||
bar();
|
||||
}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceExtends, 6, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
test_class_inAugmentation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment class A extends A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceExtends, 6, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+18
-21
@@ -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(RecursiveInterfaceInheritanceImplementsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,51 +19,46 @@ main() {
|
||||
class RecursiveInterfaceInheritanceImplementsTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceImplements, 6, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceImplements] 'A' can't implement itself.
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
test_class_inAugmentation() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
augment class A implements A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceImplements, 6, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_tail() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A implements A {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceImplements] 'A' can't implement itself.
|
||||
class B implements A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceImplements, 15, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin M {}
|
||||
class B = A with M implements B;
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceImplements, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceImplements] 'B' can't implement itself.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
mixin A implements B {}
|
||||
mixin B implements A {}''',
|
||||
mixin B implements A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 30, 1),
|
||||
|
||||
@@ -2,49 +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(RecursiveInterfaceInheritanceOnTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RecursiveInterfaceInheritanceOnTest extends PubPackageResolutionTest {
|
||||
test_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A on A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceOn, 6, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceOn] 'A' can't use itself as a superclass constraint.
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
test_1_inAugmentation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
augment mixin A on A {}
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceOn, 6, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A on B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
mixin B on A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 22, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,140 +2,124 @@
|
||||
// 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(RecursiveInterfaceInheritanceTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RecursiveInterfaceInheritanceTest extends PubPackageResolutionTest {
|
||||
test_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A extends B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 27, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 30, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> implements B<T> {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B<T> implements A<T> {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 36, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_generic_typeArgument() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> implements B<List<T>> {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
class B<T> implements A<List<T>> {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 42, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_tail2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A implements B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A.
|
||||
abstract class B implements A {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A.
|
||||
class C implements A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 15, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 48, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_tail3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A implements B {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A.
|
||||
abstract class B implements C {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A.
|
||||
abstract class C implements A {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A.
|
||||
class D implements A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 15, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 48, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 81, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_mixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class M1 = Object with M2;
|
||||
// ^^
|
||||
// [diag.recursiveInterfaceInheritance] 'M1' can't be a superinterface of itself: M2, M1.
|
||||
mixin class M2 = Object with M1;
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 12, 2),
|
||||
error(diag.recursiveInterfaceInheritance, 45, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.recursiveInterfaceInheritance] 'M2' can't be a superinterface of itself: M2, M1.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_mixin_superclass() async {
|
||||
// Make sure we don't get CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS in
|
||||
// addition--that would just be confusing.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C = D with M;
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: D, C.
|
||||
class D = C with M;
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'D' can't be a superinterface of itself: D, C.
|
||||
mixin M {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 6, 1),
|
||||
error(diag.recursiveInterfaceInheritance, 26, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(RecursiveInterfaceInheritanceWithTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,24 +18,17 @@ main() {
|
||||
class RecursiveInterfaceInheritanceWithTest extends PubPackageResolutionTest {
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
test_class_inAugmentation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A extends Object {}
|
||||
augment class A with A {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritanceWith, 6, 1),
|
||||
error(diag.classUsedAsMixin, 47, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class M = Object with M;
|
||||
''',
|
||||
[error(diag.recursiveInterfaceInheritanceWith, 12, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritanceWith] 'M' can't use itself as a mixin.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/package_config_file_builder.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(RedeclareOnNonRedeclaringMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,8 +24,7 @@ class RedeclareOnNonRedeclaringMemberTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {}
|
||||
@@ -32,14 +32,14 @@ class C {}
|
||||
extension type E(C c) implements C {
|
||||
@redeclare
|
||||
int get i => 0;
|
||||
// ^
|
||||
// [diag.redeclareOnNonRedeclaringMember] The getter doesn't redeclare a getter declared in a superinterface.
|
||||
}
|
||||
''',
|
||||
[error(diag.redeclareOnNonRedeclaringMember, 106, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_getter_redeclares() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -54,8 +54,7 @@ extension type E(C c) implements C {
|
||||
}
|
||||
|
||||
test_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {}
|
||||
@@ -63,33 +62,30 @@ class C {}
|
||||
extension type E(C c) implements C {
|
||||
@redeclare
|
||||
void n() {}
|
||||
// ^
|
||||
// [diag.redeclareOnNonRedeclaringMember] The method doesn't redeclare a method declared in a superinterface.
|
||||
}
|
||||
''',
|
||||
[error(diag.redeclareOnNonRedeclaringMember, 103, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_inClass() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {}
|
||||
|
||||
class D implements C {
|
||||
// No REDECLARE_ON_NON_REDECLARING_MEMBER warning.
|
||||
@redeclare
|
||||
// ^^^^^^^^^
|
||||
// [diag.invalidAnnotationTarget] The annotation 'redeclare' can only be used on instance members of extension types.
|
||||
void n() {}
|
||||
}
|
||||
''',
|
||||
[
|
||||
// No REDECLARE_ON_NON_REDECLARING_MEMBER warning.
|
||||
error(diag.invalidAnnotationTarget, 72, 9),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_redeclared() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -104,45 +100,42 @@ extension type E(C c) implements C {
|
||||
}
|
||||
|
||||
test_method_redeclared_private() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
void _foo() {}
|
||||
// ^^^^
|
||||
// [diag.unusedElement] The declaration '_foo' isn't referenced.
|
||||
}
|
||||
|
||||
extension type E(A it) implements A {
|
||||
@redeclare
|
||||
void _foo() {}
|
||||
// ^^^^
|
||||
// [diag.unusedElement] The declaration '_foo' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 51, 4), error(diag.unusedElement, 122, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {}
|
||||
|
||||
extension type E(C c) implements C {
|
||||
// No REDECLARE_ON_NON_REDECLARING_MEMBER warning.
|
||||
@redeclare
|
||||
// ^^^^^^^^^
|
||||
// [diag.invalidAnnotationTarget] The annotation 'redeclare' can only be used on instance members of extension types.
|
||||
static void n() {}
|
||||
}
|
||||
''',
|
||||
[
|
||||
// No REDECLARE_ON_NON_REDECLARING_MEMBER warning.
|
||||
error(diag.invalidAnnotationTarget, 86, 9),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {}
|
||||
@@ -150,14 +143,14 @@ class C {}
|
||||
extension type E(C c) implements C {
|
||||
@redeclare
|
||||
set i(int i) {}
|
||||
// ^
|
||||
// [diag.redeclareOnNonRedeclaringMember] The setter doesn't redeclare a setter declared in a superinterface.
|
||||
}
|
||||
''',
|
||||
[error(diag.redeclareOnNonRedeclaringMember, 102, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_setter_redeclares() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
|
||||
+18
-21
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(RedirectGenerativeToMissingConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,48 +18,44 @@ main() {
|
||||
class RedirectGenerativeToMissingConstructorTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_primary_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A() {
|
||||
this : this.noSuchConstructor();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 21, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_typeName_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() : this.noSuchConstructor();
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.redirectGenerativeToMissingConstructor] The constructor 'A.noSuchConstructor' couldn't be found in 'A'.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectGenerativeToMissingConstructor, 18, 24)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_primary_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E() {
|
||||
v;
|
||||
this : this.noSuchConstructor();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 25, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_typeName_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E() : this.noSuchConstructor();
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.redirectGenerativeToMissingConstructor] The constructor 'E.noSuchConstructor' couldn't be found in 'E'.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectGenerativeToMissingConstructor, 28, 24)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -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(RedirectGenerativeToNonGenerativeConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,26 +18,24 @@ main() {
|
||||
class RedirectGenerativeToNonGenerativeConstructorTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_primary_toFactory() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A() {
|
||||
this : this.x();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
factory A.x() => throw 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.primaryConstructorCannotRedirect, 21, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_toFactory() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() : this.x();
|
||||
// ^^^^^^^^
|
||||
// [diag.redirectGenerativeToNonGenerativeConstructor] Generative constructors can't redirect to a factory constructor.
|
||||
factory A.x() => throw 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectGenerativeToNonGenerativeConstructor, 18, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+12
-13
@@ -2,47 +2,46 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(RedirectToAbstractClassConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RedirectToAbstractClassConstructorTest extends PubPackageResolutionTest {
|
||||
test_abstractRedirectsToSelf() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
factory A() = A._;
|
||||
// ^^^
|
||||
// [diag.redirectToAbstractClassConstructor] The redirecting constructor 'A' can't redirect to a constructor of the abstract class 'A'.
|
||||
A._();
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToAbstractClassConstructor, 35, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_redirectsToAbstractSubclass() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A.named() = B;
|
||||
// ^
|
||||
// [diag.redirectToAbstractClassConstructor] The redirecting constructor 'A.named' can't redirect to a constructor of the abstract class 'B'.
|
||||
A();
|
||||
}
|
||||
|
||||
abstract class B extends A {}
|
||||
''',
|
||||
[error(diag.redirectToAbstractClassConstructor, 32, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_redirectsToSubclass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A.named() = B;
|
||||
A();
|
||||
@@ -53,7 +52,7 @@ class B extends A {}
|
||||
}
|
||||
|
||||
test_redirectsToSubclass_asTypedef() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A.named() = C;
|
||||
A();
|
||||
|
||||
@@ -2,34 +2,34 @@
|
||||
// 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(RedirectToInvalidFunctionTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RedirectToInvalidFunctionTypeTest extends PubPackageResolutionTest {
|
||||
test_redirectToInvalidFunctionType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B {
|
||||
A(int p) {}
|
||||
}
|
||||
class B {
|
||||
factory B() = A;
|
||||
}''',
|
||||
[error(diag.redirectToInvalidFunctionType, 65, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.redirectToInvalidFunctionType] The redirected constructor 'A Function(int)' has incompatible parameters with 'B Function()'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_valid_redirect() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B {
|
||||
A(int p) {}
|
||||
}
|
||||
|
||||
@@ -2,29 +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(RedirectToInvalidReturnTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RedirectToInvalidReturnTypeTest extends PubPackageResolutionTest {
|
||||
test_redirectToInvalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
class B {
|
||||
factory B() = A;
|
||||
}''',
|
||||
[error(diag.redirectToInvalidReturnType, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.redirectToInvalidReturnType] The return type 'A' of the redirected constructor isn't a subtype of 'B'.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(RedirectToMissingConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RedirectToMissingConstructorTest extends PubPackageResolutionTest {
|
||||
test_named() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B{
|
||||
A() {}
|
||||
}
|
||||
class B {
|
||||
factory B() = A.name;
|
||||
}''',
|
||||
[error(diag.redirectToMissingConstructor, 59, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.redirectToMissingConstructor] The constructor 'A.name' couldn't be found in 'A'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements B{
|
||||
A.name() {}
|
||||
}
|
||||
class B {
|
||||
factory B() = A;
|
||||
}''',
|
||||
[error(diag.redirectToMissingConstructor, 64, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.redirectToMissingConstructor] The constructor 'A' couldn't be found in 'A'.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,37 +2,36 @@
|
||||
// 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(RedirectToNonClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RedirectToNonClassTest extends PubPackageResolutionTest {
|
||||
test_notAType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B {
|
||||
int A = 0;
|
||||
factory B() = A;
|
||||
}''',
|
||||
[error(diag.redirectToNonClass, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.redirectToNonClass] The name 'A' isn't a type and can't be used in a redirected constructor.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_undefinedIdentifier() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B {
|
||||
factory B() = A;
|
||||
}''',
|
||||
[error(diag.redirectToNonClass, 26, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.redirectToNonClass] The name 'A' isn't a type and can't be used in a redirected constructor.
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(RedirectToNonConstConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,18 +18,17 @@ main() {
|
||||
class RedirectToNonConstConstructorTest extends PubPackageResolutionTest {
|
||||
test_constRedirector_cannotResolveRedirectee() async {
|
||||
// No crash when redirectee cannot be resolved.
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const factory A.b() = A.a;
|
||||
// ^^^
|
||||
// [diag.redirectToMissingConstructor] The constructor 'A.a' couldn't be found in 'A'.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToMissingConstructor, 34, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constRedirector_constRedirectee() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.a();
|
||||
const factory A.b() = A.a;
|
||||
@@ -37,7 +37,7 @@ class A {
|
||||
}
|
||||
|
||||
test_constRedirector_constRedirectee_generic() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
const A(T value) : this._(value);
|
||||
const A._(T value) : value = value;
|
||||
@@ -51,7 +51,7 @@ void main(){
|
||||
}
|
||||
|
||||
test_constRedirector_constRedirectee_viaInitializer() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.a();
|
||||
const A.b() : this.a();
|
||||
@@ -60,55 +60,51 @@ class A {
|
||||
}
|
||||
|
||||
test_constRedirector_nonConstRedirectee() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.a();
|
||||
const factory A.b() = A.a;
|
||||
// ^^^
|
||||
// [diag.redirectToNonConstConstructor] A constant redirecting constructor can't redirect to a non-constant constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToNonConstConstructor, 43, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constRedirector_nonConstRedirectee_viaInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.a();
|
||||
const A.b() : this.a();
|
||||
// ^
|
||||
// [diag.redirectToNonConstConstructor] A constant redirecting constructor can't redirect to a non-constant constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToNonConstConstructor, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constRedirector_nonConstRedirectee_viaInitializer_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A();
|
||||
const A.named() : this();
|
||||
// ^^^^
|
||||
// [diag.redirectToNonConstConstructor] A constant redirecting constructor can't redirect to a non-constant constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToNonConstConstructor, 37, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constRedirector_viaInitializer_cannotResolveRedirectee() async {
|
||||
// No crash when redirectee cannot be resolved.
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.b() : this.a();
|
||||
// ^^^^^^^^
|
||||
// [diag.redirectGenerativeToMissingConstructor] The constructor 'A.a' couldn't be found in 'A'.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectGenerativeToMissingConstructor, 26, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_redirect_to_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.a();
|
||||
const factory A.b() = A.a;
|
||||
|
||||
+16
-18
@@ -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(RedirectTypeAliasExpandsToTypeParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,8 +18,7 @@ main() {
|
||||
class RedirectTypeAliasExpandsToTypeParameterTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_generic_typeParameter_withArgument_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements C {
|
||||
A.named();
|
||||
}
|
||||
@@ -27,44 +27,42 @@ typedef B<T> = T;
|
||||
|
||||
class C {
|
||||
factory C() = B<A>.named;
|
||||
// ^
|
||||
// [diag.redirectToTypeAliasExpandsToTypeParameter] A redirecting constructor can't redirect to a type alias that expands to a type parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToTypeAliasExpandsToTypeParameter, 84, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_generic_typeParameter_withArgument_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements C {}
|
||||
|
||||
typedef B<T> = T;
|
||||
|
||||
class C {
|
||||
factory C() = B<A>;
|
||||
// ^
|
||||
// [diag.redirectToTypeAliasExpandsToTypeParameter] A redirecting constructor can't redirect to a type alias that expands to a type parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToTypeAliasExpandsToTypeParameter, 70, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_generic_typeParameter_withoutArgument_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements C {}
|
||||
|
||||
typedef B<T> = T;
|
||||
|
||||
class C {
|
||||
factory C() = B;
|
||||
// ^
|
||||
// [diag.redirectToTypeAliasExpandsToTypeParameter] A redirecting constructor can't redirect to a type alias that expands to a type parameter.
|
||||
}
|
||||
''',
|
||||
[error(diag.redirectToTypeAliasExpandsToTypeParameter, 70, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notGeneric_class_named() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements C {
|
||||
A.named();
|
||||
}
|
||||
@@ -78,7 +76,7 @@ class C {
|
||||
}
|
||||
|
||||
test_notGeneric_class_unnamed() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A implements C {}
|
||||
|
||||
typedef B = A;
|
||||
|
||||
@@ -2,49 +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(ReferencedBeforeDeclarationTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReferencedBeforeDeclarationTest extends PubPackageResolutionTest {
|
||||
test_block_patternVariable_after() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 0;
|
||||
void f() {
|
||||
v;
|
||||
//^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
var [v] = [0];
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
24,
|
||||
1,
|
||||
contextMessages: [message(testFile, 34, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@34
|
||||
element: v@149
|
||||
staticType: InvalidType
|
||||
''');
|
||||
}
|
||||
|
||||
test_block_patternVariable_before() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 0;
|
||||
void f() {
|
||||
var [v] = [0];
|
||||
@@ -54,7 +49,7 @@ void f() {
|
||||
}
|
||||
|
||||
test_cascade_after_declaration() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
testRequestHandler() {}
|
||||
|
||||
main() {
|
||||
@@ -68,156 +63,118 @@ main() {
|
||||
}
|
||||
|
||||
test_forElement_forPartsWithDeclarations_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
[for (var x = x;;) x];
|
||||
// ^
|
||||
// [context 1] The declaration of 'x' is here.
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'x' can't be referenced before it is declared.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
27,
|
||||
1,
|
||||
contextMessages: [message(testFile, 23, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forStatement_forPartsWithDeclarations_initializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
for (var x = x;;) {
|
||||
// ^
|
||||
// [context 1] The declaration of 'x' is here.
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'x' can't be referenced before it is declared.
|
||||
x;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
26,
|
||||
1,
|
||||
contextMessages: [message(testFile, 22, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInBlock_comment() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
/// [v] is a variable.
|
||||
var v = 2;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
}
|
||||
print(x) {}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInBlock_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 1;
|
||||
main() {
|
||||
print(v);
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
v() {}
|
||||
//^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
print(x) {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
28,
|
||||
1,
|
||||
contextMessages: [message(testFile, 34, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInBlock_local() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 1;
|
||||
main() {
|
||||
print(v);
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
var v = 2;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
print(x) {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
28,
|
||||
1,
|
||||
contextMessages: [message(testFile, 38, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInBlock_local_subBlock() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 1;
|
||||
main() {
|
||||
{
|
||||
print(v);
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
}
|
||||
var v = 2;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
print(x) {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
34,
|
||||
1,
|
||||
contextMessages: [message(testFile, 48, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchCase_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 0;
|
||||
|
||||
void f(int a) {
|
||||
switch (a) {
|
||||
case 0:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
void v() {}
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
61,
|
||||
1,
|
||||
contextMessages: [message(testFile, 75, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@75
|
||||
element: v@194
|
||||
staticType: void Function()
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchCase_function_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.19
|
||||
var v = 0;
|
||||
|
||||
@@ -225,64 +182,52 @@ void f(int a) {
|
||||
switch (a) {
|
||||
case 0:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
void v() {}
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
77,
|
||||
1,
|
||||
contextMessages: [message(testFile, 91, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@91
|
||||
element: v@210
|
||||
staticType: void Function()
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchCase_local() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 0;
|
||||
|
||||
void f(int a) {
|
||||
switch (a) {
|
||||
case 0:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
var v = 1;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
61,
|
||||
1,
|
||||
contextMessages: [message(testFile, 74, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@74
|
||||
element: v@193
|
||||
staticType: dynamic
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchCase_local_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.19
|
||||
var v = 0;
|
||||
|
||||
@@ -290,64 +235,52 @@ void f(int a) {
|
||||
switch (a) {
|
||||
case 0:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
var v = 1;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
77,
|
||||
1,
|
||||
contextMessages: [message(testFile, 90, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@90
|
||||
element: v@209
|
||||
staticType: dynamic
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchDefault_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 0;
|
||||
|
||||
void f(int a) {
|
||||
switch (a) {
|
||||
default:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
void v() {}
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
62,
|
||||
1,
|
||||
contextMessages: [message(testFile, 76, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@76
|
||||
element: v@195
|
||||
staticType: void Function()
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchDefault_function_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.19
|
||||
var v = 0;
|
||||
|
||||
@@ -355,64 +288,52 @@ void f(int a) {
|
||||
switch (a) {
|
||||
default:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
void v() {}
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
78,
|
||||
1,
|
||||
contextMessages: [message(testFile, 92, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@92
|
||||
element: v@211
|
||||
staticType: void Function()
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchDefault_local() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = 0;
|
||||
|
||||
void f(int a) {
|
||||
switch (a) {
|
||||
default:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
var v = 1;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
62,
|
||||
1,
|
||||
contextMessages: [message(testFile, 75, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@75
|
||||
element: v@194
|
||||
staticType: dynamic
|
||||
''');
|
||||
}
|
||||
|
||||
test_hideInSwitchDefault_local_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.19
|
||||
var v = 0;
|
||||
|
||||
@@ -420,67 +341,50 @@ void f(int a) {
|
||||
switch (a) {
|
||||
default:
|
||||
v;
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
var v = 1;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
78,
|
||||
1,
|
||||
contextMessages: [message(testFile, 91, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.simple('v;');
|
||||
assertResolvedNodeText(node, r'''
|
||||
SimpleIdentifier
|
||||
token: v
|
||||
element: v@91
|
||||
element: v@210
|
||||
staticType: dynamic
|
||||
''');
|
||||
}
|
||||
|
||||
test_inInitializer_closure() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
var v = () => v;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
25,
|
||||
1,
|
||||
contextMessages: [message(testFile, 15, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_inInitializer_directly() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
var v = v;
|
||||
// ^
|
||||
// [context 1] The declaration of 'v' is here.
|
||||
// ^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
19,
|
||||
1,
|
||||
contextMessages: [message(testFile, 15, 1)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_labeledStatement_function() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
// ignore:unused_label
|
||||
label: void v() {}
|
||||
@@ -498,7 +402,7 @@ SimpleIdentifier
|
||||
}
|
||||
|
||||
test_labeledStatement_local() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
// ignore:unused_label
|
||||
label: var v = 0;
|
||||
@@ -516,42 +420,30 @@ SimpleIdentifier
|
||||
}
|
||||
|
||||
test_type_localFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void testTypeRef() {
|
||||
String s = '';
|
||||
//^^^^^^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'String' can't be referenced before it is declared.
|
||||
int String(int x) => x + 1;
|
||||
// ^^^^^^
|
||||
// [context 1] The declaration of 'String' is here.
|
||||
print(s + String);
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
23,
|
||||
6,
|
||||
contextMessages: [message(testFile, 44, 6)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_type_localVariable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void testTypeRef() {
|
||||
String s = '';
|
||||
//^^^^^^
|
||||
// [diag.referencedBeforeDeclaration][context 1] Local variable 'String' can't be referenced before it is declared.
|
||||
var String = '';
|
||||
// ^^^^^^
|
||||
// [context 1] The declaration of 'String' is here.
|
||||
print(s + String);
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.referencedBeforeDeclaration,
|
||||
23,
|
||||
6,
|
||||
contextMessages: [message(testFile, 44, 6)],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+20
-24
@@ -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(RefutablePatternInIrrefutableContextTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,14 +18,13 @@ main() {
|
||||
class RefutablePatternInIrrefutableContextTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_declaration_constantPattern() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
var (0) = 0;
|
||||
// ^
|
||||
// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context.
|
||||
}
|
||||
''',
|
||||
[error(diag.refutablePatternInIrrefutableContext, 18, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePatternVariableDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -48,17 +48,15 @@ PatternVariableDeclaration
|
||||
}
|
||||
|
||||
test_declaration_logicalOrPattern() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
var (_ || _) = 0;
|
||||
// ^^^^^^
|
||||
// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context.
|
||||
// ^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.refutablePatternInIrrefutableContext, 18, 6),
|
||||
error(diag.deadCode, 20, 4),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePatternVariableDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -86,14 +84,13 @@ PatternVariableDeclaration
|
||||
}
|
||||
|
||||
test_declaration_nullCheckPattern() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? x) {
|
||||
var (_?) = x;
|
||||
// ^^
|
||||
// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context.
|
||||
}
|
||||
''',
|
||||
[error(diag.refutablePatternInIrrefutableContext, 24, 2)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePatternVariableDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -119,14 +116,13 @@ PatternVariableDeclaration
|
||||
}
|
||||
|
||||
test_declaration_relationalPattern() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
var (> 0) = 0;
|
||||
// ^^^
|
||||
// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context.
|
||||
}
|
||||
''',
|
||||
[error(diag.refutablePatternInIrrefutableContext, 18, 3)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singlePatternVariableDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
+21
-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(RelationalPatternArgumentTypeNotAssignableTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ main() {
|
||||
class RelationalPatternArgumentTypeNotAssignableTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_bangEq_matchedValueNullable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
void f(A? x) {
|
||||
@@ -30,7 +31,7 @@ void f(A? x) {
|
||||
}
|
||||
|
||||
test_bangEq_operandNull() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
void f(A x) {
|
||||
@@ -43,7 +44,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_bangEq_operandNullable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
const int? y = 0;
|
||||
@@ -58,7 +59,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_eqEq() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
void f(A x) {
|
||||
@@ -71,8 +72,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_eqEq_covariantParameterType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
bool operator ==(covariant A other) => true;
|
||||
}
|
||||
@@ -80,16 +80,16 @@ class A {
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
case == 0:
|
||||
// ^
|
||||
// [diag.relationalPatternOperandTypeNotAssignable] The constant expression type 'int' is not assignable to the parameter type 'A' of the '==' operator.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.relationalPatternOperandTypeNotAssignable, 101, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_eqEq_externalType_right() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type const A(bool it) {}
|
||||
const True = A(true);
|
||||
|
||||
@@ -103,7 +103,7 @@ void f(bool x) {
|
||||
}
|
||||
|
||||
test_eqEq_matchedValueNullable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
void f(A? x) {
|
||||
@@ -116,23 +116,22 @@ void f(A? x) {
|
||||
}
|
||||
|
||||
test_eqEq_operandNull() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
case == null:
|
||||
break;
|
||||
// ^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 65, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_eqEq_operandNullable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
const int? y = 0;
|
||||
@@ -147,8 +146,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_greaterThan() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
bool operator >(A other) => true;
|
||||
}
|
||||
@@ -156,11 +154,11 @@ class A {
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
case > 0:
|
||||
// ^
|
||||
// [diag.relationalPatternOperandTypeNotAssignable] The constant expression type 'int' is not assignable to the parameter type 'A' of the '>' operator.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.relationalPatternOperandTypeNotAssignable, 89, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+11
-24
@@ -2,16 +2,17 @@
|
||||
// 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(
|
||||
RelationalPatternOperatorReturnTypeNotAssignableToBoolTest,
|
||||
);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ main() {
|
||||
class RelationalPatternOperatorReturnTypeNotAssignableToBoolTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_dynamic() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
dynamic operator >(_) => 42;
|
||||
}
|
||||
@@ -31,44 +32,30 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int operator >(_) => 42;
|
||||
}
|
||||
|
||||
void f(A x) {
|
||||
if (x case > 0) {}
|
||||
// ^
|
||||
// [diag.relationalPatternOperatorReturnTypeNotAssignableToBool] The return type of operators used in relational patterns must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.relationalPatternOperatorReturnTypeNotAssignableToBool,
|
||||
67,
|
||||
1,
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_Object() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
Object operator >(_) => 42;
|
||||
}
|
||||
|
||||
void f(A x) {
|
||||
if (x case > 0) {}
|
||||
// ^
|
||||
// [diag.relationalPatternOperatorReturnTypeNotAssignableToBool] The return type of operators used in relational patterns must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.relationalPatternOperatorReturnTypeNotAssignableToBool,
|
||||
70,
|
||||
1,
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer/src/test_utilities/lint_registration_mixin.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(RemovedLintUseTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,23 +32,21 @@ linter:
|
||||
}
|
||||
|
||||
test_file() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore_for_file: super_goes_last
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.removedLintUse] 'super_goes_last' was removed in Dart '3.0.0'
|
||||
|
||||
void f() { }
|
||||
''',
|
||||
[error(diag.removedLintUse, 20, 15)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_line() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore: super_goes_last
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.removedLintUse] 'super_goes_last' was removed in Dart '3.0.0'
|
||||
void f() { }
|
||||
''',
|
||||
[error(diag.removedLintUse, 11, 15)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,16 @@
|
||||
|
||||
import 'package:analyzer/analysis_rule/analysis_rule.dart';
|
||||
import 'package:analyzer/analysis_rule/rule_state.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart'
|
||||
as diag
|
||||
hide removedLint;
|
||||
import 'package:analyzer/src/test_utilities/lint_registration_mixin.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(ReplacedLintUseTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,44 +50,31 @@ linter:
|
||||
}
|
||||
|
||||
test_file() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore_for_file: removed_lint
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.replacedLintUse] 'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'.
|
||||
|
||||
void f() { }
|
||||
''',
|
||||
[error(diag.replacedLintUse, 20, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_line() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore: removed_lint
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.replacedLintUse] 'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'.
|
||||
void f() { }
|
||||
''',
|
||||
[error(diag.replacedLintUse, 11, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_messageText() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// ignore_for_file: removed_lint
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.replacedLintUse] 'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'.
|
||||
|
||||
void f() { }
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.replacedLintUse,
|
||||
20,
|
||||
12,
|
||||
messageContains: [
|
||||
"'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'",
|
||||
],
|
||||
correctionContains: "Replace 'removed_lint' with 'replacing_lint'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(RethrowOutsideCatchTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class RethrowOutsideCatchTest extends PubPackageResolutionTest {
|
||||
test_insideCatch() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
try {} catch (e) {
|
||||
rethrow;
|
||||
@@ -26,22 +27,21 @@ void f() {
|
||||
}
|
||||
|
||||
test_insideCatch_insideClosure() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
try {} catch (e) {
|
||||
() {
|
||||
rethrow;
|
||||
// ^^^^^^^
|
||||
// [diag.rethrowOutsideCatch] A rethrow must be inside of a catch clause.
|
||||
};
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.rethrowOutsideCatch, 47, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_insideCatch_insideClosure_insideCatch() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
try {} catch (e1) {
|
||||
() {
|
||||
@@ -55,14 +55,13 @@ void f() {
|
||||
}
|
||||
|
||||
test_withoutCatch() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
rethrow;
|
||||
//^^^^^^^
|
||||
// [diag.rethrowOutsideCatch] A rethrow must be inside of a catch clause.
|
||||
}
|
||||
''',
|
||||
[error(diag.rethrowOutsideCatch, 13, 7)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleRethrowExpression;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -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(ReturnInGenerativeConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnInGenerativeConstructorTest extends PubPackageResolutionTest {
|
||||
test_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() { return 0; }
|
||||
// ^
|
||||
// [diag.returnInGenerativeConstructor] Constructors can't return values.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnInGenerativeConstructor, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_expressionFunctionBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() => A();
|
||||
// ^^^^^^^
|
||||
// [diag.returnInGenerativeConstructor] Constructors can't return values.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnInGenerativeConstructor, 16, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_return_without_value() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() { return; }
|
||||
}
|
||||
|
||||
@@ -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(ReturnInGeneratorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnInGeneratorTest extends PubPackageResolutionTest {
|
||||
test_async() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async {
|
||||
return 0;
|
||||
}
|
||||
@@ -24,18 +25,17 @@ f() async {
|
||||
}
|
||||
|
||||
test_asyncStar_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async* {
|
||||
return 0;
|
||||
//^^^^^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnInGenerator, 15, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_asyncStar_blockBody_noValue() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Stream<int> f() async* {
|
||||
return;
|
||||
}
|
||||
@@ -43,16 +43,15 @@ Stream<int> f() async* {
|
||||
}
|
||||
|
||||
test_asyncStar_expressionBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() async* => 0;
|
||||
''',
|
||||
[error(diag.returnInGenerator, 11, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
''');
|
||||
}
|
||||
|
||||
test_sync() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
return 0;
|
||||
}
|
||||
@@ -60,18 +59,17 @@ f() {
|
||||
}
|
||||
|
||||
test_syncStar_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() sync* {
|
||||
return 0;
|
||||
//^^^^^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnInGenerator, 14, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_syncStar_blockBody_noValue() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Iterable<int> f() sync* {
|
||||
return;
|
||||
}
|
||||
@@ -79,11 +77,10 @@ Iterable<int> f() sync* {
|
||||
}
|
||||
|
||||
test_syncStar_expressionBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() sync* => 0;
|
||||
''',
|
||||
[error(diag.returnInGenerator, 10, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ReturnOfDoNotStoreInTestsTest);
|
||||
defineReflectiveTests(ReturnOfDoNotStoreTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ class ReturnOfDoNotStoreInTestsTest 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';
|
||||
|
||||
@doNotStore
|
||||
@@ -57,8 +58,8 @@ class ReturnOfDoNotStoreTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
// TODO(srawlins): We should report `returnOfDoNotStore`.
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -67,19 +68,15 @@ class A {
|
||||
|
||||
String getA() {
|
||||
return A();
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromMethod] A value of type 'A' can't be returned from the method 'getA' because it has a return type of 'String'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.returnOfInvalidTypeFromMethod, 95, 3),
|
||||
// TODO(srawlins): We should report `returnOfDoNotStore`.
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnFromClosureInFunction() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -87,16 +84,15 @@ String get _v => '';
|
||||
|
||||
String f() {
|
||||
var v = () => _v;
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'f' is also annotated.
|
||||
return v();
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfDoNotStore, 97, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnFromFunction() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -104,23 +100,21 @@ String get v => '';
|
||||
|
||||
String getV() {
|
||||
return v;
|
||||
// ^
|
||||
// [diag.returnOfDoNotStore] 'v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV' is also annotated.
|
||||
}
|
||||
|
||||
String getV2() => v;
|
||||
// ^
|
||||
// [diag.returnOfDoNotStore] 'v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV2' is also annotated.
|
||||
|
||||
@doNotStore
|
||||
String getV3() => v;
|
||||
''',
|
||||
[
|
||||
error(diag.returnOfDoNotStore, 92, 1, messageContains: ['getV']),
|
||||
error(diag.returnOfDoNotStore, 116, 1, messageContains: ['getV2']),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnFromGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -128,23 +122,21 @@ String get _v => '';
|
||||
|
||||
String get v {
|
||||
return _v;
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated.
|
||||
}
|
||||
|
||||
String get v2 => _v;
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v2' is also annotated.
|
||||
|
||||
@doNotStore
|
||||
String get v3 => _v;
|
||||
''',
|
||||
[
|
||||
error(diag.returnOfDoNotStore, 92, 2, messageContains: ['v']),
|
||||
error(diag.returnOfDoNotStore, 116, 2, messageContains: ['v2']),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnFromGetter_binaryExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -154,16 +146,15 @@ String? get _v => '';
|
||||
String? get _v2 => '';
|
||||
|
||||
String? get v => _v ?? _v2;
|
||||
''',
|
||||
[
|
||||
error(diag.returnOfDoNotStore, 122, 2, messageContains: ['_v']),
|
||||
error(diag.returnOfDoNotStore, 128, 3, messageContains: ['_v2']),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated.
|
||||
// ^^^
|
||||
// [diag.returnOfDoNotStore] '_v2' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated.
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnFromGetter_library() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
@doNotStore
|
||||
import 'package:meta/meta.dart';
|
||||
int get foo => 0;
|
||||
@@ -172,8 +163,7 @@ int get bar => foo;
|
||||
}
|
||||
|
||||
test_returnFromGetter_ternary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -185,17 +175,15 @@ String get _v2 => '';
|
||||
var b = true;
|
||||
|
||||
String get v => b ? _v : _v2;
|
||||
''',
|
||||
[
|
||||
error(diag.returnOfDoNotStore, 138, 2),
|
||||
error(diag.returnOfDoNotStore, 143, 3),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated.
|
||||
// ^^^
|
||||
// [diag.returnOfDoNotStore] '_v2' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated.
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnFromMethod() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -204,23 +192,22 @@ class A {
|
||||
|
||||
String getV() {
|
||||
return _v;
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV' is also annotated.
|
||||
}
|
||||
|
||||
String getV2() => _v;
|
||||
// ^^
|
||||
// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV2' is also annotated.
|
||||
|
||||
@doNotStore
|
||||
String getV3() => _v;
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.returnOfDoNotStore, 111, 2, messageContains: ['getV']),
|
||||
error(diag.returnOfDoNotStore, 140, 2, messageContains: ['getV2']),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_awaitExpression() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
void get f async => await v;
|
||||
|
||||
+41
-47
@@ -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(ReturnOfInvalidTypeForCatchErrorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnOfInvalidTypeForCatchErrorTest extends PubPackageResolutionTest {
|
||||
test_async_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) async => 0);
|
||||
}
|
||||
@@ -24,20 +25,19 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_async_emptyReturn_nonVoid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) async {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 69, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_blockFunctionBody_async_emptyReturn_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((e, st) async {
|
||||
return;
|
||||
@@ -47,7 +47,7 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_emptyReturn_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<dynamic> future) {
|
||||
future.catchError((e, st) {
|
||||
return;
|
||||
@@ -57,20 +57,19 @@ void f(Future<dynamic> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_emptyReturn_nonVoid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 63, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_blockFunctionBody_emptyReturn_Null() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<Null> future) {
|
||||
future.catchError((e, st) {
|
||||
return;
|
||||
@@ -80,7 +79,7 @@ void f(Future<Null> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_emptyReturn_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((e, st) {
|
||||
return;
|
||||
@@ -90,24 +89,23 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) {
|
||||
if (1 == 2) {
|
||||
return 7;
|
||||
} else {
|
||||
return 0.5;
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromCatchError] A value of type 'double' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<int>'.
|
||||
}
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromCatchError, 119, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_blockFunctionBody_withLocalFunction_expression_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) {
|
||||
double g() => 0.5;
|
||||
@@ -119,7 +117,7 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_withLocalFunction_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) {
|
||||
double g() {
|
||||
@@ -133,18 +131,17 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_expressionFunctionBody_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) => 'c');
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromCatchError] A value of type 'String' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<int>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromCatchError, 60, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_Null_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<Null> future) {
|
||||
future.catchError((e, st) => null);
|
||||
}
|
||||
@@ -152,7 +149,7 @@ void f(Future<Null> future) {
|
||||
}
|
||||
|
||||
test_Null_voidReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<Null> future, void Function() g) {
|
||||
future.catchError((e, st) => g());
|
||||
}
|
||||
@@ -160,31 +157,29 @@ void f(Future<Null> future, void Function() g) {
|
||||
}
|
||||
|
||||
test_nullableType_emptyReturn() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int?> future) {
|
||||
future.catchError((e, st) {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 64, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullableType_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int?> future) {
|
||||
future.catchError((e, st) => '');
|
||||
// ^^
|
||||
// [diag.returnOfInvalidTypeFromCatchError] A value of type 'String' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<int?>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromCatchError, 61, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.catchError((e, st) => 0);
|
||||
}
|
||||
@@ -192,7 +187,7 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_void_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((e, st) => 0);
|
||||
}
|
||||
@@ -200,13 +195,12 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
test_voidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, void Function() g) {
|
||||
future.catchError((e, st) => g());
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromCatchError] A value of type 'void' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<int>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromCatchError, 79, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(ReturnOfInvalidTypeForThenTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnOfInvalidTypeForThenTest extends PubPackageResolutionTest {
|
||||
test_blockFunctionBody_async_emptyReturn_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then<dynamic>((_) => 0, onError: (e, st) async {
|
||||
return;
|
||||
@@ -26,33 +27,31 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_async_emptyReturn_nonVoid() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then<int>((_) => 0, onError: (e, st) async {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 87, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_blockFunctionBody_async_emptyReturn_nullable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then<int?>((_) => 0, onError: (e, st) async {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 88, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_blockFunctionBody_async_emptyReturn_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.then<void>((_) => 0, onError: (e, st) async {
|
||||
return;
|
||||
@@ -62,24 +61,23 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
test_blockFunctionBody_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then((_) => 0, onError: (e, st) {
|
||||
if (1 == 2) {
|
||||
return 7;
|
||||
} else {
|
||||
return 0.5;
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromThen] A value of type 'double' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<int>', as required by 'Future.then'.
|
||||
}
|
||||
});
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromThen, 132, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_blockFunctionBody_void_objectQuestionReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then<void>((_) {}, onError: (e, st) {
|
||||
return Future<Object?>.error(0.5);
|
||||
@@ -89,18 +87,17 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_expressionFunctionBody_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then((_) => 0, onError: (e, st) => 'c');
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromThen] A value of type 'String' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<int>', as required by 'Future.then'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromThen, 73, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_expressionFunctionBody_Null_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then<Null>((_) => null, onError: (e, st) => null);
|
||||
}
|
||||
@@ -108,7 +105,7 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_expressionFunctionBody_Null_voidReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, void Function(dynamic, StackTrace) callback) {
|
||||
future.then<Null>((_) => null, onError: callback);
|
||||
}
|
||||
@@ -116,7 +113,7 @@ void f(Future<int> future, void Function(dynamic, StackTrace) callback) {
|
||||
}
|
||||
|
||||
test_expressionFunctionBody_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then((_) => 0, onError: (e, st) => 0);
|
||||
}
|
||||
@@ -124,7 +121,7 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_expressionFunctionBody_void_okReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future) {
|
||||
future.then<void>((_) => 0, onError: (e, st) => 0);
|
||||
}
|
||||
@@ -132,7 +129,7 @@ void f(Future<int> future) {
|
||||
}
|
||||
|
||||
test_referencedFunction_FutureOfNull_voidReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, void Function(dynamic, StackTrace) callback) {
|
||||
future.then<Null>((_) => null, onError: callback);
|
||||
}
|
||||
@@ -140,7 +137,7 @@ void f(Future<int> future, void Function(dynamic, StackTrace) callback) {
|
||||
}
|
||||
|
||||
test_referencedFunction_FutureOfNull_voidReturnType2() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, void Function() callback) {
|
||||
future.then<Null>((_) => null, onError: (_, _) => callback());
|
||||
}
|
||||
@@ -148,18 +145,17 @@ void f(Future<int> future, void Function() callback) {
|
||||
}
|
||||
|
||||
test_referencedFunction_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, double Function(dynamic, StackTrace) callback) {
|
||||
future.then((_) => 0, onError: callback);
|
||||
// ^^^^^^^^
|
||||
// [diag.returnTypeInvalidForThen] The return type 'double' isn't assignable to 'FutureOr<int>', as required by 'Future.then'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnTypeInvalidForThen, 109, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_referencedFunction_void_voidReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<Object?> Function(dynamic, StackTrace) callback) {
|
||||
future.then<void>((_) {}, onError: callback);
|
||||
}
|
||||
|
||||
@@ -6,52 +6,51 @@ 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(ReturnOfInvalidTypeTest);
|
||||
defineReflectiveTests(ReturnOfInvalidTypeWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnOfInvalidTypeTest extends PubPackageResolutionTest {
|
||||
test_closure() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef Td = int Function();
|
||||
Td f() {
|
||||
return () => "hello";
|
||||
// ^^^^^^^
|
||||
// [diag.returnOfInvalidTypeFromClosure] The returned type 'String' isn't returnable from a 'int' function, as required by the closure's context.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromClosure, 53, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factoryConstructor_named() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
factory C.named() => 7;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromConstructor] A value of type 'int' can't be returned from the constructor 'C.named' because it has a return type of 'C'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromConstructor, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factoryConstructor_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
factory C() => 7;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromConstructor] A value of type 'int' can't be returned from the constructor 'C' because it has a return type of 'C'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromConstructor, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block__to_Future_void() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<void> f1() async {}
|
||||
Future<void> f2() async { return; }
|
||||
Future<void> f3() async { return null; }
|
||||
@@ -63,47 +62,43 @@ void g2() {}
|
||||
}
|
||||
|
||||
test_function_async_block_Future_Future_int__to_Future_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> f(Future<Future<int>> a) async {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Future<Future<int>>' can't be returned from the function 'f' because it has a return type of 'Future<int>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 54, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_Future_String__to_Future_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> f(Future<String> a) async {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Future<String>' can't be returned from the function 'f' because it has a return type of 'Future<int>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 49, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_Future_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f1(Future<void> a) async { return a; }
|
||||
dynamic f2(Future<void> a) async { return a; }
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_illegalReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f() async {
|
||||
// [diag.illegalAsyncReturnType][column 1][length 3] Functions marked 'async' must have a return type which is a supertype of 'Future'.
|
||||
return 5;
|
||||
}
|
||||
''',
|
||||
[error(diag.illegalAsyncReturnType, 0, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_int__to_Future_int() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> f() async {
|
||||
return 0;
|
||||
}
|
||||
@@ -111,7 +106,7 @@ Future<int> f() async {
|
||||
}
|
||||
|
||||
test_function_async_block_int__to_Future_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<num> f() async {
|
||||
return 0;
|
||||
}
|
||||
@@ -119,40 +114,37 @@ Future<num> f() async {
|
||||
}
|
||||
|
||||
test_function_async_block_int__to_Future_String() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<String> f() async {
|
||||
return 5;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'Future<String>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_int__to_Future_void() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<void> f() async {
|
||||
return 0;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'Future<void>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_int__to_void() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() async {
|
||||
return 5;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'void'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_void__to_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
dynamic f(void a) async {
|
||||
return a;
|
||||
}
|
||||
@@ -160,42 +152,39 @@ dynamic f(void a) async {
|
||||
}
|
||||
|
||||
test_function_async_block_void__to_Future_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> f(void a) async {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'Future<int>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 39, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_void__to_Future_Null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<Null> f(void a) async {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'Future<Null>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_void__to_FutureOr_ObjectQ() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
|
||||
FutureOr<Object?> f(void a) async {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'FutureOr<Object?>'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 67, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_void__to_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(void a) async {
|
||||
return a;
|
||||
}
|
||||
@@ -203,36 +192,32 @@ void f(void a) async {
|
||||
}
|
||||
|
||||
test_function_async_expression_dynamic__to_Future_int() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> f(dynamic a) async => a;
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_asyncStar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
// RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error.
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Stream<int> f() async* => 3;
|
||||
''',
|
||||
[
|
||||
// RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error.
|
||||
error(diag.returnInGenerator, 23, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block__invalidType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
return new X();
|
||||
// ^
|
||||
// [diag.newWithNonType] The name 'X' isn't a class.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithNonType, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block__to_dynamic() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
try {
|
||||
return 0;
|
||||
@@ -244,7 +229,7 @@ f() {
|
||||
}
|
||||
|
||||
test_function_sync_block__to_void() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f1() {}
|
||||
void f2() { return; }
|
||||
void f3() { return null; }
|
||||
@@ -256,7 +241,7 @@ void g2() {}
|
||||
}
|
||||
|
||||
test_function_sync_block_genericFunction__to_genericFunction() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
U Function<U>(U) foo(T Function<T>(T a) f) {
|
||||
return f;
|
||||
}
|
||||
@@ -264,18 +249,17 @@ U Function<U>(U) foo(T Function<T>(T a) f) {
|
||||
}
|
||||
|
||||
test_function_sync_block_genericFunction__to_genericFunction_notAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
U Function<U>(U, int) foo(T Function<T>(T a) f) {
|
||||
return f;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'T Function<T>(T)' can't be returned from the function 'foo' because it has a return type of 'U Function<U>(U, int)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 59, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_genericFunction__to_nonGenericFunction() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int Function(int) foo(T Function<T>(T a) f) {
|
||||
return f;
|
||||
}
|
||||
@@ -283,18 +267,17 @@ int Function(int) foo(T Function<T>(T a) f) {
|
||||
}
|
||||
|
||||
test_function_sync_block_genericFunction__to_nonGenericFunction_notAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int Function(int, int) foo(T Function<T>(T a) f) {
|
||||
return f;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'dynamic Function(dynamic)' can't be returned from the function 'foo' because it has a return type of 'int Function(int, int)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 60, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_int__to_num() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
num f(int a) {
|
||||
return a;
|
||||
}
|
||||
@@ -302,36 +285,33 @@ num f(int a) {
|
||||
}
|
||||
|
||||
test_function_sync_block_int__to_void() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
return 42;
|
||||
// ^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'void'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 20, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_num__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f(num a) {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'num' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f() {
|
||||
return '0';
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 19, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_typeParameter__to_Type() async {
|
||||
@@ -345,7 +325,7 @@ int f() {
|
||||
// returned out of the TestTypeProvider don't have a mock 'dart.core'
|
||||
// enclosing library element.
|
||||
// See TypeParameterTypeImpl.isMoreSpecificThan().
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class Foo<T> {
|
||||
Type get t => T;
|
||||
}
|
||||
@@ -353,7 +333,7 @@ class Foo<T> {
|
||||
}
|
||||
|
||||
test_function_sync_block_void__to_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
dynamic f(void a) {
|
||||
return a;
|
||||
}
|
||||
@@ -361,29 +341,27 @@ dynamic f(void a) {
|
||||
}
|
||||
|
||||
test_function_sync_block_void__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f(void a) {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_void__to_Null() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Null f(void a) {
|
||||
return a;
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'Null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_block_void__to_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(void a) {
|
||||
return a;
|
||||
}
|
||||
@@ -391,64 +369,58 @@ void f(void a) {
|
||||
}
|
||||
|
||||
test_function_sync_expression_genericFunction__to_genericFunction() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
U Function<U>(U) foo(T Function<T>(T a) f) => f;
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_expression_genericFunction__to_genericFunction_notAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
U Function<U>(U, int) foo(T Function<T>(T a) f) => f;
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'T Function<T>(T)' can't be returned from the function 'foo' because it has a return type of 'U Function<U>(U, int)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_expression_genericFunction__to_nonGenericFunction() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int Function(int) foo(T Function<T>(T a) f) => f;
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_expression_genericFunction__to_nonGenericFunction_notAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int Function(int, int) foo(T Function<T>(T a) f) => f;
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'dynamic Function(dynamic)' can't be returned from the function 'foo' because it has a return type of 'int Function(int, int)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_expression_int__to_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() => 42;
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_sync_expression_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f() => '0';
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 11, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_syncStar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
// RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error.
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Iterable<int> f() sync* => 3;
|
||||
''',
|
||||
[
|
||||
// RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error.
|
||||
error(diag.returnInGenerator, 24, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier.
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionExpression_async_futureOr_void__to_Object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void a = null;
|
||||
|
||||
Object Function() f = () async {
|
||||
@@ -458,7 +430,7 @@ Object Function() f = () async {
|
||||
}
|
||||
|
||||
test_functionExpression_async_futureQ_void__to_Object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<void>? a = (throw 0);
|
||||
|
||||
Object Function() f = () async {
|
||||
@@ -468,7 +440,7 @@ Object Function() f = () async {
|
||||
}
|
||||
|
||||
test_functionExpression_async_void__to_FutureOr_ObjectQ() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
|
||||
void a = (throw 0);
|
||||
@@ -480,55 +452,51 @@ FutureOr<Object?> Function() f = () async {
|
||||
}
|
||||
|
||||
test_getter_sync_block_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int get g {
|
||||
return '0';
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'g' because it has a return type of 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 21, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_getter_sync_expression_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int get g => '0';
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 13, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'g' because it has a return type of 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_localFunction_sync_block_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
int g() {
|
||||
return '0';
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'g' because it has a return type of 'int'.
|
||||
}
|
||||
g();
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 34, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localFunction_sync_expression_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void m() {
|
||||
int f() => '0';
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
f();
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 38, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_async_block_callable_class() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef Fn = void Function(String s);
|
||||
|
||||
class CanFn {
|
||||
@@ -542,20 +510,19 @@ Future<Fn> f() async {
|
||||
}
|
||||
|
||||
test_method_sync_block_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int m() {
|
||||
return '0';
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromMethod] A value of type 'String' can't be returned from the method 'm' because it has a return type of 'int'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromMethod, 33, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_sync_expression_generic() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class F<T> {
|
||||
T get value;
|
||||
}
|
||||
@@ -567,23 +534,21 @@ abstract class G<U> {
|
||||
}
|
||||
|
||||
test_method_sync_expression_String__to_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int f() => '0';
|
||||
// ^^^
|
||||
// [diag.returnOfInvalidTypeFromMethod] A value of type 'String' can't be returned from the method 'f' because it has a return type of 'int'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromMethod, 23, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_spread_iterable_in_map_context() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Map<int, int> f() => {...[1, 2, 3, 4]};
|
||||
''',
|
||||
[error(diag.returnOfInvalidTypeFromFunction, 21, 17)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Set<int>' can't be returned from the function 'f' because it has a return type of 'Map<int, int>'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(ReturnTypeInvalidForCatchErrorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnTypeInvalidForCatchErrorTest extends PubPackageResolutionTest {
|
||||
test_dynamic_returnTypeIsUnrelatedFuture() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(
|
||||
Future<dynamic> future, Future<String> Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
@@ -25,7 +26,7 @@ void f(
|
||||
}
|
||||
|
||||
test_dynamic_unrelatedReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<dynamic> future, String Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
}
|
||||
@@ -33,18 +34,17 @@ void f(Future<dynamic> future, String Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, String Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
// ^^
|
||||
// [diag.returnTypeInvalidForCatchError] The return type 'String' isn't assignable to 'FutureOr<int>', as required by 'Future.catchError'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnTypeInvalidForCatchError, 90, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_Null_returnTypeIsVoid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<Null> future, void Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
}
|
||||
@@ -52,18 +52,17 @@ void f(Future<Null> future, void Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_nullableReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, String? Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
// ^^
|
||||
// [diag.returnTypeInvalidForCatchError] The return type 'String?' isn't assignable to 'FutureOr<int>', as required by 'Future.catchError'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnTypeInvalidForCatchError, 91, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnTypeIsFuture() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
}
|
||||
@@ -71,7 +70,7 @@ void f(Future<int> future, Future<int> Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_returnTypeIsFutureOr() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(Future<int> future, FutureOr<int> Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
@@ -80,7 +79,7 @@ void f(Future<int> future, FutureOr<int> Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_sameReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, int Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
}
|
||||
@@ -88,7 +87,7 @@ void f(Future<int> future, int Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_void_returnTypeIsUnrelatedFuture() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, Future<String> Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
}
|
||||
@@ -96,7 +95,7 @@ void f(Future<void> future, Future<String> Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_void_unrelatedReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, String Function(dynamic, StackTrace) cb) {
|
||||
future.catchError(cb);
|
||||
}
|
||||
|
||||
@@ -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(ReturnTypeInvalidForThenTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnTypeInvalidForThenTest extends PubPackageResolutionTest {
|
||||
test_dynamic_returnTypeIsUnrelatedFuture() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(
|
||||
Future<int> future, Future<String> Function(dynamic, StackTrace) cb) {
|
||||
future.then<dynamic>((_) => 1, onError: cb);
|
||||
@@ -25,7 +26,7 @@ void f(
|
||||
}
|
||||
|
||||
test_dynamic_unrelatedReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, String Function(dynamic, StackTrace) cb) {
|
||||
future.then<dynamic>((_) => 1, onError: cb);
|
||||
}
|
||||
@@ -33,29 +34,27 @@ void f(Future<int> future, String Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_invalidReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, String Function(dynamic, StackTrace) cb) {
|
||||
future.then<int>((_) => 1, onError: cb);
|
||||
// ^^
|
||||
// [diag.returnTypeInvalidForThen] The return type 'String' isn't assignable to 'FutureOr<int>', as required by 'Future.then'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnTypeInvalidForThen, 108, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullableReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, int? Function(dynamic, StackTrace) cb) {
|
||||
future.then((_) => 1, onError: cb);
|
||||
// ^^
|
||||
// [diag.returnTypeInvalidForThen] The return type 'int?' isn't assignable to 'FutureOr<int>', as required by 'Future.then'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnTypeInvalidForThen, 101, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnTypeIsFuture() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, Future<int> Function(dynamic, StackTrace) cb) {
|
||||
future.then<int>((_) => 1, onError: cb);
|
||||
}
|
||||
@@ -63,7 +62,7 @@ void f(Future<int> future, Future<int> Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_returnTypeIsFutureOr() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
void f(Future<int> future, FutureOr<int> Function(dynamic, StackTrace) cb) {
|
||||
future.then<int>((_) => 1, onError: cb);
|
||||
@@ -72,18 +71,17 @@ void f(Future<int> future, FutureOr<int> Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_returnTypeIsVoid_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, void Function(dynamic, StackTrace) cb) {
|
||||
future.then<int>((_) => 1, onError: cb);
|
||||
// ^^
|
||||
// [diag.returnTypeInvalidForThen] The return type 'void' isn't assignable to 'FutureOr<int>', as required by 'Future.then'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnTypeInvalidForThen, 106, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnTypeIsVoid_nullableInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, void Function(dynamic, StackTrace) cb) {
|
||||
future.then<int?>((_) => 1, onError: cb);
|
||||
}
|
||||
@@ -91,7 +89,7 @@ void f(Future<int> future, void Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_sameReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<int> future, int Function(dynamic, StackTrace) cb) {
|
||||
future.then<int>((_) => 1, onError: cb);
|
||||
}
|
||||
@@ -99,7 +97,7 @@ void f(Future<int> future, int Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_void_returnTypeIsUnrelatedFuture() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, Future<String> Function(dynamic, StackTrace) cb) {
|
||||
future.then<void>((_) => 1, onError: cb);
|
||||
}
|
||||
@@ -107,7 +105,7 @@ void f(Future<void> future, Future<String> Function(dynamic, StackTrace) cb) {
|
||||
}
|
||||
|
||||
test_void_unrelatedReturnType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future, String Function(dynamic, StackTrace) cb) {
|
||||
future.then<void>((_) => 1, onError: cb);
|
||||
}
|
||||
|
||||
@@ -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(ReturnWithoutValueTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReturnWithoutValueTest extends PubPackageResolutionTest {
|
||||
test_async_futureInt() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> f() async {
|
||||
return;
|
||||
//^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 26, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_async_futureObject() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<Object> f() async {
|
||||
return;
|
||||
//^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 29, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_catchError_futureOfVoid() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Future<void> future) {
|
||||
future.catchError((e) {
|
||||
return;
|
||||
@@ -48,31 +47,29 @@ void f(Future<void> future) {
|
||||
}
|
||||
|
||||
test_factoryConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 30, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f() {
|
||||
return;
|
||||
//^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 12, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_async_block_empty__to_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
dynamic f() async {
|
||||
return;
|
||||
}
|
||||
@@ -82,7 +79,7 @@ dynamic f() async {
|
||||
test_function_Null() async {
|
||||
// Test that block bodied functions with return type Null and an empty
|
||||
// return cause a static warning.
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Null f() {
|
||||
return;
|
||||
}
|
||||
@@ -90,7 +87,7 @@ Null f() {
|
||||
}
|
||||
|
||||
test_function_sync_block_empty__to_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
dynamic f() {
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +95,7 @@ dynamic f() {
|
||||
}
|
||||
|
||||
test_function_sync_block_empty__to_Null() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Null f() {
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +103,7 @@ Null f() {
|
||||
}
|
||||
|
||||
test_function_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
return;
|
||||
}
|
||||
@@ -114,23 +111,22 @@ void f() {
|
||||
}
|
||||
|
||||
test_functionExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
return (int y) {
|
||||
if (y < 0) {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 48, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionExpression_async_block_empty__to_Object() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Object Function() f = () async {
|
||||
return;
|
||||
};
|
||||
@@ -138,31 +134,29 @@ Object Function() f = () async {
|
||||
}
|
||||
|
||||
test_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int m() {
|
||||
return;
|
||||
// ^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 26, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_multipleInconsistentReturns() async {
|
||||
// Tests that only the RETURN_WITHOUT_VALUE warning is created, and no
|
||||
// MIXED_RETURN_TYPES are created.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int f(int x) {
|
||||
if (x < 0) {
|
||||
return 1;
|
||||
}
|
||||
return;
|
||||
//^^^^^^
|
||||
// [diag.returnWithoutValue] The return value is missing after 'return'.
|
||||
}
|
||||
''',
|
||||
[error(diag.returnWithoutValue, 50, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/utilities/utilities.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
import 'sdk_constraint_verifier_support.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SdkVersionGtGtGtOperatorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,23 +24,24 @@ class SdkVersionGtGtGtOperatorTest extends SdkConstraintVerifierTest {
|
||||
'${ExperimentStatus.currentVersion.minor}';
|
||||
|
||||
test_const_equals() async {
|
||||
await verifyVersion('>=2.15.0', '''
|
||||
writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0'));
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const a = 42 >>> 3;
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_lessThan() async {
|
||||
await verifyVersion(
|
||||
'>=2.13.0',
|
||||
'''
|
||||
writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.13.0'));
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const a = 42 >>> 3;
|
||||
''',
|
||||
expectedDiagnostics: [error(diag.sdkVersionGtGtGtOperator, 13, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.sdkVersionGtGtGtOperator] The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions.
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaration_equals() async {
|
||||
await verifyVersion('>=2.15.0', '''
|
||||
writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0'));
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A operator >>>(A a) => this;
|
||||
}
|
||||
@@ -46,30 +49,29 @@ class A {
|
||||
}
|
||||
|
||||
test_declaration_lessThan() async {
|
||||
await verifyVersion(
|
||||
'>=2.13.0',
|
||||
'''
|
||||
writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.13.0'));
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A operator >>>(A a) => this;
|
||||
// ^^^
|
||||
// [diag.sdkVersionGtGtGtOperator] The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions.
|
||||
}
|
||||
''',
|
||||
expectedDiagnostics: [error(diag.sdkVersionGtGtGtOperator, 23, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_equals() async {
|
||||
await verifyVersion('>=2.15.0', '''
|
||||
writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0'));
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var a = 42 >>> 3;
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_lessThan() async {
|
||||
await verifyVersion(
|
||||
'>=2.13.0',
|
||||
'''
|
||||
writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.13.0'));
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var a = 42 >>> 3;
|
||||
''',
|
||||
expectedDiagnostics: [error(diag.sdkVersionGtGtGtOperator, 11, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.sdkVersionGtGtGtOperator] The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+67
-83
@@ -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(SealedClassSubtypeOutsideOfLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SealedClassSubtypeOutsideOfLibraryTest extends PubPackageResolutionTest {
|
||||
test_extends_sealed_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class Foo {}
|
||||
class Bar extends Foo {}
|
||||
''');
|
||||
@@ -27,13 +28,12 @@ class Bar extends Foo {}
|
||||
sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar extends Foo {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 37, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extends_sealed_outside_viaTypedef_inside() async {
|
||||
@@ -42,13 +42,12 @@ sealed class Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar extends FooTypedef {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 37, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extends_sealed_outside_viaTypedef_outside() async {
|
||||
@@ -56,14 +55,13 @@ class Bar extends FooTypedef {}
|
||||
sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
class Bar extends FooTypedef {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 63, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extends_subtypeOfSealed_outside() async {
|
||||
@@ -72,14 +70,14 @@ sealed class Foo {}
|
||||
class Bar extends Foo {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar2 extends Bar {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_sealed_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class Foo {}
|
||||
class Bar implements Foo {}
|
||||
''');
|
||||
@@ -90,13 +88,12 @@ class Bar implements Foo {}
|
||||
sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 40, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_sealed_outside_mixin() async {
|
||||
@@ -104,13 +101,12 @@ class Bar implements Foo {}
|
||||
sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
mixin Bar implements Foo {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 40, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_sealed_outside_viaTypedef_inside() async {
|
||||
@@ -119,13 +115,12 @@ sealed class Foo {}
|
||||
typedef FooTypedef = Foo;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 40, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_sealed_outside_viaTypedef_outside() async {
|
||||
@@ -133,14 +128,13 @@ class Bar implements FooTypedef {}
|
||||
sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
typedef FooTypedef = Foo;
|
||||
class Bar implements FooTypedef {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 66, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_subtypeOfSealed_outside() async {
|
||||
@@ -149,7 +143,7 @@ sealed class Foo {}
|
||||
class Bar implements Foo {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar2 implements Bar {}
|
||||
''');
|
||||
@@ -161,13 +155,12 @@ base class Foo {}
|
||||
sealed class B extends Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
base class Bar extends B {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_induced_final_extends() async {
|
||||
@@ -176,13 +169,12 @@ final class Foo {}
|
||||
sealed class B extends Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
final class Bar extends B {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 43, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_induced_final_implements() async {
|
||||
@@ -191,13 +183,12 @@ final class Foo {}
|
||||
sealed class B extends Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
final class Bar implements B {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 46, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_induced_interface_extends() async {
|
||||
@@ -206,13 +197,12 @@ interface class Foo {}
|
||||
sealed class B extends Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar extends B {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 37, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinOutside_rawClass() async {
|
||||
@@ -220,27 +210,24 @@ class Bar extends B {}
|
||||
sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'foo.dart';
|
||||
class Bar with Foo {}
|
||||
''',
|
||||
[
|
||||
error(diag.classUsedAsMixin, 34, 3),
|
||||
error(diag.sealedClassSubtypeOutsideOfLibrary, 34, 3),
|
||||
],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.classUsedAsMixin] The class 'Foo' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_on_inside() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
mixin B on A {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_on_inside_multiple() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
sealed class B {}
|
||||
mixin C on A, B {}
|
||||
@@ -252,13 +239,12 @@ mixin C on A, B {}
|
||||
sealed class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
mixin B on A {}
|
||||
''',
|
||||
[error(diag.sealedClassSubtypeOutsideOfLibrary, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'A' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_on_outside_multiple() async {
|
||||
@@ -267,15 +253,13 @@ sealed class A {}
|
||||
sealed class B {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
mixin C on A, B {}
|
||||
''',
|
||||
[
|
||||
error(diag.sealedClassSubtypeOutsideOfLibrary, 28, 1),
|
||||
error(diag.sealedClassSubtypeOutsideOfLibrary, 31, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'A' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
// ^
|
||||
// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(SetElementFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,55 +19,51 @@ class SetElementFromDeferredLibraryTest extends PubPackageResolutionTest
|
||||
with SetElementFromDeferredLibraryTestCases {}
|
||||
|
||||
mixin SetElementFromDeferredLibraryTestCases on PubPackageResolutionTest {
|
||||
@failingTest
|
||||
@skippedTest
|
||||
test_const_ifElement_thenTrue_elseDeferred() async {
|
||||
// reports wrong error code
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const int c = 1;''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
const cond = true;
|
||||
var v = const {if (cond) null else a.c};
|
||||
''',
|
||||
[error(diag.setElementFromDeferredLibrary, 88, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_thenDeferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const int c = 1;''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
const cond = true;
|
||||
var v = const {if (cond) a.c};
|
||||
''',
|
||||
[error(diag.setElementFromDeferredLibrary, 80, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topLevel_deferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const int c = 1;''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
var v = const {a.c};
|
||||
''',
|
||||
[error(diag.setElementFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topLevel_deferred_nested() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const int c = 1;''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
var v = const {a.c + 1};
|
||||
''',
|
||||
[error(diag.setElementFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,20 @@ 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(SetElementTypeNotAssignableTest);
|
||||
defineReflectiveTests(SetElementTypeNotAssignableWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SetElementTypeNotAssignableTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = const <int>{if (1 < 0) a else b};
|
||||
@@ -25,121 +27,114 @@ var v = const <int>{if (1 < 0) a else b};
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 'b';
|
||||
var v = const <int>{if (1 < 0) a else b};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignable, 82, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = const <int>{if (1 < 0) 'a'};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignable, 31, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int>{if (1 < 0) a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 0;
|
||||
var v = const <int>{if (true) a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int>{if (true) a};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignable, 53, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 42;
|
||||
var v = const <int>{a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intInt_value() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = const <int>{42};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const a = null;
|
||||
var v = const <int>{a};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignableNullability, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = const <int>{null};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignableNullability, 20, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.setElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic x = 'abc';
|
||||
var v = const <int>{x};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignable, 45, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = const <int>{'abc'};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignable, 20, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = const <int>{...[0, 1]};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_stringQuestion_null_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const a = null;
|
||||
var v = const <String?>{a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_stringQuestion_null_value() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = const <String?>{null};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 'a';
|
||||
const dynamic b = 'b';
|
||||
var v = <int>{if (1 < 0) a else b};
|
||||
@@ -147,7 +142,7 @@ var v = <int>{if (1 < 0) a else b};
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = <int>{if (1 < 0) a else b};
|
||||
@@ -155,48 +150,46 @@ var v = <int>{if (1 < 0) a else b};
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenFalse_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = <int>[if (1 < 0) 'a'];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 25, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 'a';
|
||||
var v = <int>{if (true) a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic a = 0;
|
||||
var v = <int>{if (true) a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = <int>{...[0, 1]};
|
||||
''');
|
||||
}
|
||||
|
||||
test_notConst_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic x = 'abc';
|
||||
var v = <int>{x};
|
||||
''');
|
||||
}
|
||||
|
||||
test_notConst_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = <int>{'abc'};
|
||||
''',
|
||||
[error(diag.setElementTypeNotAssignable, 14, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(SharedDeferredPrefixTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,14 +25,13 @@ f1() {}
|
||||
library lib2;
|
||||
f2() {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as lib;
|
||||
// ^^^^^^^^
|
||||
// [diag.sharedDeferredPrefix] The prefix of a deferred import can't be used in other import directives.
|
||||
import 'lib2.dart' as lib;
|
||||
main() { lib.f1(); lib.f2(); }
|
||||
''',
|
||||
[error(diag.sharedDeferredPrefix, 33, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,63 +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(SizeAnnotationDimensions);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class SizeAnnotationDimensions extends PubPackageResolutionTest {
|
||||
test_error_array_2_3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
@Array(8, 8)
|
||||
//^^^^^^^^^^^^
|
||||
// [diag.sizeAnnotationDimensions] 'Array's must have an 'Array' annotation that matches the dimensions.
|
||||
external Array<Array<Array<Uint8>>> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.sizeAnnotationDimensions, 53, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_error_array_3_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
@Array(8, 8, 8)
|
||||
//^^^^^^^^^^^^^^^
|
||||
// [diag.sizeAnnotationDimensions] 'Array's must have an 'Array' annotation that matches the dimensions.
|
||||
external Array<Array<Uint8>> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.sizeAnnotationDimensions, 53, 15)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_error_multi_2_3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
@Array.multi([8, 8])
|
||||
//^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.sizeAnnotationDimensions] 'Array's must have an 'Array' annotation that matches the dimensions.
|
||||
external Array<Array<Array<Uint8>>> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.sizeAnnotationDimensions, 53, 20)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_no_error() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
|
||||
+20
-22
@@ -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(SpreadExpressionFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,20 +22,19 @@ mixin SpreadExpressionFromDeferredLibraryTestCases on PubPackageResolutionTest {
|
||||
test_inList_deferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const List c = [];''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
f() {
|
||||
return const [...a.c];
|
||||
}''',
|
||||
[error(diag.spreadExpressionFromDeferredLibrary, 61, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.spreadExpressionFromDeferredLibrary] Constant values from a deferred library can't be spread into a const literal.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_inList_deferred_notConst() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const List c = [];''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
f() {
|
||||
return [...a.c];
|
||||
@@ -44,7 +44,7 @@ f() {
|
||||
test_inList_notDeferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const List c = [];''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as a;
|
||||
f() {
|
||||
return const [...a.c];
|
||||
@@ -54,20 +54,19 @@ f() {
|
||||
test_inMap_deferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const Map c = <int, int>{};''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
f() {
|
||||
return const {...a.c};
|
||||
}''',
|
||||
[error(diag.spreadExpressionFromDeferredLibrary, 61, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.spreadExpressionFromDeferredLibrary] Constant values from a deferred library can't be spread into a const literal.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_inMap_notConst() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const Map c = <int, int>{};''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
f() {
|
||||
return {...a.c};
|
||||
@@ -77,7 +76,7 @@ f() {
|
||||
test_inMap_notDeferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const Map c = <int, int>{};''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as a;
|
||||
f() {
|
||||
return const {...a.c};
|
||||
@@ -87,20 +86,19 @@ f() {
|
||||
test_inSet_deferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const Set c = <int>{};''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
f() {
|
||||
return const {...a.c};
|
||||
}''',
|
||||
[error(diag.spreadExpressionFromDeferredLibrary, 61, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.spreadExpressionFromDeferredLibrary] Constant values from a deferred library can't be spread into a const literal.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_inSet_notConst() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const Set c = <int>{};''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
f() {
|
||||
return {...a.c};
|
||||
@@ -110,7 +108,7 @@ f() {
|
||||
test_inSet_notDeferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const Set c = <int>{};''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as a;
|
||||
f() {
|
||||
return const {...a.c};
|
||||
|
||||
@@ -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(StaticAccessToInstanceMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class StaticAccessToInstanceMemberTest extends PubPackageResolutionTest {
|
||||
test_annotation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.name();
|
||||
}
|
||||
@@ -27,126 +28,117 @@ main() {
|
||||
}
|
||||
|
||||
test_extension_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {
|
||||
int get g => 0;
|
||||
}
|
||||
f() {
|
||||
E.g;
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'g' can't be accessed using static access.
|
||||
}
|
||||
''',
|
||||
[error(diag.staticAccessToInstanceMember, 51, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {
|
||||
void m() {}
|
||||
}
|
||||
f() {
|
||||
E.m();
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'm' can't be accessed using static access.
|
||||
}
|
||||
''',
|
||||
[error(diag.staticAccessToInstanceMember, 47, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on int {
|
||||
void set s(int i) {}
|
||||
}
|
||||
f() {
|
||||
E.s = 2;
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 's' can't be accessed using static access.
|
||||
}
|
||||
''',
|
||||
[error(diag.staticAccessToInstanceMember, 56, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_invocation() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() {}
|
||||
}
|
||||
main() {
|
||||
A.m();
|
||||
}''',
|
||||
[error(diag.staticAccessToInstanceMember, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'm' can't be accessed using static access.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_method_reference() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m() {}
|
||||
}
|
||||
main() {
|
||||
A.m;
|
||||
}''',
|
||||
[error(diag.staticAccessToInstanceMember, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'm' can't be accessed using static access.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_propertyAccess_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
var f;
|
||||
}
|
||||
main() {
|
||||
A.f;
|
||||
}''',
|
||||
[error(diag.staticAccessToInstanceMember, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'f' can't be accessed using static access.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_propertyAccess_field_toplevel_generic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {
|
||||
List<T> t = [];
|
||||
}
|
||||
var x = C.t;
|
||||
''',
|
||||
[error(diag.staticAccessToInstanceMember, 43, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 't' can't be accessed using static access.
|
||||
''');
|
||||
}
|
||||
|
||||
test_propertyAccess_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
get f => 42;
|
||||
}
|
||||
main() {
|
||||
A.f;
|
||||
}''',
|
||||
[error(diag.staticAccessToInstanceMember, 40, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'f' can't be accessed using static access.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_propertyAccess_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set f(x) {}
|
||||
}
|
||||
main() {
|
||||
A.f = 42;
|
||||
}''',
|
||||
[error(diag.staticAccessToInstanceMember, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.staticAccessToInstanceMember] Instance member 'f' can't be accessed using static access.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_static_method() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static m() {}
|
||||
}
|
||||
@@ -158,7 +150,7 @@ main() {
|
||||
}
|
||||
|
||||
test_static_propertyAccess_field() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static var f;
|
||||
}
|
||||
@@ -170,7 +162,7 @@ main() {
|
||||
}
|
||||
|
||||
test_static_propertyAccess_propertyAccessor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static get f => 42;
|
||||
static set f(x) {}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/utilities/utilities.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(StrictRawTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,7 +26,7 @@ class StrictRawTypeTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_asExpression() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(dynamic x) {
|
||||
print(x as List);
|
||||
}
|
||||
@@ -33,7 +34,7 @@ void f(dynamic x) {
|
||||
}
|
||||
|
||||
test_asExpression_typeArgument() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(dynamic x) {
|
||||
print(x as List<List>);
|
||||
}
|
||||
@@ -41,7 +42,7 @@ void f(dynamic x) {
|
||||
}
|
||||
|
||||
test_castPattern() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f([(Object, )? l]) {
|
||||
var (_ as List, ) = l!;
|
||||
}
|
||||
@@ -49,7 +50,7 @@ void f([(Object, )? l]) {
|
||||
}
|
||||
|
||||
test_castPattern_typeArgument() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f([(Object, )? l]) {
|
||||
var (_ as List<List>, ) = l!;
|
||||
}
|
||||
@@ -59,7 +60,7 @@ void f([(Object, )? l]) {
|
||||
test_constantPattern() async {
|
||||
// This is not considered a "strict raw type" here, but a "strict inference"
|
||||
// issue.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(C<int> c) {
|
||||
switch (c) {
|
||||
case const C():
|
||||
@@ -74,7 +75,7 @@ class C<T> {
|
||||
|
||||
test_functionParts_optionalTypeArg() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@optionalTypeArgs
|
||||
class C<T> {}
|
||||
@@ -84,20 +85,19 @@ void g(C a) {}
|
||||
}
|
||||
|
||||
test_genericTypeArgument_extensionType_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E<T>(int i) {}
|
||||
|
||||
void f() {
|
||||
<List<E>>[];
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'E<dynamic>' should have explicit type arguments but doesn't.
|
||||
}
|
||||
''',
|
||||
[error(diag.strictRawType, 50, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericTypeArgument_extensionType_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E<T>(int i) {}
|
||||
|
||||
void f() {
|
||||
@@ -107,70 +107,64 @@ void f() {
|
||||
}
|
||||
|
||||
test_genericTypeArgument_extensionTypeImplements_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E(List<int> i) implements Iterable {}
|
||||
''',
|
||||
[error(diag.strictRawType, 41, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.strictRawType] The generic type 'Iterable<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericTypeArgument_extensionTypeImplementsExtensionType_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
|
||||
extension type E<T>(Iterable<T> i) {}
|
||||
|
||||
extension type F(List<int> j) implements E {}
|
||||
''',
|
||||
[error(diag.strictRawType, 81, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'E<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericTypeArgument_extensionTypeRepresentationType_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E(List i) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 17, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericTypeArgument_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
var a = <List>[];
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 17, 1),
|
||||
error(diag.strictRawType, 22, 4),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericTypeArgument_withTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
var a = <List<int>>[];
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 17, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_instanceCreation() async {
|
||||
// This is not considered a "strict raw type" here, but a "strict inference"
|
||||
// issue.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var c = List.empty();
|
||||
''');
|
||||
}
|
||||
|
||||
test_isExpression() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(dynamic x) {
|
||||
print(x is List);
|
||||
print(x is List<dynamic>);
|
||||
@@ -180,50 +174,45 @@ void f(dynamic x) {
|
||||
}
|
||||
|
||||
test_localVariable_extensionType_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E<T>(int i) {}
|
||||
|
||||
void f() {
|
||||
E e = E(1);
|
||||
//^
|
||||
// [diag.strictRawType] The generic type 'E<dynamic>' should have explicit type arguments but doesn't.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.strictRawType, 48, 1),
|
||||
error(diag.unusedLocalVariable, 50, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localVariable_extensionType_withTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E<T>(int i) {}
|
||||
|
||||
void f() {
|
||||
E<int> e = E<int>(1);
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 55, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localVariable_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
List a = [1, 2, 3];
|
||||
//^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.strictRawType, 13, 4),
|
||||
error(diag.unusedLocalVariable, 18, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localVariable_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
List<Object> a = [1, 2, 3];
|
||||
print(a);
|
||||
@@ -232,17 +221,16 @@ void f() {
|
||||
}
|
||||
|
||||
test_mixinApplication_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class C<T> {}
|
||||
class D = Object with C;
|
||||
''',
|
||||
[error(diag.strictRawType, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'C<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinApplication_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class C<T> {}
|
||||
class D = Object with C<int>;
|
||||
''');
|
||||
@@ -250,7 +238,7 @@ class D = Object with C<int>;
|
||||
|
||||
test_nonFunctionTypeAlias_explicitTypeArg() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef List2<T> = List<T>;
|
||||
void f(List2<int> a) {}
|
||||
''');
|
||||
@@ -258,18 +246,17 @@ void f(List2<int> a) {}
|
||||
|
||||
test_nonFunctionTypeAlias_missingTypeArg() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef List2<T> = List<T>;
|
||||
void f(List2 a) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 35, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.strictRawType] The generic type 'List2<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonFunctionTypeAlias_optionalTypeArgs() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
@optionalTypeArgs
|
||||
typedef List2<T> = List<T>;
|
||||
@@ -280,7 +267,7 @@ void f(List2 a) {}
|
||||
test_objectPattern() async {
|
||||
// This is not considered a "strict raw type" here, but a "strict inference"
|
||||
// issue.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Object o) {
|
||||
switch (o) {
|
||||
case List():
|
||||
@@ -290,115 +277,103 @@ void f(Object o) {
|
||||
}
|
||||
|
||||
test_parameter_default_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({List a = const []}) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 8, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_fieldFormal_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
Object a;
|
||||
C(List this.a);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
}
|
||||
''',
|
||||
[error(diag.strictRawType, 26, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_functionTyped_parameter_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(void a(List p)) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 14, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_functionTyped_returnType_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(List a()) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 7, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_primaryDeclaring_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C(final List a);
|
||||
''',
|
||||
[error(diag.strictRawType, 14, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_simple_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(List a) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 7, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter_super_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class C {
|
||||
Object a;
|
||||
C(this.a);
|
||||
}
|
||||
class D extends C {
|
||||
D(List super.a);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
}
|
||||
''',
|
||||
[error(diag.strictRawType, 70, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnType_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
List f(int a) => [1, 2, 3];
|
||||
''',
|
||||
[error(diag.strictRawType, 0, 4)],
|
||||
);
|
||||
// [diag.strictRawType][column 1][length 4] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_superclassWith_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class C<T> {}
|
||||
class D extends Object with C {}
|
||||
''',
|
||||
[error(diag.strictRawType, 48, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'C<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_superclassWith_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class C<T> {}
|
||||
class D extends Object with C<int> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelField_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
List a = [];
|
||||
''',
|
||||
[error(diag.strictRawType, 0, 4)],
|
||||
);
|
||||
// [diag.strictRawType][column 1][length 4] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelField_optionalTypeArg() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@optionalTypeArgs
|
||||
class C<T> {}
|
||||
@@ -409,7 +384,7 @@ void set s(C a) {}
|
||||
}
|
||||
|
||||
test_topLevelField_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
List<int> a = [];
|
||||
List<num> get g => [];
|
||||
void set s(List<double> a) {}
|
||||
@@ -417,46 +392,39 @@ void set s(List<double> a) {}
|
||||
}
|
||||
|
||||
test_topLevelGetter_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
List get g => [];
|
||||
''',
|
||||
[error(diag.strictRawType, 0, 4)],
|
||||
);
|
||||
// [diag.strictRawType][column 1][length 4] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelSetter_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void set s(List a) {}
|
||||
''',
|
||||
[error(diag.strictRawType, 11, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeAlias_classic_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T F1<T>(T _);
|
||||
F1 func = (a) => a;
|
||||
''',
|
||||
[error(diag.strictRawType, 22, 2)],
|
||||
);
|
||||
// [diag.strictRawType][column 1][length 2] The generic type 'F1<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeAlias_modern_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F1<T> = T Function(T);
|
||||
F1 func = (a) => a;
|
||||
''',
|
||||
[error(diag.strictRawType, 31, 2)],
|
||||
);
|
||||
// [diag.strictRawType][column 1][length 2] The generic type 'F1<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeAlias_modern_optionalTypeArgs() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@optionalTypeArgs
|
||||
typedef T F1<T>(T _);
|
||||
@@ -468,7 +436,7 @@ F2 f2 = (a) => a;
|
||||
}
|
||||
|
||||
test_typeAlias_modern_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T F1<T>(T _);
|
||||
typedef F2<T> = T Function(T);
|
||||
typedef F3 = T Function<T>(T);
|
||||
@@ -480,7 +448,7 @@ F3 f3 = <T>(T a) => a;
|
||||
|
||||
test_typeInClassDeclaration_optionalTypeArgs() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@optionalTypeArgs
|
||||
mixin class C<T> {}
|
||||
@@ -492,7 +460,7 @@ class G implements C {}
|
||||
}
|
||||
|
||||
test_typeInConstructorName() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C();
|
||||
C.named();
|
||||
@@ -504,26 +472,24 @@ var d = C.named();
|
||||
}
|
||||
|
||||
test_typeInExtendedType_anonymous_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension on List {}
|
||||
''',
|
||||
[error(diag.strictRawType, 13, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeInExtendedType_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E on List {}
|
||||
''',
|
||||
[error(diag.strictRawType, 15, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.strictRawType] The generic type 'List<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeInExtendedType_optionalTypeArgs() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@optionalTypeArgs
|
||||
class C<T> {}
|
||||
@@ -533,48 +499,46 @@ extension on C {}
|
||||
}
|
||||
|
||||
test_typeInExtendedType_present() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E<T> on List<T> {}
|
||||
extension F on List<int> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeInInterface_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {}
|
||||
class D implements C {}
|
||||
''',
|
||||
[error(diag.strictRawType, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'C<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeInInterface_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {}
|
||||
class D implements C<int> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeInSuperclass_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {}
|
||||
class D extends C {}
|
||||
''',
|
||||
[error(diag.strictRawType, 30, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'C<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeInSuperclass_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {}
|
||||
class D extends C<int> {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeLiteral_raw() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
var t = List;
|
||||
print(t);
|
||||
@@ -583,17 +547,16 @@ void f() {
|
||||
}
|
||||
|
||||
test_typeParameterBound_missingTypeArg() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {}
|
||||
class D<T extends C> {}
|
||||
''',
|
||||
[error(diag.strictRawType, 32, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.strictRawType] The generic type 'C<dynamic>' should have explicit type arguments but doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameterBound_withTypeArg() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> {}
|
||||
class D<S, T extends C<S>> {}
|
||||
''');
|
||||
|
||||
+11
-11
@@ -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(TearoffOfGenerativeConstructorOfAbstractClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ main() {
|
||||
class TearoffOfGenerativeConstructorOfAbstractClassTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_abstractClass_factoryConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
factory A() => B();
|
||||
}
|
||||
@@ -31,7 +32,7 @@ void foo() {
|
||||
}
|
||||
|
||||
test_abstractClass_factoryConstructor_viaEquals() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
factory A() = B;
|
||||
}
|
||||
@@ -45,22 +46,21 @@ void foo() {
|
||||
}
|
||||
|
||||
test_abstractClass_generativeConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
A();
|
||||
}
|
||||
|
||||
void foo() {
|
||||
A.new;
|
||||
//^^^^^
|
||||
// [diag.tearoffOfGenerativeConstructorOfAbstractClass] A generative constructor of an abstract class can't be torn off.
|
||||
}
|
||||
''',
|
||||
[error(diag.tearoffOfGenerativeConstructorOfAbstractClass, 44, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_concreteClass_factoryConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => A.two();
|
||||
|
||||
@@ -74,7 +74,7 @@ void foo() {
|
||||
}
|
||||
|
||||
test_concreteClass_factoryConstructor_viaEquals() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() = A.two;
|
||||
|
||||
@@ -88,7 +88,7 @@ void foo() {
|
||||
}
|
||||
|
||||
test_concreteClass_generativeConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A();
|
||||
}
|
||||
|
||||
@@ -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(TearoffWithMustBeConstParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ class TearoffWithMustBeConstParameterTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_class_method_commentReference_threeNames() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
import '' as self;
|
||||
/// Reference to [self.C.f].
|
||||
@@ -35,7 +36,7 @@ class C {
|
||||
}
|
||||
|
||||
test_class_method_commentReference_twoNames() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
/// Reference to [C.f].
|
||||
var a = 1;
|
||||
@@ -47,21 +48,20 @@ class C {
|
||||
}
|
||||
|
||||
test_class_method_implicitThis_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
Object get n => m;
|
||||
// ^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'm' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
// ignore: experimental_member_use
|
||||
void m(@mustBeConst int x) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 61, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_invocation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C().m(1);
|
||||
class C {
|
||||
@@ -72,33 +72,31 @@ class C {
|
||||
}
|
||||
|
||||
test_class_method_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C().m;
|
||||
// ^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'm' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
class C {
|
||||
// ignore: experimental_member_use
|
||||
void m(@mustBeConst int x) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 45, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_primaryConstructor_named_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C.named;
|
||||
// ^^^^^^^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'named' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
// ignore: experimental_member_use
|
||||
class C.named(@mustBeConst int x);
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 41, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_primaryConstructor_unnamed_invocation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C(1);
|
||||
// ignore: experimental_member_use
|
||||
@@ -107,33 +105,31 @@ class C(@mustBeConst int x);
|
||||
}
|
||||
|
||||
test_class_primaryConstructor_unnamed_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C.new;
|
||||
// ^^^^^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'new' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
// ignore: experimental_member_use
|
||||
class C(@mustBeConst int x);
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 41, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_named_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C.named;
|
||||
// ^^^^^^^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'named' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
class C {
|
||||
// ignore: experimental_member_use
|
||||
C.named(@mustBeConst int x);
|
||||
}
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 41, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_unnamed_invocation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C.new(1);
|
||||
class C {
|
||||
@@ -144,21 +140,20 @@ class C {
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_unnamed_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = C.new;
|
||||
// ^^^^^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'new' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
class C {
|
||||
// ignore: experimental_member_use
|
||||
C(@mustBeConst int x);
|
||||
}
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 41, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_commentReference() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
/// Reference to [f].
|
||||
var a = 1;
|
||||
@@ -168,19 +163,18 @@ void f(@mustBeConst int x) {}
|
||||
}
|
||||
|
||||
test_topLevelFunction_instantiated_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = f<int>;
|
||||
// ^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'f' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
// ignore: experimental_member_use
|
||||
void f<T>(@mustBeConst T x) {}
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 41, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_invocation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = f(1);
|
||||
// ignore: experimental_member_use
|
||||
@@ -189,14 +183,13 @@ void f(@mustBeConst int x) {}
|
||||
}
|
||||
|
||||
test_topLevelFunction_tearoff() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
var g = f;
|
||||
// ^
|
||||
// [diag.tearoffWithMustBeConstParameter] The function 'f' has a parameter marked as '@mustBeConst' and can't be torn off.
|
||||
// ignore: experimental_member_use
|
||||
void f(@mustBeConst int x) {}
|
||||
''',
|
||||
[error(diag.tearoffWithMustBeConstParameter, 41, 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(ThrowOfInvalidTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ThrowOfInvalidTypeTest extends PubPackageResolutionTest {
|
||||
test_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(dynamic a) {
|
||||
throw a;
|
||||
}
|
||||
@@ -24,7 +25,7 @@ f(dynamic a) {
|
||||
}
|
||||
|
||||
test_nonNullable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(int a) {
|
||||
throw a;
|
||||
}
|
||||
@@ -32,13 +33,12 @@ f(int a) {
|
||||
}
|
||||
|
||||
test_nullable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(int? a) {
|
||||
throw a;
|
||||
// ^
|
||||
// [diag.throwOfInvalidType] The type 'int?' of the thrown expression must be assignable to 'Object'.
|
||||
}
|
||||
''',
|
||||
[error(diag.throwOfInvalidType, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,73 +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(TopLevelCycleTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TopLevelCycleTest extends PubPackageResolutionTest {
|
||||
test_cycle_fields() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static final x = y + 1;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x, y.
|
||||
static final y = x + 1;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'y' can't be inferred because it depends on itself through the cycle: x, y.
|
||||
}
|
||||
''',
|
||||
[error(diag.topLevelCycle, 25, 1), error(diag.topLevelCycle, 51, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_cycle_fields_chain() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static final a = b.c;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'a' can't be inferred because it depends on itself through the cycle: a, c.
|
||||
static final b = A();
|
||||
final c = a;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'c' can't be inferred because it depends on itself through the cycle: a, c.
|
||||
}
|
||||
''',
|
||||
[error(diag.topLevelCycle, 25, 1), error(diag.topLevelCycle, 66, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_cycle_topLevelVariables() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var x = y + 1;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x, y.
|
||||
var y = x + 1;
|
||||
''',
|
||||
[error(diag.topLevelCycle, 4, 1), error(diag.topLevelCycle, 19, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'y' can't be inferred because it depends on itself through the cycle: x, y.
|
||||
''');
|
||||
}
|
||||
|
||||
test_singleVariable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var x = x;
|
||||
''',
|
||||
[error(diag.topLevelCycle, 4, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x.
|
||||
''');
|
||||
}
|
||||
|
||||
test_singleVariable_fromList() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var elems = [
|
||||
// ^^^^^
|
||||
// [diag.topLevelCycle] The type of 'elems' can't be inferred because it depends on itself through the cycle: elems.
|
||||
[
|
||||
1, elems, 3,
|
||||
],
|
||||
];
|
||||
''',
|
||||
[error(diag.topLevelCycle, 4, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,93 +2,86 @@
|
||||
// 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(TypeAliasCannotReferenceItselfTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeAliasCannotReferenceItselfTest extends PubPackageResolutionTest {
|
||||
test_functionTypeAlias_typeParameterBounds() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A<T extends A<int>>();
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionTypedParameter_returnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A(A b());
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_generic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F = void Function(List<G> l);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
typedef G = void Function(List<F> l);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
main() {
|
||||
F? foo(G? g) => g;
|
||||
foo(null);
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.typeAliasCannotReferenceItself, 8, 1),
|
||||
error(diag.typeAliasCannotReferenceItself, 46, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericTypeAlias_typeParameterBounds() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A<T extends A<int>> = void Function();
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_infiniteParameterBoundCycle() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F<X extends F<X>> = F Function();
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_issue11987() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef void F(List<G> l);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
typedef void G(List<F> l);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
main() {
|
||||
F? foo(G? g) => g;
|
||||
foo(null);
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.typeAliasCannotReferenceItself, 13, 1),
|
||||
error(diag.typeAliasCannotReferenceItself, 40, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_issue19459() async {
|
||||
// A complex example involving multiple classes. This is legal, since
|
||||
// typedef F references itself only via a class.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<B, C> {}
|
||||
abstract class D {
|
||||
f(E e);
|
||||
@@ -99,101 +92,90 @@ typedef D F();
|
||||
}
|
||||
|
||||
test_nonFunction_aliasedType_cycleOf2() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T1 = T2;
|
||||
// ^^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
typedef T2 = T1;
|
||||
''',
|
||||
[
|
||||
error(diag.typeAliasCannotReferenceItself, 8, 2),
|
||||
error(diag.typeAliasCannotReferenceItself, 25, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonFunction_aliasedType_directly_functionWithIt() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T = void Function(T);
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonFunction_aliasedType_directly_it_none() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T = T;
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonFunction_aliasedType_directly_it_question() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T = T?;
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonFunction_aliasedType_directly_ListOfIt() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T = List<T>;
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonFunction_typeParameterBounds() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef T<X extends T<Never>> = List<X>;
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameterType_named() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A({A a});
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameterType_positional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A([A a]);
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameterType_required() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A(A a);
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameterType_typeArgument() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A(List<A> a);
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_referencesReturnType_inTypeAlias() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef B A();
|
||||
class B {
|
||||
A? a;
|
||||
@@ -203,7 +185,7 @@ class B {
|
||||
|
||||
test_returnClass_withTypeAlias() async {
|
||||
// A typedef is allowed to indirectly reference itself via a class.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef C A();
|
||||
typedef A B();
|
||||
class C {
|
||||
@@ -213,33 +195,29 @@ class C {
|
||||
}
|
||||
|
||||
test_returnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef A A();
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 10, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_returnType_indirect() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef B A();
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
typedef A B();
|
||||
''',
|
||||
[
|
||||
error(diag.typeAliasCannotReferenceItself, 10, 1),
|
||||
error(diag.typeAliasCannotReferenceItself, 25, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
|
||||
test_usingRecordType_directly() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F = (F, int) Function();
|
||||
''',
|
||||
[error(diag.typeAliasCannotReferenceItself, 8, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(TypeAnnotationDeferredClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,96 +20,84 @@ class TypeAnnotationDeferredClassTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
class D {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class C<T> { const C(); }
|
||||
@C<a.D>() main () {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.typeAnnotationDeferredClass,
|
||||
77,
|
||||
3,
|
||||
messageContains: ["'a.D'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.D' can't be used in a declaration, cast, or type test.
|
||||
''');
|
||||
}
|
||||
|
||||
test_asExpression() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f(v) {
|
||||
v as a.A;
|
||||
}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 62, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_catchClause() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f(v) {
|
||||
try {
|
||||
} on a.A {
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
}
|
||||
}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 70, 3)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_fieldFormalParameter() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class C {
|
||||
var v;
|
||||
C(a.A this.v);
|
||||
}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 71, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_functionDeclaration_returnType() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
a.A? f() { return null; }
|
||||
''',
|
||||
[error(diag.typeAnnotationDeferredClass, 48, 4)],
|
||||
);
|
||||
// [diag.typeAnnotationDeferredClass][column 1][length 4] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionTypedFormalParameter_returnType() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f(a.A g()) {}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 50, 3)],
|
||||
f(a.A g()) {}
|
||||
//^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,45 +105,43 @@ f(a.A g()) {}''',
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f(v) {
|
||||
bool b = v is a.A;
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 62, 1),
|
||||
error(diag.typeAnnotationDeferredClass, 71, 3),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used.
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_methodDeclaration_returnType() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class C {
|
||||
a.A? m() { return null; }
|
||||
}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 60, 4)],
|
||||
);
|
||||
//^^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_simpleFormalParameter() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f(a.A v) {}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 50, 3)],
|
||||
f(a.A v) {}
|
||||
//^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -162,45 +149,43 @@ f(a.A v) {}''',
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class C<E> {}
|
||||
C<a.A> c = C();
|
||||
''',
|
||||
[error(diag.typeAnnotationDeferredClass, 64, 3)],
|
||||
);
|
||||
//^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeArgumentList2() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class C<E, F> {}
|
||||
C<a.A, a.A> c = C();
|
||||
''',
|
||||
[
|
||||
error(diag.typeAnnotationDeferredClass, 67, 3),
|
||||
error(diag.typeAnnotationDeferredClass, 72, 3),
|
||||
],
|
||||
);
|
||||
//^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_bound() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(
|
||||
r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class C<E extends a.A> {}''',
|
||||
[error(diag.typeAnnotationDeferredClass, 66, 3)],
|
||||
class C<E extends a.A> {}
|
||||
// ^^^
|
||||
// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.''',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,13 +193,11 @@ class C<E extends a.A> {}''',
|
||||
newFile('$testPackageLibPath/lib1.dart', '''
|
||||
library lib1;
|
||||
class A {}''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
a.A v = a.A();
|
||||
''',
|
||||
[error(diag.typeAnnotationDeferredClass, 48, 3)],
|
||||
);
|
||||
// [diag.typeAnnotationDeferredClass][column 1][length 3] The deferred type 'a.A' can't be used in a declaration, cast, or type test.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(TypeCheckIsNotNullTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeCheckIsNotNullTest extends PubPackageResolutionTest {
|
||||
test_not_Null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool m(i) {
|
||||
return i is! Null;
|
||||
// ^^^^^^^^^^
|
||||
// [diag.typeCheckIsNotNull] Tests for non-null should be done with '!= null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeCheckIsNotNull, 21, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(TypeCheckIsNullTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeCheckIsNullTest extends PubPackageResolutionTest {
|
||||
test_is_Null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool m(i) {
|
||||
return i is Null;
|
||||
// ^^^^^^^^^
|
||||
// [diag.typeCheckIsNull] Tests for null should be done with '== null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeCheckIsNull, 21, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,146 +2,136 @@
|
||||
// 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(TypeParameterReferencedByStaticTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeParameterReferencedByStaticTest extends PubPackageResolutionTest {
|
||||
test_class_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static T? foo;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static T? get foo => null;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_bodyReference() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static foo() {
|
||||
// ignore:unused_local_variable
|
||||
T v;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 70, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_closure() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static Object foo() {
|
||||
return (T a) {};
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 49, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static foo(T a) {}
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_return() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static T foo() {
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
throw 0;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static set foo(T _) {}
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 30, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
static foo() {
|
||||
T;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E<T> on int {
|
||||
static T? foo;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extension_method_return() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension E<T> on int {
|
||||
static T foo() => throw 0;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A<T> {
|
||||
static T? foo;
|
||||
// ^
|
||||
// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterReferencedByStatic, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,135 +2,123 @@
|
||||
// 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(TypeParameterSupertypeOfItsBoundTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeParameterSupertypeOfItsBoundTest extends PubPackageResolutionTest {
|
||||
test_1of1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends T> {
|
||||
// ^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T' can't be a supertype of its upper bound.
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterSupertypeOfItsBound, 8, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_1of1_local() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void m() {
|
||||
void local<T extends T>() {}
|
||||
// ^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T' can't be a supertype of its upper bound.
|
||||
local;
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterSupertypeOfItsBound, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_1of1_local_viaExtensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(T it) {}
|
||||
|
||||
void m() {
|
||||
void local<U extends A<U>>() {}
|
||||
// ^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'U' can't be a supertype of its upper bound.
|
||||
local;
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterSupertypeOfItsBound, 54, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_1of1_used() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends T> {
|
||||
// ^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T' can't be a supertype of its upper bound.
|
||||
void foo(x) {
|
||||
x is T;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.typeParameterSupertypeOfItsBound, 8, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_1of1_viaExtensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(T it) {}
|
||||
|
||||
class B<U extends A<U>> {}
|
||||
''',
|
||||
[error(diag.typeParameterSupertypeOfItsBound, 38, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'U' can't be a supertype of its upper bound.
|
||||
''');
|
||||
}
|
||||
|
||||
test_2of2_local_viaExtensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(T it) {}
|
||||
|
||||
void m() {
|
||||
void local<T1 extends A<T2>, T2 extends T1>() {}
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound.
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T2' can't be a supertype of its upper bound.
|
||||
local;
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.typeParameterSupertypeOfItsBound, 54, 2),
|
||||
error(diag.typeParameterSupertypeOfItsBound, 72, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_2of2_viaExtensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(T it) {}
|
||||
|
||||
class B<T1 extends A<T2>, T2 extends T1> {}
|
||||
''',
|
||||
[
|
||||
error(diag.typeParameterSupertypeOfItsBound, 38, 2),
|
||||
error(diag.typeParameterSupertypeOfItsBound, 56, 2),
|
||||
],
|
||||
);
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound.
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T2' can't be a supertype of its upper bound.
|
||||
''');
|
||||
}
|
||||
|
||||
test_2of3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T1 extends T3, T2, T3 extends T1> {
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound.
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T3' can't be a supertype of its upper bound.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.typeParameterSupertypeOfItsBound, 8, 2),
|
||||
error(diag.typeParameterSupertypeOfItsBound, 27, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_local_2of3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void m() {
|
||||
void local<T1 extends T3, T2, T3 extends T1>() {}
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound.
|
||||
// ^^
|
||||
// [diag.typeParameterSupertypeOfItsBound] 'T3' can't be a supertype of its upper bound.
|
||||
local;
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.typeParameterSupertypeOfItsBound, 24, 2),
|
||||
error(diag.typeParameterSupertypeOfItsBound, 43, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,28 +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(TypeTestWithNonTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeTestWithNonTypeTest extends PubPackageResolutionTest {
|
||||
test_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var A = 0;
|
||||
f(p) {
|
||||
if (p is A) {
|
||||
}
|
||||
}''',
|
||||
[error(diag.typeTestWithNonType, 29, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeTestWithNonType] The name 'A' isn't a type and can't be used in an 'is' expression.
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,27 +2,28 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(TypeTestWithUndefinedNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class TypeTestWithUndefinedNameTest extends PubPackageResolutionTest {
|
||||
test_undefined() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(p) {
|
||||
if (p is A) {
|
||||
}
|
||||
}''',
|
||||
[error(diag.typeTestWithUndefinedName, 18, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.typeTestWithUndefinedName] The name 'A' isn't defined, so it can't be used in an 'is' expression.
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user