CQ. Migrate diagnostics tests to resolveTestCodeWithDiagnostics. LMNOP.
Change-Id: I4baefc8a58f94fde52bde498307a55ffa71527b4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503160 SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
b1fbe470a1
commit
bfca71d6d6
@@ -2,33 +2,35 @@
|
||||
// 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(LabelInOuterScopeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class LabelInOuterScopeTest extends PubPackageResolutionTest {
|
||||
test_label_in_outer_scope() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void m(int i) {
|
||||
l: while (i > 0) {
|
||||
void f() {
|
||||
// ^
|
||||
// [diag.unusedElement] The declaration 'f' isn't referenced.
|
||||
break l;
|
||||
// ^
|
||||
// [diag.labelInOuterScope] Can't reference label 'l' declared in an outer method.
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 62, 1), error(diag.labelInOuterScope, 82, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,68 +2,69 @@
|
||||
// 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(LabelUndefinedTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class LabelUndefinedTest extends PubPackageResolutionTest {
|
||||
test_break() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
x: while (true) {
|
||||
//^^
|
||||
// [diag.unusedLabel] The label 'x' isn't used.
|
||||
break y;
|
||||
// ^
|
||||
// [diag.labelUndefined] Can't reference an undefined label 'y'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLabel, 8, 2), error(diag.labelUndefined, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_break_notLabel() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(int x) {
|
||||
while (true) {
|
||||
break x;
|
||||
// ^
|
||||
// [diag.labelUndefined] Can't reference an undefined label 'x'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.labelUndefined, 38, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_continue() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
x: while (true) {
|
||||
//^^
|
||||
// [diag.unusedLabel] The label 'x' isn't used.
|
||||
continue y;
|
||||
// ^
|
||||
// [diag.labelUndefined] Can't reference an undefined label 'y'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLabel, 8, 2), error(diag.labelUndefined, 39, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_continue_notLabel() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(int x) {
|
||||
while (true) {
|
||||
continue x;
|
||||
// ^
|
||||
// [diag.labelUndefined] Can't reference an undefined label 'x'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.labelUndefined, 41, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,62 +2,60 @@
|
||||
// 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(LateFinalLocalAlreadyAssignedTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class LateFinalLocalAlreadyAssignedTest extends PubPackageResolutionTest {
|
||||
test_assignmentExpression_compound() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final int v;
|
||||
v = 0;
|
||||
v += 1;
|
||||
//^
|
||||
// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.lateFinalLocalAlreadyAssigned, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_assignmentExpression_simple() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final int v;
|
||||
v = 0;
|
||||
v = 1;
|
||||
//^
|
||||
// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.lateFinalLocalAlreadyAssigned, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_assignmentExpression_simple_initialized() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final int v = 0;
|
||||
v = 1;
|
||||
//^
|
||||
// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.lateFinalLocalAlreadyAssigned, 35, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_localVariable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f() {
|
||||
late final int a;
|
||||
a = 1;
|
||||
@@ -67,60 +65,56 @@ void f() {
|
||||
}
|
||||
|
||||
test_localVariable_forEach() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
late final int i;
|
||||
for (i in [1, 2, 3]) {
|
||||
// ^
|
||||
// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned.
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.lateFinalLocalAlreadyAssigned, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_postfixExpression_inc() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final int v = 0;
|
||||
v++;
|
||||
//^
|
||||
// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.lateFinalLocalAlreadyAssigned, 35, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_postfixExpression_nullCheck() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final int v = 0;
|
||||
v!;
|
||||
// ^
|
||||
// [diag.unnecessaryNonNullAssertion] The '!' will have no effect because the receiver can't be null.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.unnecessaryNonNullAssertion, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixExpression_inc() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final int v = 0;
|
||||
++v;
|
||||
// ^
|
||||
// [diag.lateFinalLocalAlreadyAssigned] The late final local variable is already assigned.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.lateFinalLocalAlreadyAssigned, 37, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_prefixExpression_negation() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
main() {
|
||||
late final bool v = true;
|
||||
!v;
|
||||
|
||||
@@ -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(ListElementTypeNotAssignableTest);
|
||||
defineReflectiveTests(ListElementTypeNotAssignableWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ListElementTypeNotAssignableTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = const <int>[if (1 < 0) a else b];
|
||||
@@ -25,114 +27,107 @@ var v = const <int>[if (1 < 0) a else b];
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 'b';
|
||||
var v = const <int>[if (1 < 0) a else b];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 82, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int>[if (1 < 0) 'a'];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 31, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int>[if (1 < 0) a];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int>[if (true) a];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int>[if (true) a];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 53, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intInt() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v1 = <int> [42];
|
||||
var v2 = const <int> [42];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const a = null;
|
||||
var v = const <int>[a];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignableNullability, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.listElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the list type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int>[null];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignableNullability, 20, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.listElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the list type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int>[...[0, 1]];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_stringInt() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <String>[42];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 23, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'int' can't be assigned to the list type 'String'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_stringInt_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic x = 42;
|
||||
var v = const <String>[x];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 45, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'int' can't be assigned to the list type 'String'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_stringQuestion_null_value() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <String?>[null];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_voidInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <void>[42];
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_genericFunction_genericContext() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
List<U Function<U>(U)> foo(T Function<T>(T a) f) {
|
||||
return [f];
|
||||
}
|
||||
@@ -140,18 +135,17 @@ List<U Function<U>(U)> foo(T Function<T>(T a) f) {
|
||||
}
|
||||
|
||||
test_nonConst_genericFunction_genericContext_nonAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
List<U Function<U>(U, int)> foo(T Function<T>(T a) f) {
|
||||
return [f];
|
||||
// ^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'T Function<T>(T)' can't be assigned to the list type 'U Function<U>(U, int)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 66, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_genericFunction_nonGenericContext() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
List<int Function(int)> foo(T Function<T>(T a) f) {
|
||||
return [f];
|
||||
}
|
||||
@@ -159,18 +153,17 @@ List<int Function(int)> foo(T Function<T>(T a) f) {
|
||||
}
|
||||
|
||||
test_nonConst_genericFunction_nonGenericContext_nonAssignable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
List<int Function(int, int)> foo(T Function<T>(T a) f) {
|
||||
return [f];
|
||||
// ^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'dynamic Function(dynamic)' can't be assigned to the list type 'int Function(int, int)'.
|
||||
}
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 67, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intDynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
const dynamic b = 'b';
|
||||
var v = <int>[if (1 < 0) a else b];
|
||||
@@ -178,7 +171,7 @@ var v = <int>[if (1 < 0) a else b];
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = <int>[if (1 < 0) a else b];
|
||||
@@ -186,52 +179,50 @@ var v = <int>[if (1 < 0) a else b];
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenFalse_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
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('''
|
||||
const dynamic a = 'a';
|
||||
var v = <int>[if (true) a];
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = <int>[if (true) a];
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <int>[...[0, 1]];
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_stringInt() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <String>[42];
|
||||
''',
|
||||
[error(diag.listElementTypeNotAssignable, 17, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.listElementTypeNotAssignable] The element type 'int' can't be assigned to the list type 'String'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_stringInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic x = 42;
|
||||
var v = <String>[x];
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_voidInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <void>[42];
|
||||
''');
|
||||
}
|
||||
|
||||
@@ -2,78 +2,82 @@
|
||||
// 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(MainFirstPositionalParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MainFirstPositionalParameterTest extends PubPackageResolutionTest {
|
||||
test_positionalOptional_listOfInt() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main([List<int> args = const []]) {}
|
||||
// ^^^^^^^^^
|
||||
// [diag.mainFirstPositionalParameterType] The type of the first positional parameter of the 'main' function must be a supertype of 'List<String>'.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainFirstPositionalParameterType, 11, 9)]);
|
||||
}
|
||||
|
||||
test_positionalRequired_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(dynamic args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_positionalRequired_functionTypedFormal() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(void args()) {}
|
||||
// ^^^^
|
||||
// [diag.mainFirstPositionalParameterType] The type of the first positional parameter of the 'main' function must be a supertype of 'List<String>'.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainFirstPositionalParameterType, 10, 4)]);
|
||||
}
|
||||
|
||||
test_positionalRequired_iterableOfString() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(Iterable<String> args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_positionalRequired_listOfInt() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(List<int> args) {}
|
||||
// ^^^^^^^^^
|
||||
// [diag.mainFirstPositionalParameterType] The type of the first positional parameter of the 'main' function must be a supertype of 'List<String>'.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainFirstPositionalParameterType, 10, 9)]);
|
||||
}
|
||||
|
||||
test_positionalRequired_listOfString() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(List<String> args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_positionalRequired_listOfStringQuestion() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(List<String?> args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_positionalRequired_listQuestionOfString() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(List<String>? args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_positionalRequired_object() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(Object args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_positionalRequired_objectQuestion() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(Object? args) {}
|
||||
''');
|
||||
}
|
||||
|
||||
@@ -2,32 +2,31 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MainHasRequiredNamedParametersTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MainHasRequiredNamedParametersTest extends PubPackageResolutionTest {
|
||||
test_namedOptional() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main({int a = 0}) {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_namedRequired() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main({required List<String> a}) {}
|
||||
''',
|
||||
[error(diag.mainHasRequiredNamedParameters, 5, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mainHasRequiredNamedParameters] The function 'main' can't have any required named parameters.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+18
-26
@@ -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(MainHasTooManyRequiredPositionalParametersTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,72 +18,63 @@ main() {
|
||||
class MainHasTooManyRequiredPositionalParametersTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_namedOptional_1() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main({int a = 0}) {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_positionalOptional_1() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int a = 0]) {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_positionalRequired_0() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_positionalRequired_1() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(args) {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_positionalRequired_2() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(args, int a) {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_positionalRequired_2_positionalOptional_1() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(args, int a, [int b = 0]) {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
}
|
||||
|
||||
test_positionalRequired_3() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(args, int a, int b) {}
|
||||
// ^^^^
|
||||
// [diag.mainHasTooManyRequiredPositionalParameters] The function 'main' can't have more than two required positional parameters.
|
||||
''');
|
||||
assertErrorsInResult([
|
||||
error(diag.mainHasTooManyRequiredPositionalParameters, 5, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
test_positionalRequired_3_namedOptional_1() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(args, int a, int b, {int c = 0}) {}
|
||||
// ^^^^
|
||||
// [diag.mainHasTooManyRequiredPositionalParameters] The function 'main' can't have more than two required positional parameters.
|
||||
''');
|
||||
assertErrorsInResult([
|
||||
error(diag.mainHasTooManyRequiredPositionalParameters, 5, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
test_positionalRequired_3_namedRequired_1() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main(args, int a, int b, {required int c}) {}
|
||||
// ^^^^
|
||||
// [diag.mainHasTooManyRequiredPositionalParameters] The function 'main' can't have more than two required positional parameters.
|
||||
// [diag.mainHasRequiredNamedParameters] The function 'main' can't have any required named parameters.
|
||||
''');
|
||||
assertErrorsInResult([
|
||||
error(diag.mainHasRequiredNamedParameters, 5, 4),
|
||||
error(diag.mainHasTooManyRequiredPositionalParameters, 5, 4),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,83 +2,92 @@
|
||||
// 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(MainIsNotFunctionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MainIsNotFunctionTest extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class main {}
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 6, 4)]);
|
||||
}
|
||||
|
||||
test_classAlias() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
mixin M {}
|
||||
class main = A with M;
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 28, 4)]);
|
||||
}
|
||||
|
||||
test_enum() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum main {
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
v
|
||||
}
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 5, 4)]);
|
||||
}
|
||||
|
||||
test_function() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_getter() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int get main => 0;
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 8, 4)]);
|
||||
}
|
||||
|
||||
test_mixin() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
mixin main on A {}
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 17, 4)]);
|
||||
}
|
||||
|
||||
test_typedef() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef main = void Function();
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 8, 4)]);
|
||||
}
|
||||
|
||||
test_typedef_legacy() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef void main();
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 13, 4)]);
|
||||
}
|
||||
|
||||
test_variable() async {
|
||||
await resolveTestCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var main = 0;
|
||||
// ^^^^
|
||||
// [diag.mainIsNotFunction] The declaration named 'main' must be a function.
|
||||
''');
|
||||
assertErrorsInResult([error(diag.mainIsNotFunction, 4, 4)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,34 +2,33 @@
|
||||
// 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(MapEntryNotInMapTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MapEntryNotInMapTest extends PubPackageResolutionTest {
|
||||
test_set() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var c = <int>{1:2};
|
||||
''',
|
||||
[error(diag.mapEntryNotInMap, 14, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapEntryNotInMap] Map entries can only be used in a map literal.
|
||||
''');
|
||||
}
|
||||
|
||||
test_set_const() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var c = const <int>{1:2};
|
||||
''',
|
||||
[error(diag.mapEntryNotInMap, 20, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapEntryNotInMap] Map entries can only be used in a map 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(MapKeyTypeNotAssignableTest);
|
||||
defineReflectiveTests(MapKeyTypeNotAssignableWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MapKeyTypeNotAssignableTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = const <int, bool>{if (1 < 0) a: true else b: false};
|
||||
@@ -25,141 +27,132 @@ var v = const <int, bool>{if (1 < 0) a: true else b: false};
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 'b';
|
||||
var v = const <int, bool>{if (1 < 0) a: true else b: false};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 94, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int, bool>{if (1 < 0) a: true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int, bool>{if (1 < 0) 'a': true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 37, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int, bool>{if (true) a: true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int, bool>{if (true) a: true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 59, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_notConst() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final a = 0;
|
||||
var v = const <int, bool>{if (1 < 2) a: true};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 50, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int, bool>{a : true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = null;
|
||||
var v = const <int, bool>{a : true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignableNullability, 50, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapKeyTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int, bool>{null : true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignableNullability, 26, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mapKeyTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intQuestion_null_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = null;
|
||||
var v = const <int?, bool>{a : true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intQuestion_null_value() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int?, bool>{null : true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int, bool>{a : true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 49, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int, bool>{'a' : true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 26, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <int, String>{...{1: 'a'}};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_spread_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <int, String>{...{a: 'a'}};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 55, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_key_type_is_assignable() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <String, int > {'a' : 1};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = <int, bool>{if (1 < 0) a: true else b: false};
|
||||
@@ -167,7 +160,7 @@ var v = <int, bool>{if (1 < 0) a: true else b: false};
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 'b';
|
||||
var v = <int, bool>{if (1 < 0) a: true else b: false};
|
||||
@@ -175,68 +168,65 @@ var v = <int, bool>{if (1 < 0) a: true else b: false};
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenFalse_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <int, bool>{if (1 < 0) 'a': true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 31, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = <int, bool>{if (true) a: true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = <int, bool>{if (true) a: true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = <int, bool>{a : true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = <int, bool>{a : true};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <int, bool>{'a' : true};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 20, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <int, String>{...{1: 'a'}};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <int, String>{...{'a': 'a'}};
|
||||
''',
|
||||
[error(diag.mapKeyTypeNotAssignable, 26, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapKeyTypeNotAssignable] The element type 'String' can't be assigned to the map key type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
dynamic a = 'a';
|
||||
var v = <int, String>{...{a: 'a'}};
|
||||
''');
|
||||
|
||||
@@ -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(MapValueTypeNotAssignableTest);
|
||||
defineReflectiveTests(MapValueTypeNotAssignableWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MapValueTypeNotAssignableTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = const <bool, int>{if (1 < 0) true: a else false: b};
|
||||
@@ -25,135 +27,126 @@ var v = const <bool, int>{if (1 < 0) true: a else false: b};
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 'b';
|
||||
var v = const <bool, int>{if (1 < 0) true: a else false: b};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 101, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <bool, int>{if (1 < 0) true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <bool, int>{if (1 < 0) true: 'a'};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 43, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <bool, int>{if (true) true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <bool, int>{if (true) true: a};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 65, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_notConst() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final a = 0;
|
||||
var v = const <bool, int>{if (1 < 2) true: a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 56, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <bool, int>{true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = null;
|
||||
var v = const <bool, int>{true: a};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignableNullability, 56, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapValueTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intNull_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <bool, int>{true: null};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignableNullability, 32, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mapValueTypeNotAssignableNullability] The element type 'Null' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intQuestion_null_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = null;
|
||||
var v = const <bool, int?>{true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intQuestion_null_value() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <bool, int?>{true: null};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <bool, int>{true: a};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 55, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <bool, int>{true: 'a'};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 32, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = const <bool, int>{...{true: 1}};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_spread_intString_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = const <bool, int>{...{true: a}};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 59, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 0;
|
||||
var v = <bool, int>{if (1 < 0) true: a else false: b};
|
||||
@@ -161,7 +154,7 @@ var v = <bool, int>{if (1 < 0) true: a else false: b};
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenElseFalse_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
const dynamic b = 'b';
|
||||
var v = <bool, int>{if (1 < 0) true: a else false: b};
|
||||
@@ -169,68 +162,65 @@ var v = <bool, int>{if (1 < 0) true: a else false: b};
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenFalse_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <bool, int>{if (1 < 0) true: 'a'};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 37, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = <bool, int>{if (true) true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_ifElement_thenTrue_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = <bool, int>{if (true) true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_intInt_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = <bool, int>{true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = <bool, int>{true: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_intString_value() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <bool, int>{true: 'a'};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 26, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intInt() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <bool, int>{...{true: 1}};
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intString() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var v = <bool, int>{...{true: 'a'}};
|
||||
''',
|
||||
[error(diag.mapValueTypeNotAssignable, 30, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mapValueTypeNotAssignable] The element type 'String' can't be assigned to the map value type 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_spread_intString_dynamic() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 'a';
|
||||
var v = <bool, int>{...{true: a}};
|
||||
''');
|
||||
|
||||
@@ -2,61 +2,58 @@
|
||||
// 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(MemberWithClassNameTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MemberWithClassNameTest extends PubPackageResolutionTest {
|
||||
test_class_field() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int A = 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 16, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_field_multiple() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int z = 0, A = 0, b = 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
get A => 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 16, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_getter_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int get A => 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method() async {
|
||||
@@ -65,128 +62,117 @@ class A {
|
||||
}
|
||||
|
||||
test_class_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set A(_) {}
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 16, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_setter_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static set A(_) {}
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_field() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
final int E = 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
int get E => 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 24, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_getter_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
static int get E => 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 31, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
set E(int _) {}
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_setter_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
static set E(int _) {}
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
int get M => 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_getter_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
static int get M => 0;
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
void set M(_) {}
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 21, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_setter_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
static void set M(_) {}
|
||||
// ^
|
||||
// [diag.memberWithClassName] A class member can't have the same name as the enclosing class.
|
||||
}
|
||||
''',
|
||||
[error(diag.memberWithClassName, 28, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(MismatchedAnnotationOnStructFieldTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MismatchedAnnotationOnStructFieldTest extends PubPackageResolutionTest {
|
||||
test_double_on_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
@Double()
|
||||
//^^^^^^^^^
|
||||
// [diag.mismatchedAnnotationOnStructField] The annotation doesn't match the declared type of the field.
|
||||
external int x;
|
||||
}
|
||||
''',
|
||||
[error(diag.mismatchedAnnotationOnStructField, 52, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_int32_on_double() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
@Int32()
|
||||
//^^^^^^^^
|
||||
// [diag.mismatchedAnnotationOnStructField] The annotation doesn't match the declared type of the field.
|
||||
external double x;
|
||||
}
|
||||
''',
|
||||
[error(diag.mismatchedAnnotationOnStructField, 52, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,33 @@
|
||||
// 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(MissingAnnotationOnStructFieldTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingAnnotationOnStructFieldTest extends PubPackageResolutionTest {
|
||||
test_missing_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
external int x;
|
||||
// ^^^
|
||||
// [diag.missingAnnotationOnStructField] Fields of type 'int' in a subclass of 'Struct' must have an annotation indicating the native type.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingAnnotationOnStructField, 61, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notMissing() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
@Int32()
|
||||
|
||||
@@ -2,52 +2,51 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MissingDefaultValueForParameterTest);
|
||||
defineReflectiveTests(MissingDefaultValueForParameterWithAnnotationTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingDefaultValueForParameterTest extends PubPackageResolutionTest {
|
||||
test_closure_nonNullable_named_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var f = ({int a = 0}) {};
|
||||
''');
|
||||
}
|
||||
|
||||
test_closure_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var f = ({int a}) {};
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 14, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_closure_nonNullable_positional_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var f = ([int a = 0]) {};
|
||||
''');
|
||||
}
|
||||
|
||||
test_closure_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var f = ([int a]) {};
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 14, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_externalFactory_nonNullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
external factory C({int a});
|
||||
}
|
||||
@@ -55,7 +54,7 @@ class C {
|
||||
}
|
||||
|
||||
test_constructor_externalFactory_nonNullable_positional_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
external factory C([int a]);
|
||||
}
|
||||
@@ -63,7 +62,7 @@ class C {
|
||||
}
|
||||
|
||||
test_constructor_externalFactory_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
external factory C({int? a});
|
||||
}
|
||||
@@ -71,31 +70,29 @@ class C {
|
||||
}
|
||||
|
||||
test_constructor_factory_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
factory C({int a}) => C._();
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
C._();
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_factory_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
factory C([int a]) => C._();
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
C._();
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_factory_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
factory C({int? a}) => C._();
|
||||
C._();
|
||||
@@ -104,18 +101,17 @@ class C {
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
C({int a});
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 19, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_named_optional_super_hasDefault_explicit() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A({required int a});
|
||||
}
|
||||
@@ -126,7 +122,7 @@ class B extends A{
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_named_optional_super_hasDefault_fromSuper() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A({int a = 0});
|
||||
}
|
||||
@@ -137,7 +133,7 @@ class B extends A{
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_named_optional_super_hasDefault_fromSuper_extensionType() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
extension type const E(int it) {}
|
||||
|
||||
class A {
|
||||
@@ -151,46 +147,43 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_named_optional_super_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
class B extends A{
|
||||
B({int super.a});
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 61, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_named_optional_super_noDefault_fromSuper() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A({num a = 1.2});
|
||||
}
|
||||
class B extends A{
|
||||
B({int super.a});
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 66, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
C([int a]);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 19, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_positional_optional_super_hasDefault_explicit() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A(int a);
|
||||
}
|
||||
@@ -201,7 +194,7 @@ class B extends A{
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_positional_optional_super_hasDefault_fromSuper() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A([int a = 0]);
|
||||
}
|
||||
@@ -212,35 +205,33 @@ class B extends A{
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_positional_optional_super_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
class B extends A{
|
||||
B([int super.a]);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 61, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_nonNullable_positional_optional_super_noDefault_fromSuper() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A([num a = 1.2]);
|
||||
}
|
||||
class B extends A{
|
||||
B([int super.a]);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 66, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
C({int? a});
|
||||
}
|
||||
@@ -248,7 +239,7 @@ class C {
|
||||
}
|
||||
|
||||
test_constructor_generative_nullable_named_optional_noDefault_fieldFormal() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
int? f;
|
||||
C({this.f});
|
||||
@@ -257,8 +248,7 @@ class C {
|
||||
}
|
||||
|
||||
test_constructor_generative_super_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
final int a;
|
||||
A({this.a = 0});
|
||||
@@ -270,14 +260,14 @@ class B extends A {
|
||||
|
||||
class C extends B {
|
||||
C({super.a});
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 126, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_generative_super_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
final int? a;
|
||||
A({this.a});
|
||||
@@ -294,7 +284,7 @@ class C extends B {
|
||||
}
|
||||
|
||||
test_constructor_redirectingFactory_nonNullable_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
factory A({int a}) = B;
|
||||
}
|
||||
@@ -306,7 +296,7 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_constructor_redirectingFactory_nonNullable_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
factory A([int a]) = B;
|
||||
}
|
||||
@@ -318,7 +308,7 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_constructor_redirectingFactory_nullable_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
factory A({int? a}) = B;
|
||||
}
|
||||
@@ -330,7 +320,7 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_fieldFormalParameter_functionTyped_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
dynamic f;
|
||||
A(void this.f({int a, int? b}));
|
||||
@@ -339,7 +329,7 @@ class A {
|
||||
}
|
||||
|
||||
test_fieldFormalParameter_functionTyped_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
dynamic f;
|
||||
A(void this.f([int a, int? b]));
|
||||
@@ -348,211 +338,205 @@ class A {
|
||||
}
|
||||
|
||||
test_function_external_nonNullable_named_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f({int a = 0});
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nonNullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f({int a});
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nonNullable_named_required_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f({required int a});
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nonNullable_positional_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f([int a = 0]);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nonNullable_positional_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f([int a]);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nonNullable_positional_required_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f(int a);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f({int? a});
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_external_nullable_positional_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
external void f([int? a]);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_native_nonNullable_named_optional_default() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({int a = 0}) native;
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 20, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_native_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({int a}) native;
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 16, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_native_nonNullable_positional_optional_default() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int a = 0]) native;
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 20, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_native_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int a]) native;
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 16, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_named_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({int a = 0}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({int a}) {}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 12, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_named_required() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({required int a}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_positional_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int a = 0]) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int a]) {}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 12, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nonNullable_positional_required() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(int a) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nullable_named_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({int? a = 0}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({int? a}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nullable_named_required() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f({required int? a}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nullable_positional_optional_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int? a = 0]) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nullable_positional_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f([int? a]) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_nullable_positional_required() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(int? a) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionTypeAlias_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef void F({int a, int? b});
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionTypeAlias_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef void F([int a, int? b]);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionTypedFormalParameter_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(void p({int a, int? b})) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionTypedFormalParameter_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(void p([int a, int? b])) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericFunctionType_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(void Function({int a, int? b}) p) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericFunctionType_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(void Function([int a, int? b]) p) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_genericFunctionType_positional_optional2() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void f(void Function([int, int?]) p) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_abstract_nonNullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class C {
|
||||
void foo({int a});
|
||||
}
|
||||
@@ -560,7 +544,7 @@ abstract class C {
|
||||
}
|
||||
|
||||
test_method_abstract_nonNullable_positional_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class C {
|
||||
void foo([int a]);
|
||||
}
|
||||
@@ -568,7 +552,7 @@ abstract class C {
|
||||
}
|
||||
|
||||
test_method_abstract_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class C {
|
||||
void foo({int? a});
|
||||
}
|
||||
@@ -576,7 +560,7 @@ abstract class C {
|
||||
}
|
||||
|
||||
test_method_abstract_potentiallyNonNullable_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {
|
||||
void foo({T a});
|
||||
}
|
||||
@@ -584,7 +568,7 @@ abstract class A<T> {
|
||||
}
|
||||
|
||||
test_method_abstract_potentiallyNonNullable_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T extends Object?> {
|
||||
void foo([T a]);
|
||||
}
|
||||
@@ -592,7 +576,7 @@ abstract class A<T extends Object?> {
|
||||
}
|
||||
|
||||
test_method_external_nonNullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
external void foo({int a});
|
||||
}
|
||||
@@ -600,7 +584,7 @@ class C {
|
||||
}
|
||||
|
||||
test_method_external_nonNullable_positional_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
external void foo([int a]);
|
||||
}
|
||||
@@ -608,7 +592,7 @@ class C {
|
||||
}
|
||||
|
||||
test_method_external_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
external void foo({int? a});
|
||||
}
|
||||
@@ -616,7 +600,7 @@ class C {
|
||||
}
|
||||
|
||||
test_method_external_potentiallyNonNullable_named_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A<T> {
|
||||
external void foo({T a});
|
||||
}
|
||||
@@ -624,7 +608,7 @@ class A<T> {
|
||||
}
|
||||
|
||||
test_method_external_potentiallyNonNullable_positional_optional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A<T extends Object?> {
|
||||
external void foo([T a]);
|
||||
}
|
||||
@@ -632,84 +616,77 @@ class A<T extends Object?> {
|
||||
}
|
||||
|
||||
test_method_native_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
void foo({int a}) native;
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 30, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_native_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
void foo([int a]) native;
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 30, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_native_nullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
void foo({int? a}) native;
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 31, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_native_potentiallyNonNullable_named_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A<T> {
|
||||
void foo({T a}) native;
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 31, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_native_potentiallyNonNullable_positional_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A<T extends Object?> {
|
||||
void foo([T a]) native;
|
||||
// ^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 47, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_nonNullable_named_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
void foo({int a}) {}
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_nonNullable_positional_optional_noDefault() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
void foo([int a]) {}
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_nullable_named_optional_noDefault() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
void foo({int? a}) {}
|
||||
}
|
||||
@@ -717,29 +694,27 @@ class C {
|
||||
}
|
||||
|
||||
test_method_potentiallyNonNullable_named_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A<T extends Object?> {
|
||||
void foo({T a}) {}
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameter, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_potentiallyNonNullable_positional_optional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A<T extends Object?> {
|
||||
void foo([T a]) {}
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterPositional, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_forward_wildcards() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
final int x, y;
|
||||
A(this.x, [this.y = 0]);
|
||||
@@ -758,16 +733,15 @@ class MissingDefaultValueForParameterWithAnnotationTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_method_withAnnotation() async {
|
||||
writeTestPackageConfigWithMeta();
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
// ignore: deprecated_member_use
|
||||
void foo({@required int a}) {}
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterWithAnnotation] With null safety, use the 'required' keyword, not the '@required' annotation.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingDefaultValueForParameterWithAnnotation, 105, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,38 +2,23 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MissingEnumConstantInSwitchTest);
|
||||
defineReflectiveTests(MissingEnumConstantInSwitchTest_Language219);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingEnumConstantInSwitchTest extends PubPackageResolutionTest
|
||||
with MissingEnumConstantInSwitchTestCases {
|
||||
@override
|
||||
bool get _arePatternsEnabled => true;
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingEnumConstantInSwitchTest_Language219
|
||||
extends PubPackageResolutionTest
|
||||
with WithLanguage219Mixin, MissingEnumConstantInSwitchTestCases {
|
||||
@override
|
||||
bool get _arePatternsEnabled => false;
|
||||
}
|
||||
|
||||
mixin MissingEnumConstantInSwitchTestCases on PubPackageResolutionTest {
|
||||
bool get _arePatternsEnabled;
|
||||
|
||||
class MissingEnumConstantInSwitchTest extends PubPackageResolutionTest {
|
||||
test_all_enhanced() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E {
|
||||
one, two;
|
||||
|
||||
@@ -52,7 +37,7 @@ void f(E e) {
|
||||
}
|
||||
|
||||
test_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
@@ -67,95 +52,71 @@ void f(E e) {
|
||||
}
|
||||
|
||||
test_first() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.one'.
|
||||
case E.two:
|
||||
case E.three:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
if (!_arePatternsEnabled)
|
||||
error(diag.missingEnumConstantInSwitch, 44, 10)
|
||||
else
|
||||
error(diag.nonExhaustiveSwitchStatement, 44, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_last() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.three'.
|
||||
case E.one:
|
||||
case E.two:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
if (!_arePatternsEnabled)
|
||||
error(diag.missingEnumConstantInSwitch, 44, 10)
|
||||
else
|
||||
error(diag.nonExhaustiveSwitchStatement, 44, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_middle() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.two'.
|
||||
case E.one:
|
||||
case E.three:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
if (!_arePatternsEnabled)
|
||||
error(diag.missingEnumConstantInSwitch, 44, 10)
|
||||
else
|
||||
error(diag.nonExhaustiveSwitchStatement, 44, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two }
|
||||
|
||||
void f(E? e) {
|
||||
switch (e) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E?' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'null'.
|
||||
case E.one:
|
||||
case E.two:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
if (!_arePatternsEnabled)
|
||||
error(diag.missingEnumConstantInSwitch, 38, 10)
|
||||
else
|
||||
error(diag.nonExhaustiveSwitchStatement, 38, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullable_default() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two }
|
||||
|
||||
void f(E? e) {
|
||||
@@ -170,7 +131,142 @@ void f(E? e) {
|
||||
}
|
||||
|
||||
test_nullable_null() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two }
|
||||
|
||||
void f(E? e) {
|
||||
switch (e) {
|
||||
case E.one:
|
||||
break;
|
||||
case E.two:
|
||||
break;
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingEnumConstantInSwitchTest_Language219
|
||||
extends PubPackageResolutionTest
|
||||
with WithLanguage219Mixin {
|
||||
test_all_enhanced() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E {
|
||||
one, two;
|
||||
|
||||
static const x = 0;
|
||||
}
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
case E.one:
|
||||
break;
|
||||
case E.two:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_default() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
case E.one:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_first() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^^^^^
|
||||
// [diag.missingEnumConstantInSwitch] Missing case clause for 'one'.
|
||||
case E.two:
|
||||
case E.three:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_last() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^^^^^
|
||||
// [diag.missingEnumConstantInSwitch] Missing case clause for 'three'.
|
||||
case E.one:
|
||||
case E.two:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_middle() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^^^^^
|
||||
// [diag.missingEnumConstantInSwitch] Missing case clause for 'two'.
|
||||
case E.one:
|
||||
case E.three:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullable() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two }
|
||||
|
||||
void f(E? e) {
|
||||
switch (e) {
|
||||
//^^^^^^^^^^
|
||||
// [diag.missingEnumConstantInSwitch] Missing case clause for 'null'.
|
||||
case E.one:
|
||||
case E.two:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullable_default() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two }
|
||||
|
||||
void f(E? e) {
|
||||
switch (e) {
|
||||
case E.one:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_nullable_null() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two }
|
||||
|
||||
void f(E? e) {
|
||||
@@ -188,8 +284,7 @@ void f(E? e) {
|
||||
|
||||
test_parenthesized() async {
|
||||
// TODO(johnniwinther): Re-enable this test for the patterns feature.
|
||||
if (_arePatternsEnabled) return;
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { one, two, three }
|
||||
|
||||
void f(E e) {
|
||||
|
||||
@@ -2,30 +2,30 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MissingExceptionValueTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingExceptionValueTest extends PubPackageResolutionTest {
|
||||
test_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Int8 Function(Int8);
|
||||
int f(int i) => i * 2;
|
||||
void g() {
|
||||
Pointer.fromFunction<T>(f);
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.missingExceptionValue] The method fromFunction must have an exceptional return value (the second argument) when the return type of the function is neither 'void', 'Handle', nor 'Pointer'.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingExceptionValue, 96, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,35 @@
|
||||
// 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(MissingFieldTypeInStructTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingFieldTypeInStructTest extends PubPackageResolutionTest {
|
||||
test_missing() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
external var str;
|
||||
// ^^^
|
||||
// [diag.missingFieldTypeInStruct] Fields in struct classes must have an explicitly declared type of 'int', 'double' or 'Pointer'.
|
||||
|
||||
external Pointer notEmpty;
|
||||
}
|
||||
''',
|
||||
[error(diag.missingFieldTypeInStruct, 65, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_valid() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final class C extends Struct {
|
||||
external Pointer p;
|
||||
|
||||
+82
-104
@@ -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(MissingOverrideOfMustBeOverriddenTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,8 +23,7 @@ class MissingOverrideOfMustBeOverriddenTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_field() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -32,27 +32,25 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 86, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_field_declaredInPrimaryConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A(@mustBeOverridden var int f);
|
||||
|
||||
class B(super.f) extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 79, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_field_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -64,20 +62,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.missingOverrideOfMustBeOverriddenTwo,
|
||||
121,
|
||||
1,
|
||||
messageContains: ["'f'", "'m'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenTwo] Missing a required override of 'm' and 'f'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_field_overriddenWithField() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -92,7 +83,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_field_overriddenWithField_inPrimaryConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -105,7 +96,7 @@ class B(var int f) extends A;
|
||||
}
|
||||
|
||||
test_field_overriddenWithGetterSetterPair() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -122,8 +113,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_field_overriddenWithOnlyGetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -132,15 +122,15 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'.
|
||||
int get f => 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 86, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_finalField_overriddenWithOnlyGetter() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -155,8 +145,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -165,13 +154,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 91, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_getter_overriddenWithField() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -186,7 +175,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_getter_overriddenWithField_inPrimaryConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -199,7 +188,7 @@ class B(var int f) extends A;
|
||||
}
|
||||
|
||||
test_getter_overriddenWithGetter() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -214,8 +203,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_method_directMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
mixin M {
|
||||
@@ -224,14 +212,13 @@ mixin M {
|
||||
}
|
||||
|
||||
class A with M {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 87, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_directSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -240,14 +227,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 87, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_directSuperclass_three() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -262,14 +248,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenThreePlus, 157, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenThreePlus] Missing a required override of 'm', 'n', and 1 more.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_directSuperclass_two() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -281,13 +266,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenTwo, 122, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenTwo] Missing a required override of 'm' and 'n'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_hasAbstractOverride_isOkBecauseNotConcreteClass() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -302,7 +287,7 @@ abstract class B extends A {
|
||||
}
|
||||
|
||||
test_method_hasConcreteOverride() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -317,7 +302,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_method_hasNoSuchMethod() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -332,8 +317,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_method_indirectMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
mixin M {
|
||||
@@ -346,14 +330,13 @@ class A with M {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 121, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_indirectSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -366,14 +349,13 @@ class B extends A {
|
||||
}
|
||||
|
||||
class C extends B {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 124, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_indirectSuperclass_oneErrorPerName() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -387,14 +369,13 @@ class B extends A {
|
||||
}
|
||||
|
||||
class C extends B {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 144, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_mixinApplication() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
mixin A {
|
||||
@@ -403,9 +384,9 @@ mixin A {
|
||||
}
|
||||
|
||||
class B = Object with A;
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 87, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'm'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_notVisible() async {
|
||||
@@ -418,7 +399,7 @@ class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:test/a.dart';
|
||||
|
||||
class B extends A {}
|
||||
@@ -426,7 +407,7 @@ class B extends A {}
|
||||
}
|
||||
|
||||
test_method_overriddenWithMethod_wildcardParams() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class C {
|
||||
@@ -442,7 +423,7 @@ class A extends C {
|
||||
}
|
||||
|
||||
test_method_overriddenWithMethod_wildcardParams_preWildcards() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
// @dart = 3.4
|
||||
// (pre wildcard-variables)
|
||||
|
||||
@@ -461,7 +442,7 @@ class A extends C {
|
||||
}
|
||||
|
||||
test_method_sealedClassIsImplicitlyAbstract() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -474,7 +455,7 @@ sealed class B extends A {}
|
||||
}
|
||||
|
||||
test_method_superconstraint_isOkBecauseMixinsAreNotConcrete() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -487,8 +468,7 @@ mixin M on A {}
|
||||
}
|
||||
|
||||
test_operator_directSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -497,14 +477,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 107, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of '+'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -513,14 +492,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 100, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of 'f'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_unary_operator() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -529,13 +507,13 @@ class A {
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.missingOverrideOfMustBeOverriddenOne, 96, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.missingOverrideOfMustBeOverriddenOne] Missing a required override of '-'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_unary_operator_overriden() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustBeOverridden
|
||||
|
||||
@@ -2,45 +2,43 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MissingRequiredParamTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingRequiredParamTest extends PubPackageResolutionTest {
|
||||
test_annotation_noImportPrefix_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A.named({required int a});
|
||||
}
|
||||
|
||||
@A.named()
|
||||
// ^^^^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
void f() {}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 51, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_annotation_noImportPrefix_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A({required int a});
|
||||
}
|
||||
|
||||
@A()
|
||||
// [diag.missingRequiredArgument][column 2][length 1] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
void f() {}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_annotation_withImportPrefix_named() async {
|
||||
@@ -50,15 +48,14 @@ class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' as a;
|
||||
|
||||
@a.A.named()
|
||||
// ^^^^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
void f() {}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 28, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_annotation_withImportPrefix_unnamed() async {
|
||||
@@ -68,19 +65,18 @@ class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' as a;
|
||||
|
||||
@a.A()
|
||||
// ^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
void f() {}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 26, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_argumentGiven() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C({required int a}) {}
|
||||
}
|
||||
@@ -92,67 +88,62 @@ main() {
|
||||
}
|
||||
|
||||
test_constructor_fieldFormal_missingName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required this.})
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [diag.initializingFormalForNonExistentField] '' isn't a field in the enclosing class.
|
||||
// ^
|
||||
// [diag.missingIdentifier] Expected an identifier.
|
||||
}
|
||||
// [diag.missingFunctionBody][column 1][length 1] A function body must be provided.
|
||||
|
||||
void f() {
|
||||
A();
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.initializingFormalForNonExistentField, 15, 14),
|
||||
error(diag.missingIdentifier, 29, 1),
|
||||
error(diag.missingFunctionBody, 32, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_missingArgument() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C({required int a}) {}
|
||||
}
|
||||
main() {
|
||||
new C();
|
||||
// ^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 52, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_redirectingConstructorCall() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C({required int x});
|
||||
C.named() : this();
|
||||
// ^^^^^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'x' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 47, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_superCall() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C({required int a}) {}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
D() : super();
|
||||
// ^^^^^^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 66, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_superFormalParameter() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int a});
|
||||
}
|
||||
@@ -164,79 +155,73 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_enumConstant_withArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v();
|
||||
//^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
const E({required int a});
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 11, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enumConstant_withoutArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
//^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
const E({required int a});
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 11, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({required int a}) {}
|
||||
|
||||
main() {
|
||||
f();
|
||||
//^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_call() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({required int a}) {}
|
||||
|
||||
main() {
|
||||
f.call();
|
||||
// ^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 46, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionInvocation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void Function({required int a}) f() => throw '';
|
||||
g() {
|
||||
f()();
|
||||
//^^^^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 57, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void m({required int a}) {}
|
||||
}
|
||||
f() {
|
||||
new A().m();
|
||||
// ^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 58, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_inOtherLib() async {
|
||||
@@ -245,29 +230,27 @@ class A {
|
||||
void m({required int a}) {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import "a_lib.dart";
|
||||
f() {
|
||||
new A().m();
|
||||
// ^
|
||||
// [diag.missingRequiredArgument] The named parameter 'a' is required, but there's no corresponding argument.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 37, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_function() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
String test(C c) => c.m()();
|
||||
// ^^^^^^^
|
||||
// [diag.missingRequiredArgument] The named parameter 'x' is required, but there's no corresponding argument.
|
||||
|
||||
typedef String F({required String x});
|
||||
|
||||
class C {
|
||||
F m() => ({required String x}) => throw '';
|
||||
}
|
||||
''',
|
||||
[error(diag.missingRequiredArgument, 20, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(MissingSizeAnnotationArray);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingSizeAnnotationArray extends PubPackageResolutionTest {
|
||||
test_one() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
@@ -27,15 +28,14 @@ final class C extends Struct {
|
||||
}
|
||||
|
||||
test_two() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
external Array<Uint8> a0;
|
||||
// ^^^^^^^^^^^^
|
||||
// [diag.missingSizeAnnotationCarray] Fields of type 'Array' must have exactly one 'Array' annotation.
|
||||
}
|
||||
''',
|
||||
[error(diag.missingSizeAnnotationCarray, 62, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,32 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MissingVariablePatternTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MissingVariablePatternTest extends PubPackageResolutionTest {
|
||||
test_ifCase_differentStatements_nested() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case final a) {
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
if (x case final b) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 35, 1),
|
||||
error(diag.unusedLocalVariable, 61, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node1 = findNode.caseClause('case final a').guardedPattern;
|
||||
assertResolvedNodeText(node1, r'''
|
||||
@@ -48,7 +47,7 @@ GuardedPattern
|
||||
pattern: DeclaredVariablePattern
|
||||
keyword: final
|
||||
name: b
|
||||
declaredFragment: isFinal isPublic b@61
|
||||
declaredFragment: isFinal isPublic b@160
|
||||
element: hasImplicitType isFinal isPublic
|
||||
type: int
|
||||
matchedValueType: int
|
||||
@@ -56,18 +55,16 @@ GuardedPattern
|
||||
}
|
||||
|
||||
test_ifCase_differentStatements_sibling() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case final a) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
if (x case final b) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 35, 1),
|
||||
error(diag.unusedLocalVariable, 60, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node1 = findNode.caseClause('case final a').guardedPattern;
|
||||
assertResolvedNodeText(node1, r'''
|
||||
@@ -87,7 +84,7 @@ GuardedPattern
|
||||
pattern: DeclaredVariablePattern
|
||||
keyword: final
|
||||
name: b
|
||||
declaredFragment: isFinal isPublic b@60
|
||||
declaredFragment: isFinal isPublic b@159
|
||||
element: hasImplicitType isFinal isPublic
|
||||
type: int
|
||||
matchedValueType: int
|
||||
@@ -95,18 +92,17 @@ GuardedPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr2_both_direct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case final a || final a) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 35, 1),
|
||||
error(diag.deadCode, 37, 10),
|
||||
error(diag.unusedLocalVariable, 46, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -130,17 +126,15 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr2_both_nested_logicalAnd() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case 0 && final a || final a) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 40, 1),
|
||||
error(diag.unusedLocalVariable, 51, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -172,17 +166,15 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr2_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
if (x case final int a || 2) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 39, 1),
|
||||
error(diag.missingVariablePattern, 44, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -208,17 +200,15 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr2_right() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case 1 || final a) {}
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.missingVariablePattern, 29, 1),
|
||||
error(diag.unusedLocalVariable, 40, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -240,18 +230,17 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
if (x case final int a || 2 || 3) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 39, 1),
|
||||
error(diag.missingVariablePattern, 44, 1),
|
||||
error(diag.missingVariablePattern, 49, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -285,18 +274,17 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_12() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
if (x case final int a || final int a || 3) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 39, 1),
|
||||
error(diag.unusedLocalVariable, 54, 1),
|
||||
error(diag.missingVariablePattern, 59, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -336,20 +324,21 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_123() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case final a || final a || final a) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 35, 1),
|
||||
error(diag.deadCode, 37, 10),
|
||||
error(diag.unusedLocalVariable, 46, 1),
|
||||
error(diag.deadCode, 48, 10),
|
||||
error(diag.unusedLocalVariable, 57, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -383,18 +372,17 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_13() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
if (x case final int a || 2 || final int a) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 39, 1),
|
||||
error(diag.missingVariablePattern, 44, 1),
|
||||
error(diag.unusedLocalVariable, 59, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -434,18 +422,17 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
if (x case 1 || final int a || 3) {}
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.missingVariablePattern, 29, 1),
|
||||
error(diag.unusedLocalVariable, 44, 1),
|
||||
error(diag.missingVariablePattern, 49, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -479,19 +466,19 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_23() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case 1 || final a || final a) {}
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.missingVariablePattern, 29, 1),
|
||||
error(diag.unusedLocalVariable, 40, 1),
|
||||
error(diag.deadCode, 42, 10),
|
||||
error(diag.unusedLocalVariable, 51, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -523,17 +510,15 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_ifCase_logicalOr3_3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
if (x case 1 || 2 || final a) {}
|
||||
// ^^^^^^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.missingVariablePattern, 29, 6),
|
||||
error(diag.unusedLocalVariable, 45, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -563,21 +548,20 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_switchStatement_case1_logicalOr2_both() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
case final a || final a:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 46, 1),
|
||||
error(diag.deadCode, 48, 10),
|
||||
error(diag.unusedLocalVariable, 57, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -601,22 +585,20 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_switchStatement_case1_logicalOr2_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
switch (x) {
|
||||
case final int a || 2:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 50, 1),
|
||||
error(diag.missingVariablePattern, 55, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -642,20 +624,18 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_switchStatement_case1_logicalOr2_right() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
case 1 || final a:
|
||||
// ^
|
||||
// [diag.missingVariablePattern] Variable pattern 'a' is missing in this branch of the logical-or pattern.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.missingVariablePattern, 40, 1),
|
||||
error(diag.unusedLocalVariable, 51, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
var node = findNode.singleGuardedPattern.pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
LogicalOrPattern
|
||||
@@ -677,23 +657,22 @@ LogicalOrPattern
|
||||
}
|
||||
|
||||
test_switchStatement_case2_both() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
case /*1*/ final a:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
case /*2*/ final a:
|
||||
// ^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
// [diag.unreachableSwitchCase] This case is covered by the previous cases.
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 52, 1),
|
||||
error(diag.deadCode, 59, 4),
|
||||
error(diag.unreachableSwitchCase, 59, 4),
|
||||
error(diag.unusedLocalVariable, 76, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node1 = findNode.switchPatternCase('case /*1*/').guardedPattern;
|
||||
assertResolvedNodeText(node1, r'''
|
||||
@@ -713,7 +692,7 @@ GuardedPattern
|
||||
pattern: DeclaredVariablePattern
|
||||
keyword: final
|
||||
name: a
|
||||
declaredFragment: isFinal isPublic a@76
|
||||
declaredFragment: isFinal isPublic a@177
|
||||
element: hasImplicitType isFinal isPublic
|
||||
type: int
|
||||
matchedValueType: int
|
||||
@@ -721,43 +700,42 @@ GuardedPattern
|
||||
}
|
||||
|
||||
test_switchStatement_case2_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
switch (x) {
|
||||
case final double a:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
case 2:
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 53, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_switchStatement_case2_right() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
case 1:
|
||||
case final a:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 58, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_switchStatement_differentCases_nested() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
case final a:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
switch (x) {
|
||||
case 2:
|
||||
return;
|
||||
@@ -765,17 +743,16 @@ void f(int x) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 46, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_switchStatement_differentCases_sibling() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(num x) {
|
||||
switch (x) {
|
||||
case final double a:
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
|
||||
return;
|
||||
case 2:
|
||||
return;
|
||||
@@ -783,8 +760,6 @@ void f(num x) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedLocalVariable, 53, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -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(MixinApplicationConcreteSuperInvokedMemberTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,8 +18,7 @@ main() {
|
||||
class MixinApplicationConcreteSuperInvokedMemberTypeTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class I {
|
||||
void foo([int? p]) {}
|
||||
}
|
||||
@@ -38,13 +38,13 @@ mixin M on I {
|
||||
}
|
||||
|
||||
abstract class X extends B with M {}
|
||||
''',
|
||||
[error(diag.mixinApplicationConcreteSuperInvokedMemberType, 227, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationConcreteSuperInvokedMemberType] The super-invoked member 'foo' has the type 'void Function([int?])', and the concrete member in the class has the type 'void Function(int?)'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method_OK_overriddenInMixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {
|
||||
void remove(T x) {}
|
||||
}
|
||||
@@ -60,8 +60,7 @@ class X<T> = A<T> with M<T>;
|
||||
}
|
||||
|
||||
test_enum_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class I {
|
||||
void foo([int? p]);
|
||||
}
|
||||
@@ -79,11 +78,11 @@ mixin M3 on I {
|
||||
}
|
||||
|
||||
enum E with M1, M2, M3 {
|
||||
// ^^
|
||||
// [diag.mixinApplicationConcreteSuperInvokedMemberType] The super-invoked member 'foo' has the type 'void Function([int?])', and the concrete member in the class has the type 'void Function(int?)'.
|
||||
v;
|
||||
void foo([int? p]) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinApplicationConcreteSuperInvokedMemberType, 183, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+44
-51
@@ -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(MixinApplicationNoConcreteSuperInvokedMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,8 +18,7 @@ main() {
|
||||
class MixinApplicationNoConcreteSuperInvokedMemberTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
int get foo;
|
||||
}
|
||||
@@ -30,14 +30,13 @@ mixin M on A {
|
||||
}
|
||||
|
||||
abstract class X extends A with M {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedMember, 121, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_inNextMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -53,14 +52,13 @@ mixin M2 on A {
|
||||
}
|
||||
|
||||
class X extends A with M1, M2 {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedMember, 149, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_inSameMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -72,14 +70,13 @@ mixin M on A {
|
||||
}
|
||||
|
||||
class X extends A with M {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedMember, 113, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -91,13 +88,13 @@ mixin M on A {
|
||||
}
|
||||
|
||||
abstract class X extends A with M {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedMember, 122, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_OK_hasNSM() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -117,7 +114,7 @@ class X extends C with M {}
|
||||
}
|
||||
|
||||
test_class_OK_hasNSM2() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -141,7 +138,7 @@ class X extends C with M {}
|
||||
}
|
||||
|
||||
test_class_OK_inPreviousMixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -161,7 +158,7 @@ class X extends A with M1, M2 {}
|
||||
}
|
||||
|
||||
test_class_OK_inSuper_fromMixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -183,7 +180,7 @@ class X extends B with M2 {}
|
||||
}
|
||||
|
||||
test_class_OK_notInvoked() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
@@ -195,7 +192,7 @@ abstract class X extends A with M {}
|
||||
}
|
||||
|
||||
test_class_OK_super_covariant() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
bar(num n) {}
|
||||
}
|
||||
@@ -215,8 +212,7 @@ class C extends B with M {}
|
||||
}
|
||||
|
||||
test_class_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void set foo(_);
|
||||
}
|
||||
@@ -228,14 +224,13 @@ mixin M on A {
|
||||
}
|
||||
|
||||
abstract class X extends A with M {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedSetter, 129, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedSetter] The class doesn't have a concrete implementation of the super-invoked setter 'foo'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {
|
||||
int get foo;
|
||||
}
|
||||
@@ -247,16 +242,16 @@ mixin M2 on M1 {
|
||||
}
|
||||
|
||||
enum E with M1, M2 {
|
||||
// ^^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'.
|
||||
v;
|
||||
int get foo => 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedMember, 99, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_getter_exists() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {
|
||||
int get foo => 0;
|
||||
}
|
||||
@@ -274,7 +269,7 @@ enum E with M1, M2 {
|
||||
}
|
||||
|
||||
test_enum_getter_index() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M on Enum {
|
||||
void foo() {
|
||||
super.index;
|
||||
@@ -288,8 +283,7 @@ enum E with M {
|
||||
}
|
||||
|
||||
test_enum_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {
|
||||
void foo();
|
||||
}
|
||||
@@ -301,16 +295,16 @@ mixin M2 on M1 {
|
||||
}
|
||||
|
||||
enum E with M1, M2 {
|
||||
// ^^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedMember] The class doesn't have a concrete implementation of the super-invoked member 'foo'.
|
||||
v;
|
||||
void foo() {}
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedMember, 100, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_method_exists() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -328,7 +322,7 @@ enum E with M1, M2 {
|
||||
}
|
||||
|
||||
test_enum_OK_getter_inPreviousMixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {
|
||||
int get foo => 0;
|
||||
}
|
||||
@@ -346,8 +340,7 @@ enum E with M1, M2 {
|
||||
}
|
||||
|
||||
test_enum_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {
|
||||
set foo(int _);
|
||||
}
|
||||
@@ -359,11 +352,11 @@ mixin M2 on M1 {
|
||||
}
|
||||
|
||||
enum E with M1, M2 {
|
||||
// ^^
|
||||
// [diag.mixinApplicationNoConcreteSuperInvokedSetter] The class doesn't have a concrete implementation of the super-invoked setter 'foo'.
|
||||
v;
|
||||
set foo(int _) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinApplicationNoConcreteSuperInvokedSetter, 106, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+58
-72
@@ -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(MixinApplicationNotImplementedInterfaceTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,23 +19,22 @@ class MixinApplicationNotImplementedInterfaceTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_hasRecursion() async {
|
||||
// https://github.com/dart-lang/sdk/issues/61829
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
abstract class X with Unresolved, M, CycleWithX {}
|
||||
// ^
|
||||
// [diag.recursiveInterfaceInheritance] 'X' can't be a superinterface of itself: CycleWithX, X.
|
||||
// ^^^^^^^^^^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
mixin M on A {}
|
||||
mixin CycleWithX on X {}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveInterfaceInheritance, 26, 1),
|
||||
error(diag.mixinOfNonClass, 33, 10),
|
||||
error(diag.recursiveInterfaceInheritance, 84, 10),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.recursiveInterfaceInheritance] 'CycleWithX' can't be a superinterface of itself: CycleWithX, X.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_matchingInterface() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {}
|
||||
class B {}
|
||||
mixin M<T> on A<T> {}
|
||||
@@ -43,7 +43,7 @@ class C extends A<int> with M {}
|
||||
}
|
||||
|
||||
test_class_matchingInterface_inPreviousMixin() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {}
|
||||
class B {}
|
||||
mixin M1 implements A<B> {}
|
||||
@@ -53,45 +53,39 @@ class C extends Object with M1, M2 {}
|
||||
}
|
||||
|
||||
test_class_noMatchingInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {}
|
||||
class B {}
|
||||
mixin M<T> on A<T> {}
|
||||
class C extends Object with M {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 84, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M<dynamic>' can't be mixed onto 'Object' because 'Object' doesn't implement 'A<dynamic>'.
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
test_class_noMatchingInterface_fromAugmentation() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class B with M {}
|
||||
mixin M {}
|
||||
class A {}
|
||||
augment mixin M on A {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 13, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_noMatchingInterface_withTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {}
|
||||
class B {}
|
||||
mixin M<T> on A<T> {}
|
||||
class C extends Object with M<int> {}
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 84, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M<int>' can't be mixed onto 'Object' because 'Object' doesn't implement 'A<int>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_noMemberErrors() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -107,13 +101,13 @@ class C {
|
||||
}
|
||||
|
||||
class X = C with M;
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 134, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'C' because 'C' doesn't implement 'A'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_noSuperclassConstraint() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {}
|
||||
class B {}
|
||||
mixin M<T> {}
|
||||
@@ -123,13 +117,15 @@ class C extends Object with M {}
|
||||
|
||||
test_class_recursiveSubtypeCheck() async {
|
||||
// See dartbug.com/32353 for a detailed explanation.
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class ioDirectory implements ioFileSystemEntity {}
|
||||
|
||||
class ioFileSystemEntity {}
|
||||
|
||||
abstract class _LocalDirectory
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.conflictingGenericInterfaces] The class '_LocalDirectory' can't implement both 'ForwardingFileSystemEntity<_LocalDirectory, ioDirectory>' and 'ForwardingFileSystemEntity<Directory, ioDirectory>' because the type arguments are different.
|
||||
// [diag.unusedElement] The declaration '_LocalDirectory' isn't referenced.
|
||||
extends _LocalFileSystemEntity<_LocalDirectory, ioDirectory>
|
||||
with ForwardingDirectory, DirectoryAddOnsMixin {}
|
||||
|
||||
@@ -149,57 +145,49 @@ mixin ForwardingDirectory<T extends Directory>
|
||||
abstract class Directory implements FileSystemEntity, ioDirectory {}
|
||||
|
||||
mixin DirectoryAddOnsMixin implements Directory {}
|
||||
''',
|
||||
[
|
||||
error(diag.conflictingGenericInterfaces, 96, 15),
|
||||
error(diag.unusedElement, 96, 15),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var mixins = findElement2.class_('_LocalDirectory').mixins;
|
||||
assertType(mixins[0], 'ForwardingDirectory<Directory>');
|
||||
}
|
||||
|
||||
test_classTypeAlias_generic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
|
||||
mixin M on A<int> {}
|
||||
|
||||
class X = A<double> with M;
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 62, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'A<double>' because 'A<double>' doesn't implement 'A<int>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_noMatchingInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A<T> {}
|
||||
class B {}
|
||||
mixin M<T> on A<T> {}
|
||||
class C = Object with M;
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 78, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M<dynamic>' can't be mixed onto 'Object' because 'Object' doesn't implement 'A<dynamic>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_notGeneric() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
mixin M on A {}
|
||||
|
||||
class X = Object with M;
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_OK_0() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {}
|
||||
|
||||
class X = Object with M;
|
||||
@@ -207,7 +195,7 @@ class X = Object with M;
|
||||
}
|
||||
|
||||
test_classTypeAlias_OK_1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
mixin M on A {}
|
||||
@@ -217,7 +205,7 @@ class X = A with M;
|
||||
}
|
||||
|
||||
test_classTypeAlias_OK_generic() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
|
||||
mixin M<T> on A<T> {}
|
||||
@@ -229,7 +217,7 @@ class C<T> = B<T> with M<T>;
|
||||
}
|
||||
|
||||
test_classTypeAlias_OK_previousMixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
mixin M1 implements A {}
|
||||
@@ -241,8 +229,7 @@ class X = Object with M1, M2;
|
||||
}
|
||||
|
||||
test_classTypeAlias_oneOfTwo() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B {}
|
||||
class C {}
|
||||
@@ -250,13 +237,13 @@ class C {}
|
||||
mixin M on A, B {}
|
||||
|
||||
class X = C with M;
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 71, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'C' because 'C' doesn't implement 'A'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_matchingInterface_inPreviousMixin() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {}
|
||||
|
||||
mixin M1 implements A {}
|
||||
@@ -270,22 +257,21 @@ enum E with M1, M2 {
|
||||
}
|
||||
|
||||
test_enum_noMatchingInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {}
|
||||
|
||||
mixin M on A {}
|
||||
|
||||
enum E with M {
|
||||
// ^
|
||||
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Enum' because 'Enum' doesn't implement 'A'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinApplicationNotImplementedInterface, 50, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_noSuperclassConstraint() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
mixin M {}
|
||||
|
||||
enum E with M {
|
||||
|
||||
@@ -2,66 +2,58 @@
|
||||
// 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(MixinClassDeclarationTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinClassDeclarationTest extends PubPackageResolutionTest {
|
||||
test_class_extends_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin class B extends A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclarationExtendsNotObject, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_Object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A extends Object {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extends_Object_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {}
|
||||
mixin class A extends Object with M {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclarationWithClause, 40, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinClassDeclarationWithClause] The class 'A' can't be declared a mixin because it has a 'with' clause.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_with() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {}
|
||||
mixin class A = Object with M;
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_with2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M1 {}
|
||||
mixin M2 {}
|
||||
mixin class A = Object with M1, M2;
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.mixinModifierMixinApplicationClassWithMultipleMixins,
|
||||
47,
|
||||
11,
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'A' can only have a single mixin.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+82
-98
@@ -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(
|
||||
MixinClassDeclaresNonTrivialGenerativeConstructorTest,
|
||||
);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ main() {
|
||||
class MixinClassDeclaresNonTrivialGenerativeConstructorTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_mixinClass_constructor_factory_blockBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A.named();
|
||||
factory A.x() {
|
||||
@@ -31,7 +32,7 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_factory_redirect() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A.named();
|
||||
factory A.x() = A.named;
|
||||
@@ -41,68 +42,63 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_generative_redirect() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A() : this.named();
|
||||
//^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
A.named();
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_newHead_nonTrivial_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
new() {}
|
||||
//^^^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_newHead_nonTrivial_external() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
external new();
|
||||
// ^^^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 27, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_newHead_nonTrivial_hasFormalParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
new(int foo);
|
||||
//^^^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_newHead_nonTrivial_super() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
new(): super();
|
||||
//^^^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_newHead_trivial() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
new();
|
||||
}
|
||||
@@ -111,7 +107,7 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_newHead_trivial_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
const new();
|
||||
}
|
||||
@@ -120,7 +116,7 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_trivial_named() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A.named();
|
||||
}
|
||||
@@ -129,7 +125,7 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_trivial_named_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
const A.named();
|
||||
}
|
||||
@@ -138,67 +134,62 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_nonTrivial_blockBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A() {}
|
||||
//^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_nonTrivial_blockBody_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A.named() {}
|
||||
//^^^^^^^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_nonTrivial_external() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
external A();
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_nonTrivial_hasFormalParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A(int foo);
|
||||
//^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_nonTrivial_super() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A(): super();
|
||||
//^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 18, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_trivial() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
A();
|
||||
}
|
||||
@@ -207,7 +198,7 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_constructor_typeName_trivial_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {
|
||||
const A();
|
||||
}
|
||||
@@ -216,48 +207,45 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_named_nonTrivial_hasBody_block() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A.named() {
|
||||
this {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 31, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_named_nonTrivial_hasFormalParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A.named(int x) {}
|
||||
// ^^^^^^^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 12, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_named_nonTrivial_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A.named() {
|
||||
this : assert(true);
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 31, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_named_trivial() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A.named() {}
|
||||
class B with A {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_named_trivial_hasBody_empty() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A.named() {
|
||||
this;
|
||||
}
|
||||
@@ -266,60 +254,56 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasBody_block() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A() {
|
||||
this {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasBody_block_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A() {
|
||||
this : assert(true) {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasFormalParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A(int x) {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 12, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_unnamed_nonTrivial_hasInitializer() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A() {
|
||||
this : assert(true);
|
||||
// ^
|
||||
// [diag.mixinClassDeclaresNonTrivialGenerativeConstructor] The mixin class 'A' can't declare a non-trivial generative constructor.
|
||||
}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclaresNonTrivialGenerativeConstructor, 25, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_unnamed_trivial() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A() {}
|
||||
class B with A {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_primaryConstructor_unnamed_trivial_hasBody_empty() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A() {
|
||||
this;
|
||||
}
|
||||
|
||||
@@ -2,28 +2,28 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MixinDeclaresConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinDeclaresConstructorTest extends PubPackageResolutionTest {
|
||||
test_factory_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
factory M.named() => throw 0;
|
||||
//^^^^^^^
|
||||
// [diag.mixinDeclaresConstructor] Mixins can't declare constructors.
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinDeclaresConstructor, 12, 7)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -40,14 +40,13 @@ invalidNodes
|
||||
}
|
||||
|
||||
test_factory_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
factory M() => throw 0;
|
||||
//^^^^^^^
|
||||
// [diag.mixinDeclaresConstructor] Mixins can't declare constructors.
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinDeclaresConstructor, 12, 7)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -64,14 +63,13 @@ invalidNodes
|
||||
}
|
||||
|
||||
test_generative_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
M.named();
|
||||
//^
|
||||
// [diag.mixinDeclaresConstructor] Mixins can't declare constructors.
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinDeclaresConstructor, 12, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -88,14 +86,13 @@ invalidNodes
|
||||
}
|
||||
|
||||
test_generative_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
M();
|
||||
//^
|
||||
// [diag.mixinDeclaresConstructor] Mixins can't declare constructors.
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinDeclaresConstructor, 12, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinDeclaration;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -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(MixinDeferredClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,36 +21,30 @@ class MixinDeferredClassTest extends PubPackageResolutionTest {
|
||||
library lib1;
|
||||
class A {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class B {}
|
||||
class C = B with a.A;
|
||||
''',
|
||||
[
|
||||
error(diag.mixinDeferredClass, 76, 3),
|
||||
error(diag.classUsedAsMixin, 76, 3),
|
||||
],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinDeferredClass] Classes can't mixin deferred classes.
|
||||
// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class A {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
enum E with a.A {
|
||||
// ^^^
|
||||
// [diag.mixinDeferredClass] Classes can't mixin deferred classes.
|
||||
// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinDeferredClass, 43, 3),
|
||||
error(diag.classUsedAsMixin, 43, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_deferred_class() async {
|
||||
@@ -57,16 +52,13 @@ enum E with a.A {
|
||||
library lib1;
|
||||
class A {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
class B extends Object with a.A {}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinDeferredClass, 76, 3),
|
||||
error(diag.classUsedAsMixin, 76, 3),
|
||||
],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinDeferredClass] Classes can't mixin deferred classes.
|
||||
// [diag.classUsedAsMixin] The class 'A' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -5,10 +5,12 @@
|
||||
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(MixinInferenceNoPossibleSubstitutionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,7 +18,7 @@ main() {
|
||||
class MixinInferenceNoPossibleSubstitutionTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_valid_single() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T> {}
|
||||
|
||||
mixin M<T> on A<T> {}
|
||||
|
||||
@@ -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(MixinInheritsFromNotObjectTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinInheritsFromNotObjectTest extends PubPackageResolutionTest {
|
||||
test_class_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin class B extends A {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'.
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinClassDeclarationExtendsNotObject, 33, 1),
|
||||
error(diag.mixinInheritsFromNotObject, 66, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_class_extends_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 74, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_class_extends_Object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin class B extends Object {}
|
||||
class C extends Object with B {}
|
||||
@@ -50,7 +48,7 @@ class C extends Object with B {}
|
||||
}
|
||||
|
||||
test_class_class_extends_Object_language219() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends Object {}
|
||||
@@ -59,33 +57,30 @@ class C extends Object with B {}
|
||||
}
|
||||
|
||||
test_class_class_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B extends Object with A {}
|
||||
// ^^^^^^
|
||||
// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause.
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinClassDeclarationWithClause, 46, 6),
|
||||
error(diag.mixinInheritsFromNotObject, 84, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_class_with_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends Object with A {}
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 86, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_classTypeAlias_with() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B = Object with A;
|
||||
class C extends Object with B {}
|
||||
@@ -93,35 +88,32 @@ class C extends Object with B {}
|
||||
}
|
||||
|
||||
test_class_classTypeAlias_with2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B {}
|
||||
mixin class C = Object with A, B;
|
||||
// ^^^^^^^^^
|
||||
// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'C' can only have a single mixin.
|
||||
class D extends Object with C {}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinModifierMixinApplicationClassWithMultipleMixins, 57, 9),
|
||||
error(diag.mixinInheritsFromNotObject, 96, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_classTypeAlias_with2_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B {}
|
||||
class C = Object with A, B;
|
||||
class D extends Object with C {}
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 92, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_classTypeAlias_with_language219() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B = Object with A;
|
||||
@@ -130,7 +122,7 @@ class C extends Object with B {}
|
||||
}
|
||||
|
||||
test_class_mixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin B on A {}
|
||||
class C extends A with B {}
|
||||
@@ -138,59 +130,53 @@ class C extends A with B {}
|
||||
}
|
||||
|
||||
test_classTypeAlias_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin class B extends A {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'.
|
||||
class C = Object with B;
|
||||
''',
|
||||
[
|
||||
error(diag.mixinClassDeclarationExtendsNotObject, 33, 1),
|
||||
error(diag.mixinInheritsFromNotObject, 60, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_class_extends_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C = Object with B;
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 68, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_class_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B extends Object with A {}
|
||||
// ^^^^^^
|
||||
// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause.
|
||||
class C = Object with B;
|
||||
''',
|
||||
[
|
||||
error(diag.mixinClassDeclarationWithClause, 46, 6),
|
||||
error(diag.mixinInheritsFromNotObject, 78, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_class_with_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends Object with A {}
|
||||
class C = Object with B;
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 80, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_classAlias_with() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B = Object with A;
|
||||
class C = Object with B;
|
||||
@@ -198,35 +184,32 @@ class C = Object with B;
|
||||
}
|
||||
|
||||
test_classTypeAlias_classAlias_with2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B {}
|
||||
mixin class C = Object with A, B;
|
||||
// ^^^^^^^^^
|
||||
// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'C' can only have a single mixin.
|
||||
class D = Object with C;
|
||||
''',
|
||||
[
|
||||
error(diag.mixinModifierMixinApplicationClassWithMultipleMixins, 57, 9),
|
||||
error(diag.mixinInheritsFromNotObject, 90, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_classAlias_with2_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B {}
|
||||
class C = Object with A, B;
|
||||
class D = Object with C;
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 86, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_classAlias_with_language219() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B = Object with A;
|
||||
@@ -235,7 +218,7 @@ class C = Object with B;
|
||||
}
|
||||
|
||||
test_classTypeAlias_mixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin B on A {}
|
||||
class C = A with B;
|
||||
@@ -243,37 +226,34 @@ class C = A with B;
|
||||
}
|
||||
|
||||
test_enum_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin class B extends A {}
|
||||
// ^
|
||||
// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'.
|
||||
enum E with B {
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinClassDeclarationExtendsNotObject, 33, 1),
|
||||
error(diag.mixinInheritsFromNotObject, 50, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_class_extends_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends A {}
|
||||
enum E with B {
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 58, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_class_extends_Object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
mixin class B extends Object {}
|
||||
enum E with B {
|
||||
@@ -283,7 +263,7 @@ enum E with B {
|
||||
}
|
||||
|
||||
test_enum_class_extends_Object_language219() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends Object {}
|
||||
@@ -294,37 +274,34 @@ enum E with B {
|
||||
}
|
||||
|
||||
test_enum_class_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B extends Object with A {}
|
||||
// ^^^^^^
|
||||
// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause.
|
||||
enum E with B {
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinClassDeclarationWithClause, 46, 6),
|
||||
error(diag.mixinInheritsFromNotObject, 68, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_class_with_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B extends Object with A {}
|
||||
enum E with B {
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'B' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 70, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_classTypeAlias_with() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B = Object with A;
|
||||
enum E with B {
|
||||
@@ -334,36 +311,34 @@ enum E with B {
|
||||
}
|
||||
|
||||
test_enum_classTypeAlias_with2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B {}
|
||||
class C = Object with A, B;
|
||||
enum E with C {
|
||||
// ^
|
||||
// [diag.classUsedAsMixin] The class 'C' can't be used as a mixin because it's neither a mixin class nor a mixin.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.classUsedAsMixin, 74, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_classTypeAlias_with2_language219() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B {}
|
||||
class C = Object with A, B;
|
||||
enum E with C {
|
||||
// ^
|
||||
// [diag.mixinInheritsFromNotObject] The class 'C' can't be used as a mixin because it extends a class other than 'Object'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinInheritsFromNotObject, 76, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_classTypeAlias_with_language219() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart=2.19
|
||||
class A {}
|
||||
class B = Object with A;
|
||||
@@ -374,56 +349,52 @@ enum E with B {
|
||||
}
|
||||
|
||||
test_mixinClass_class_extends() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B extends A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclarationExtendsNotObject, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinClassDeclarationExtendsNotObject] The class 'B' can't be declared a mixin because it extends a class other than 'Object'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_class_extends_Object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A extends Object {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_class_extends_Object_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B extends Object with A {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclarationWithClause, 46, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinClassDeclarationWithClause] The class 'B' can't be declared a mixin because it has a 'with' clause.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_class_with() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {}
|
||||
mixin class A with M {}
|
||||
''',
|
||||
[error(diag.mixinClassDeclarationWithClause, 25, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinClassDeclarationWithClause] The class 'A' can't be declared a mixin because it has a 'with' clause.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_classTypeAlias_with() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B = Object with A;
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinClass_classTypeAlias_with2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
mixin class B {}
|
||||
mixin class C = Object with A, B;
|
||||
''',
|
||||
[error(diag.mixinModifierMixinApplicationClassWithMultipleMixins, 57, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.mixinModifierMixinApplicationClassWithMultipleMixins] The mixin application class 'C' can only have a single mixin.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +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(MixinInstantiateTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinInstantiateTest extends PubPackageResolutionTest {
|
||||
test_namedConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
M.named() {}
|
||||
//^
|
||||
// [diag.mixinDeclaresConstructor] Mixins can't declare constructors.
|
||||
}
|
||||
|
||||
void f() {
|
||||
new M.named();
|
||||
// ^
|
||||
// [diag.mixinInstantiate] Mixins can't be instantiated.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.mixinDeclaresConstructor, 12, 1),
|
||||
error(diag.mixinInstantiate, 45, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleInstanceCreationExpression;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -57,16 +56,15 @@ invalidNodes
|
||||
}
|
||||
|
||||
test_unnamedConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {}
|
||||
|
||||
void f() {
|
||||
new M();
|
||||
// ^
|
||||
// [diag.mixinInstantiate] Mixins can't be instantiated.
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinInstantiate, 29, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.singleInstanceCreationExpression;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -2,85 +2,79 @@
|
||||
// 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(MixinOfDisallowedClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinOfDisallowedClassTest extends PubPackageResolutionTest {
|
||||
test_class_bool() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with bool {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_bool_augment() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
augment class A with bool {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 33, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_double() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with double {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'double'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_FutureOr() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'dart:async';
|
||||
class A extends Object with FutureOr {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 49, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr<dynamic>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_FutureOr_typeArgument() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'dart:async';
|
||||
class A extends Object with FutureOr<int> {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 49, 13)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr<int>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_FutureOr_typeVariable() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'dart:async';
|
||||
class A<T> extends Object with FutureOr<T> {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 52, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr<T>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with int {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
@@ -96,138 +90,124 @@ augment class A with int {}
|
||||
''');
|
||||
|
||||
await assertErrorsInFile2(a, []);
|
||||
await assertErrorsInFile2(b, [error(diag.mixinOfDisallowedClass, 39, 3)]);
|
||||
await assertErrorsInFile2(b, []);
|
||||
}
|
||||
|
||||
test_class_Null() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with Null {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'Null'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_num() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with num {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_Record() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with Record {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'Record'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_String() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A extends Object with String {}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'String'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_bool() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with bool;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_double() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with double;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'double'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_FutureOr() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
class A {}
|
||||
class C = A with FutureOr;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 49, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'FutureOr<dynamic>'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with int;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'int'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_Null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with Null;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'Null'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with num;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_String() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with String;
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 28, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'String'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_String_num() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class C = A with String, num;
|
||||
''',
|
||||
[
|
||||
error(diag.mixinOfDisallowedClass, 28, 6),
|
||||
error(diag.mixinOfDisallowedClass, 36, 3),
|
||||
],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'String'.
|
||||
// ^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'num'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_int() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E with int {
|
||||
// ^^^
|
||||
// [diag.mixinOfDisallowedClass] Classes can't mixin 'int'.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinOfDisallowedClass, 12, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
@@ -243,6 +223,6 @@ augment enum A with int {}
|
||||
''');
|
||||
|
||||
await assertErrorsInFile2(a, []);
|
||||
await assertErrorsInFile2(b, [error(diag.mixinOfDisallowedClass, 38, 3)]);
|
||||
await assertErrorsInFile2(b, []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,152 +2,142 @@
|
||||
// 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(MixinOfNonClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinOfNonClassTest extends PubPackageResolutionTest {
|
||||
test_class_enum() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E { ONE }
|
||||
class A extends Object with E {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 43, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_extensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(int it) {}
|
||||
class B with A {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 41, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_topLevelVariable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int A = 7;
|
||||
class B extends Object with A {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_typeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
int B = 7;
|
||||
class C = A with B;
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_undefined() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C with M {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 13, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_enum() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E1 { v }
|
||||
enum E2 with E1 { v }
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 27, 2)],
|
||||
);
|
||||
// ^^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_extensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(int it) {}
|
||||
enum E with A { v }
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 40, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_topLevelVariable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int A = 7;
|
||||
enum E with A {
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_undefined() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E with M {
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
v
|
||||
}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 12, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_Never() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A with Never {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 13, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_import_prefix() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' as p;
|
||||
// ^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'a.dart'.
|
||||
|
||||
class C with p.M {}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_import_show_it() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' show M;
|
||||
// ^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'a.dart'.
|
||||
|
||||
class C with M {}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_import_show_other() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart' show N;
|
||||
// ^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'a.dart'.
|
||||
|
||||
class C with M {}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 7, 8), error(diag.mixinOfNonClass, 38, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_part_exists_uriGenerated_nameIgnorable() async {
|
||||
@@ -155,71 +145,68 @@ class C with M {}
|
||||
part of 'test.dart';
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'a.g.dart';
|
||||
|
||||
class C with _$M {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 31, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_part_notExist_uriGenerated_nameIgnorable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'a.g.dart';
|
||||
// ^^^^^^^^^^
|
||||
// [diag.uriHasNotBeenGenerated] Target of URI hasn't been generated: 'package:test/a.g.dart'.
|
||||
|
||||
class C with _$M {}
|
||||
''',
|
||||
[error(diag.uriHasNotBeenGenerated, 5, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_part_notExist_uriGenerated_nameNotIgnorable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'a.g.dart';
|
||||
// ^^^^^^^^^^
|
||||
// [diag.uriHasNotBeenGenerated] Target of URI hasn't been generated: 'package:test/a.g.dart'.
|
||||
|
||||
class C with M {}
|
||||
''',
|
||||
[
|
||||
error(diag.uriHasNotBeenGenerated, 5, 10),
|
||||
error(diag.mixinOfNonClass, 31, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_part_notExist_uriNotGenerated_nameIgnorable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'a.dart';
|
||||
// ^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'package:test/a.dart'.
|
||||
|
||||
class C with _$M {}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 5, 8), error(diag.mixinOfNonClass, 29, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_ignore_part_notExist_uriNotGenerated_nameNotIgnorable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'a.dart';
|
||||
// ^^^^^^^^
|
||||
// [diag.uriDoesNotExist] Target of URI doesn't exist: 'package:test/a.dart'.
|
||||
|
||||
class C with M {}
|
||||
''',
|
||||
[error(diag.uriDoesNotExist, 5, 8), error(diag.mixinOfNonClass, 29, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefined_import_exists_prefixed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:math' as p;
|
||||
|
||||
class C with p.M {}
|
||||
''',
|
||||
[error(diag.mixinOfNonClass, 39, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinOfNonClass] Classes can only mix in mixins and classes.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -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(MixinOfTypeAliasExpandsToTypeParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ main() {
|
||||
class MixinOfTypeAliasExpandsToTypeParameterTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
typedef T = A;
|
||||
class B with A {}
|
||||
@@ -25,24 +26,22 @@ class B with A {}
|
||||
}
|
||||
|
||||
test_class_noTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
typedef T<X extends A> = X;
|
||||
class B with T {}
|
||||
''',
|
||||
[error(diag.mixinOfTypeAliasExpandsToTypeParameter, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be mixed in.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_withTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {}
|
||||
typedef T<X extends A> = X;
|
||||
class B with T<A> {}
|
||||
''',
|
||||
[error(diag.mixinOfTypeAliasExpandsToTypeParameter, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOfTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be mixed in.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/package_config_file_builder.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MixinOnSealedClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,17 +35,15 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:foo/foo.dart';
|
||||
mixin Bar on Foo {}
|
||||
''',
|
||||
[error(diag.mixinOnSealedClass, 31, 19)],
|
||||
);
|
||||
// [diag.mixinOnSealedClass][column 1][length 19] The class 'Foo' shouldn't be used as a mixin constraint because it is sealed, and any class mixing in this mixin must have 'Foo' as a superclass.
|
||||
''');
|
||||
}
|
||||
|
||||
test_withinLibrary_OK() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
mixin Bar on Foo {}
|
||||
|
||||
+11
-12
@@ -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(MixinOnTypeAliasExpandsToTypeParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ main() {
|
||||
class MixinOnTypeAliasExpandsToTypeParameterTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
typedef T = A;
|
||||
mixin M on A {}
|
||||
@@ -25,24 +26,22 @@ mixin M on A {}
|
||||
}
|
||||
|
||||
test_class_noTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
typedef T<X extends A> = X;
|
||||
mixin M on T {}
|
||||
''',
|
||||
[error(diag.mixinOnTypeAliasExpandsToTypeParameter, 50, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOnTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be used as a superclass constraint.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_withTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
typedef T<X extends A> = X;
|
||||
mixin M on T<A> {}
|
||||
''',
|
||||
[error(diag.mixinOnTypeAliasExpandsToTypeParameter, 50, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinOnTypeAliasExpandsToTypeParameter] A type alias that expands to a type parameter can't be used as a superclass constraint.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,100 +2,56 @@
|
||||
// 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/analysis_rule/analysis_rule.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MixinSubtypeOfBaseIsNotBaseTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinSubtypeOfBaseIsNotBaseTest extends PubPackageResolutionTest {
|
||||
test_class_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
mixin B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfBaseIsNotBase,
|
||||
22,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'B' must be 'base' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfBaseIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_implements_indirect() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B implements A {}
|
||||
mixin C implements B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfBaseIsNotBase,
|
||||
53,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'C' must be 'base' because the supertype 'A' is 'base'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
11,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfBaseIsNotBase][context 1] The mixin 'C' must be 'base' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_on() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base class A {}
|
||||
mixin B on A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfBaseIsNotBase,
|
||||
22,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'B' must be 'base' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfBaseIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
base mixin A {}
|
||||
mixin B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfBaseIsNotBase,
|
||||
22,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'B' must be 'base' because the supertype 'A' is 'base'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfBaseIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'base'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,82 +2,47 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:analyzer_testing/analysis_rule/analysis_rule.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MixinSubtypeOfFinalIsNotBaseTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinSubtypeOfFinalIsNotBaseTest extends PubPackageResolutionTest {
|
||||
test_implements() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
mixin B implements A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfFinalIsNotBase,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'B' must be 'base' because the supertype 'A' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfFinalIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_implements_indirect() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
// ^
|
||||
// [context 1] The type 'B' is a subtype of 'A', and 'A' is defined here.
|
||||
sealed class B implements A {}
|
||||
mixin C implements B {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfFinalIsNotBase,
|
||||
54,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'C' must be 'base' because the supertype 'A' is 'final'.",
|
||||
contextMessages: [
|
||||
contextMessage(
|
||||
testFile,
|
||||
12,
|
||||
1,
|
||||
textContains: [
|
||||
"The type 'B' is a subtype of 'A', and 'A' is defined here.",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfFinalIsNotBase][context 1] The mixin 'C' must be 'base' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_on() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final class A {}
|
||||
mixin B on A {}
|
||||
''',
|
||||
[
|
||||
this.error(
|
||||
diag.mixinSubtypeOfFinalIsNotBase,
|
||||
23,
|
||||
1,
|
||||
text:
|
||||
"The mixin 'B' must be 'base' because the supertype 'A' is 'final'.",
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSubtypeOfFinalIsNotBase] The mixin 'B' must be 'base' because the supertype 'A' is 'final'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -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(MixinSuperClassConstraintDeferredClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,13 +18,12 @@ main() {
|
||||
class MixinSuperClassConstraintDeferredClassTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_error_onClause_deferredClass() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:math' deferred as math;
|
||||
mixin M on math.Random {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintDeferredClass, 48, 11)],
|
||||
);
|
||||
// ^^^^^^^^^^^
|
||||
// [diag.mixinSuperClassConstraintDeferredClass] Deferred classes can't be used as superclass constraints.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
+12
-15
@@ -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(MixinSuperClassConstraintDisallowedClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,19 +18,18 @@ main() {
|
||||
class MixinSuperClassConstraintDisallowedClassTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_dartCoreEnum() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M on Enum {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_dartCoreEnum_language216() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.16
|
||||
mixin M on Enum {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintDisallowedClass, 27, 4)],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.mixinSuperClassConstraintDisallowedClass] 'Enum' can't be used as a superclass constraint.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -56,18 +56,15 @@ augment mixin A on int {}
|
||||
''');
|
||||
|
||||
await assertErrorsInFile2(a, []);
|
||||
await assertErrorsInFile2(b, [
|
||||
error(diag.mixinSuperClassConstraintDisallowedClass, 37, 3),
|
||||
]);
|
||||
await assertErrorsInFile2(b, []);
|
||||
}
|
||||
|
||||
test_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M on int {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintDisallowedClass, 11, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.mixinSuperClassConstraintDisallowedClass] 'int' can't be used as a superclass constraint.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
+23
-29
@@ -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(MixinSuperClassConstraintNonInterfaceTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,12 +18,11 @@ main() {
|
||||
class MixinSuperClassConstraintNonInterfaceTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M on dynamic {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintNonInterface, 11, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -37,13 +37,12 @@ MixinOnClause
|
||||
}
|
||||
|
||||
test_enum() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E { v }
|
||||
mixin M on E {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintNonInterface, 24, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -58,13 +57,12 @@ MixinOnClause
|
||||
}
|
||||
|
||||
test_extensionType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A(int it) {}
|
||||
mixin M on A {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintNonInterface, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -79,12 +77,11 @@ MixinOnClause
|
||||
}
|
||||
|
||||
test_Never() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
mixin M on Never {}
|
||||
''',
|
||||
[error(diag.mixinSuperClassConstraintNonInterface, 11, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -99,15 +96,12 @@ MixinOnClause
|
||||
}
|
||||
|
||||
test_void() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M on void {}
|
||||
''',
|
||||
[
|
||||
error(diag.expectedTypeName, 11, 4),
|
||||
error(diag.mixinSuperClassConstraintNonInterface, 11, 4),
|
||||
],
|
||||
);
|
||||
// ^^^^
|
||||
// [diag.expectedTypeName] Expected a type name.
|
||||
// [diag.mixinSuperClassConstraintNonInterface] Only classes and mixins can be used as superclass constraints.
|
||||
''');
|
||||
|
||||
var node = findNode.singleMixinOnClause;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -2,38 +2,37 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MixinWithNonClassSuperclassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinWithNonClassSuperclassTest extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int A = 0;
|
||||
mixin B {}
|
||||
class C extends A with B {}
|
||||
''',
|
||||
[error(diag.mixinWithNonClassSuperclass, 38, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinWithNonClassSuperclass] Mixin can only be applied to class.
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinApplication() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int A = 0;
|
||||
mixin B {}
|
||||
class C = A with B;
|
||||
''',
|
||||
[error(diag.mixinWithNonClassSuperclass, 32, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinWithNonClassSuperclass] Mixin can only be applied to class.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,58 +2,55 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(MixinsSuperClassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MixinsSuperClassTest extends PubPackageResolutionTest {
|
||||
test_class() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
class B extends A with A {}
|
||||
''',
|
||||
[error(diag.mixinsSuperClass, 40, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_viaTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
typedef B = A;
|
||||
class C extends A with B {}
|
||||
''',
|
||||
[error(diag.mixinsSuperClass, 55, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
class B = A with A;
|
||||
''',
|
||||
[error(diag.mixinsSuperClass, 34, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses.
|
||||
''');
|
||||
}
|
||||
|
||||
test_classAlias_viaTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin class A {}
|
||||
typedef B = A;
|
||||
class C = A with B;
|
||||
''',
|
||||
[error(diag.mixinsSuperClass, 49, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mixinsSuperClass] 'mixin class A' can't be used in both the 'extends' and 'with' clauses.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,145 +2,137 @@
|
||||
// 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(MultipleCombinatorsExportTest);
|
||||
defineReflectiveTests(MultipleCombinatorsImportTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MultipleCombinatorsExportTest extends PubPackageResolutionTest {
|
||||
Future<void> test_hide() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async' hide Future, Stream;
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_hide_hide() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async' hide Future, Stream hide Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 20, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_hide_show() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async' hide Future, Stream show Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 20, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_no_combinators() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async';
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_show() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async' show Future, Stream;
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_show_hide() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async' show Future, Stream hide Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 20, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_show_show() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'dart:async' show Future, Stream show Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 20, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MultipleCombinatorsImportTest extends PubPackageResolutionTest {
|
||||
Future<void> test_hide() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' hide Future, Stream;
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_hide_hide() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' hide Future, Stream hide Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 44, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_hide_show() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' hide Future, Stream show Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 44, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_no_combinators() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async';
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_prefixed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' as async hide Future, Stream show Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 53, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_show() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' show Future, Stream;
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_show_hide() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' show Future, Stream hide Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 44, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_show_show() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//ignore: unused_import
|
||||
import 'dart:async' show Future, Stream show Stream;
|
||||
''',
|
||||
[error(diag.multipleCombinators, 44, 31)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.multipleCombinators] Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+26
-29
@@ -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(MultipleRedirectingConstructorInvocationsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,66 +18,62 @@ main() {
|
||||
class MultipleRedirectingConstructorInvocationsTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_primary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B() extends A {
|
||||
B.foo() : this();
|
||||
B.bar() : this();
|
||||
this : this.foo(), this.bar();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.primaryConstructorCannotRedirect, 83, 4),
|
||||
error(diag.primaryConstructorCannotRedirect, 95, 4),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_typeName_twoNamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() : this.foo(), this.bar();
|
||||
// ^^^^^^^^^^
|
||||
// [diag.multipleRedirectingConstructorInvocations] Constructors can have only one 'this' redirection, at most.
|
||||
A.foo() {}
|
||||
A.bar() {}
|
||||
}
|
||||
''',
|
||||
[error(diag.multipleRedirectingConstructorInvocations, 30, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_primary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E() {
|
||||
v;
|
||||
const E.foo() : this();
|
||||
// ^^^^^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
const E.bar() : this();
|
||||
// ^^^^^
|
||||
// [diag.recursiveConstantConstructor] The constant constructor depends on itself.
|
||||
this : this.foo(), this.bar();
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
// ^^^^
|
||||
// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveConstantConstructor, 24, 5),
|
||||
error(diag.recursiveConstantConstructor, 50, 5),
|
||||
error(diag.primaryConstructorCannotRedirect, 77, 4),
|
||||
error(diag.primaryConstructorCannotRedirect, 89, 4),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_typeName_twoNamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E() : this.foo(), this.bar();
|
||||
// ^^^^^^^^^^
|
||||
// [diag.multipleRedirectingConstructorInvocations] Constructors can have only one 'this' redirection, at most.
|
||||
const E.foo();
|
||||
const E.bar();
|
||||
}
|
||||
''',
|
||||
[error(diag.multipleRedirectingConstructorInvocations, 40, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,33 @@
|
||||
// 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(MultipleSuperInitializersTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MultipleSuperInitializersTest extends PubPackageResolutionTest {
|
||||
test_primary_twoSuperInitializers() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
class B() extends A {
|
||||
this : super(), super();
|
||||
// ^^^^^
|
||||
// [diag.multipleSuperInitializers] A constructor can have at most one 'super' initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.multipleSuperInitializers, 51, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_oneSuperInitializer() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
class B extends A {
|
||||
B() : super() {}
|
||||
@@ -37,14 +37,13 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_typeName_twoSuperInitializers() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {}
|
||||
class B extends A {
|
||||
B() : super(), super() {}
|
||||
// ^^^^^^^
|
||||
// [diag.multipleSuperInitializers] A constructor can have at most one 'super' initializer.
|
||||
}
|
||||
''',
|
||||
[error(diag.multipleSuperInitializers, 48, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,64 +2,49 @@
|
||||
// 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(MustBeANativeFunctionTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MustBeANativeFunctionTypeTest extends PubPackageResolutionTest {
|
||||
test_fromFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
int f(int i) => i * 2;
|
||||
class C<T extends Function> {
|
||||
void g() {
|
||||
Pointer.fromFunction<T>(f);
|
||||
// ^
|
||||
// [diag.mustBeANativeFunctionType] The type 'T' given to 'fromFunction' must be a valid 'dart:ffi' native function type.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.mustBeANativeFunctionType,
|
||||
110,
|
||||
1,
|
||||
messageContains: ["The type 'T' given to 'fromFunction' must be"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_lookupFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef S = int Function(int);
|
||||
typedef F = String Function(String);
|
||||
void f(DynamicLibrary lib) {
|
||||
lib.lookupFunction<S, F>('g');
|
||||
// ^
|
||||
// [diag.mustBeANativeFunctionType] The type 'S' given to 'lookupFunction' must be a valid 'dart:ffi' native function type.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.mustBeANativeFunctionType,
|
||||
137,
|
||||
1,
|
||||
messageContains: ["The type 'S' given to 'lookupFunction' must be"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_lookupFunction_Pointer() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef S = Void Function(Pointer);
|
||||
typedef F = void Function(Pointer);
|
||||
@@ -72,21 +57,20 @@ void f(DynamicLibrary lib) {
|
||||
// TODO(dacoharkes): Should this be an error or not?
|
||||
// https://dartbug.com/44594
|
||||
test_lookupFunction_PointerNativeFunction() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef S = Void Function(Pointer<NativeFunction>);
|
||||
typedef F = void Function(Pointer<NativeFunction>);
|
||||
void f(DynamicLibrary lib) {
|
||||
lib.lookupFunction<S, F>('g');
|
||||
// ^
|
||||
// [diag.mustBeANativeFunctionType] The type 'S' given to 'lookupFunction' must be a valid 'dart:ffi' native function type.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeANativeFunctionType, 173, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_lookupFunction_PointerNativeFunction2() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef S = Void Function(Pointer<NativeFunction<Int8 Function()>>);
|
||||
typedef F = void Function(Pointer<NativeFunction<Int8 Function()>>);
|
||||
@@ -97,7 +81,7 @@ void f(DynamicLibrary lib) {
|
||||
}
|
||||
|
||||
test_lookupFunction_PointerVoid() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef S = Pointer<Void> Function(Pointer<Void>);
|
||||
typedef F = Pointer<Void> Function(Pointer<Void>);
|
||||
@@ -108,22 +92,21 @@ void f(DynamicLibrary lib) {
|
||||
}
|
||||
|
||||
test_lookupFunction_T() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef F = int Function(int);
|
||||
class C<T extends Function> {
|
||||
void f(DynamicLibrary lib, NativeFunction x) {
|
||||
lib.lookupFunction<T, F>('g');
|
||||
// ^
|
||||
// [diag.mustBeANativeFunctionType] The type 'T' given to 'lookupFunction' must be a valid 'dart:ffi' native function type.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeANativeFunctionType, 152, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_lookupFunction_VarArgs1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final lib = DynamicLibrary.open('dontcare');
|
||||
final variadicAt1Doublex2 =
|
||||
@@ -137,7 +120,7 @@ final variadicAt1Doublex2 =
|
||||
}
|
||||
|
||||
test_lookupFunction_VarArgs2() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final lib = DynamicLibrary.open('dontcare');
|
||||
final variadicAt1Int64x5Leaf =
|
||||
@@ -152,56 +135,53 @@ final variadicAt1Int64x5Leaf =
|
||||
}
|
||||
|
||||
test_lookupFunction_VarArgs3() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final lib = DynamicLibrary.open('dontcare');
|
||||
final variadicAt1Int64x5Leaf =
|
||||
lib.lookupFunction<
|
||||
Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, Int64)>),
|
||||
int Function(int, int, int, int, double)
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.mustBeASubtype] The type 'Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, Int64)>)' must be a subtype of 'int Function(int, int, int, int, double)' for 'lookupFunction'.
|
||||
>(
|
||||
"VariadicAt1Int64x5",
|
||||
isLeaf:true
|
||||
);
|
||||
''',
|
||||
[error(diag.mustBeASubtype, 187, 40)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_lookupFunction_VarArgs4() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final lib = DynamicLibrary.open('dontcare');
|
||||
final variadicAt1Int64x5Leaf =
|
||||
lib.lookupFunction<
|
||||
Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, {Int64 named})>),
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.mustBeANativeFunctionType] The type 'Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, {Int64 named})>)' given to 'lookupFunction' must be a valid 'dart:ffi' native function type.
|
||||
int Function(int, int, int, int)
|
||||
>(
|
||||
"VariadicAt1Int64x5",
|
||||
isLeaf:true
|
||||
);
|
||||
''',
|
||||
[error(diag.mustBeANativeFunctionType, 121, 68)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_lookupFunction_VarArgs5() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
final lib = DynamicLibrary.open('dontcare');
|
||||
final variadicAt1Int64x5Leaf =
|
||||
lib.lookupFunction<
|
||||
Int64 Function(Int64, VarArgs<(Int64, Int64, Int64)>, Int64),
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.mustBeANativeFunctionType] The type 'Int64 Function(Int64, VarArgs<(Int64, Int64, Int64)>, Int64)' given to 'lookupFunction' must be a valid 'dart:ffi' native function type.
|
||||
int Function(int, int, int, int, int)
|
||||
>(
|
||||
"VariadicAt1Int64x5",
|
||||
isLeaf:true
|
||||
);
|
||||
''',
|
||||
[error(diag.mustBeANativeFunctionType, 121, 60)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,49 +2,48 @@
|
||||
// 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(MustBeASubtypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MustBeASubtypeTest extends PubPackageResolutionTest {
|
||||
test_fromFunction_firstArgument() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Int8 Function(Int8);
|
||||
String f(int i) => i.toString();
|
||||
void g() {
|
||||
Pointer.fromFunction<T>(f, 5);
|
||||
// ^
|
||||
// [diag.mustBeASubtype] The type 'String Function(int)' must be a subtype of 'T' for 'fromFunction'.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeASubtype, 122, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromFunction_secondArgument() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Int8 Function(Int8);
|
||||
int f(int i) => i * 2;
|
||||
void g() {
|
||||
Pointer.fromFunction<T>(f, '');
|
||||
// ^^
|
||||
// [diag.mustBeASubtype] The type 'String' must be a subtype of 'Int8' for 'fromFunction'.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeASubtype, 115, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromFunction_valid_oneArgument() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Void Function(Int8);
|
||||
void f(int i) {}
|
||||
@@ -55,7 +54,7 @@ void g() {
|
||||
}
|
||||
|
||||
test_fromFunction_valid_twoArguments() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Int8 Function(Int8);
|
||||
int f(int i) => i * 2;
|
||||
@@ -66,7 +65,7 @@ void g() {
|
||||
}
|
||||
|
||||
test_fromFunction_valid_voidReturnPermissive() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Void Function(Int8);
|
||||
int f(int i) => i * 2;
|
||||
@@ -77,17 +76,16 @@ void g() {
|
||||
}
|
||||
|
||||
test_lookupFunction_F() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = Int8 Function(Int8);
|
||||
class C<F extends int Function(int)> {
|
||||
void f(DynamicLibrary lib, NativeFunction x) {
|
||||
lib.lookupFunction<T, F>('g');
|
||||
// ^
|
||||
// [diag.mustBeASubtype] The type 'T' must be a subtype of 'F' for 'lookupFunction'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeASubtype, 166, 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(MustBeImmutableTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,58 +23,54 @@ class MustBeImmutableTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_directAnnotation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class A {
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x
|
||||
int x = 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 50, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_directAnnotation_declaredInPrimaryConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class A(var int x);
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 50, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x
|
||||
''');
|
||||
}
|
||||
|
||||
test_directMixinAnnotation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
mixin A {
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x
|
||||
int x = 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 50, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_extendsClassWithAnnotation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class A {}
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: B.x
|
||||
int x = 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 61, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_finalField() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class A {
|
||||
@@ -83,8 +80,7 @@ class A {
|
||||
}
|
||||
|
||||
test_fromMixinWithAnnotation() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class A {}
|
||||
@@ -92,14 +88,13 @@ mixin B {
|
||||
int x = 0;
|
||||
}
|
||||
class C extends A with B {}
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 86, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: B.x
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinApplication() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class A {}
|
||||
@@ -107,14 +102,13 @@ mixin B {
|
||||
int x = 0;
|
||||
}
|
||||
class C = A with B;
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 86, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: B.x
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinApplicationBase() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
int x = 0;
|
||||
@@ -122,13 +116,13 @@ class A {
|
||||
mixin B {}
|
||||
@immutable
|
||||
class C = A with B;
|
||||
''',
|
||||
[error(diag.mustBeImmutable, 86, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.mustBeImmutable] This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: A.x
|
||||
''');
|
||||
}
|
||||
|
||||
test_staticField() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@immutable
|
||||
class 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(MustCallSuperTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ class MustCallSuperTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_containsSuperCall() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -38,8 +39,7 @@ class C extends A {
|
||||
}
|
||||
|
||||
test_fromExtendingClass() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -48,14 +48,14 @@ class A {
|
||||
class B extends A {
|
||||
@override
|
||||
void a() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 115, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_abstractInSubclass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
abstract class A {
|
||||
@mustCallSuper
|
||||
@@ -69,7 +69,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_fromExtendingClass_abstractInSuperclass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
abstract class A {
|
||||
@mustCallSuper
|
||||
@@ -83,8 +83,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_fromExtendingClass_genericClass() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A<T> {
|
||||
@mustCallSuper
|
||||
@@ -93,15 +92,14 @@ class A<T> {
|
||||
class B extends A<int> {
|
||||
@override
|
||||
void a() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 123, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_genericMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -110,15 +108,14 @@ class A {
|
||||
class B extends A {
|
||||
@override
|
||||
void a<T>() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 118, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -127,14 +124,14 @@ class A {
|
||||
class B extends A {
|
||||
@override
|
||||
int get a => 2;
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 122, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_getter_containsSuperCall() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -151,8 +148,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_fromExtendingClass_getter_invokesSuper_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -164,18 +160,17 @@ class A {
|
||||
|
||||
class B extends A {
|
||||
int get foo {
|
||||
// ^^^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
super.foo = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 135, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_operator() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -184,14 +179,14 @@ class A {
|
||||
class B extends A {
|
||||
@override
|
||||
operator ==(Object o) => o is B;
|
||||
// ^^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 140, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_operator_containsSuperCall() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -205,8 +200,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_fromExtendingClass_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -215,14 +209,14 @@ class A {
|
||||
class B extends A {
|
||||
@override
|
||||
set a(int value) {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 122, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromExtendingClass_setter_containsSuperCall() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -238,8 +232,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_fromExtendingClass_setter_invokesSuper_getter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -251,16 +244,16 @@ class A {
|
||||
|
||||
class B extends A {
|
||||
set foo(int _) {
|
||||
// ^^^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
super.foo;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 131, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromInterface() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -274,8 +267,7 @@ class C implements A {
|
||||
}
|
||||
|
||||
test_fromMixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
mixin Mixin {
|
||||
@mustCallSuper
|
||||
@@ -284,15 +276,14 @@ mixin Mixin {
|
||||
class C with Mixin {
|
||||
@override
|
||||
void a() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'Mixin', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 120, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromMixin_setter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
mixin Mixin {
|
||||
@mustCallSuper
|
||||
@@ -301,15 +292,14 @@ mixin Mixin {
|
||||
class C with Mixin {
|
||||
@override
|
||||
void set a(int value) {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'Mixin', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 137, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fromMixin_throughExtendingClass() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
mixin M {
|
||||
@mustCallSuper
|
||||
@@ -319,15 +309,14 @@ class C with M {}
|
||||
class D extends C {
|
||||
@override
|
||||
void a() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'M', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 133, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_indirectlyInherited() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -342,15 +331,14 @@ class C extends A {
|
||||
class D extends C {
|
||||
@override
|
||||
void a() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 181, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_indirectlyInheritedFromMixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
mixin Mixin {
|
||||
@mustCallSuper
|
||||
@@ -360,15 +348,14 @@ class C extends Object with Mixin {}
|
||||
class D extends C {
|
||||
@override
|
||||
void b() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'Mixin', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 156, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_indirectlyInheritedFromMixinConstraint() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -377,15 +364,15 @@ class A {
|
||||
mixin C on A {
|
||||
@override
|
||||
void a() {}
|
||||
// ^
|
||||
// [diag.mustCallSuper] This method overrides a method annotated as '@mustCallSuper' in 'A', but doesn't invoke the overridden method.
|
||||
}
|
||||
''',
|
||||
[error(diag.mustCallSuper, 110, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_overriddenWithFuture() async {
|
||||
// https://github.com/flutter/flutter/issues/11646
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
@@ -405,7 +392,7 @@ class C extends A {
|
||||
|
||||
test_overriddenWithFuture2() async {
|
||||
// https://github.com/flutter/flutter/issues/11646
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@mustCallSuper
|
||||
|
||||
@@ -2,25 +2,25 @@
|
||||
// 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(NativeClauseInNonSdkCodeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NativeClauseInNonSdkCodeTest extends PubPackageResolutionTest {
|
||||
test_nativeClauseInNonSDKCode() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A native 'string' {}
|
||||
''',
|
||||
[error(diag.nativeClauseInNonSdkCode, 8, 15)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [diag.nativeClauseInNonSdkCode] Native clause can only be used in the SDK and code that is loaded through native extensions.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(NativeFunctionBodyInNonSdkCodeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NativeFunctionBodyInNonSdkCodeTest extends PubPackageResolutionTest {
|
||||
test_function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int m(a) native 'string';
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 9, 16)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
static int m(a) native 'string';
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 28, 16)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixinMethod() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin A {
|
||||
static int m(a) native 'string';
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [diag.nativeFunctionBodyInNonSdkCode] Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
||||
}
|
||||
''',
|
||||
[error(diag.nativeFunctionBodyInNonSdkCode, 28, 16)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +2,30 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NewWithNonTypeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NewWithNonTypeTest extends PubPackageResolutionTest {
|
||||
test_functionTypeAlias() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
typedef F = void Function();
|
||||
|
||||
void foo() {
|
||||
new F();
|
||||
// ^
|
||||
// [diag.newWithNonType] The name 'F' isn't a class.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithNonType, 49, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.namedType('F()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -40,28 +40,26 @@ NamedType
|
||||
newFile('$testPackageLibPath/lib.dart', '''
|
||||
class B {}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'lib.dart' as lib;
|
||||
void f() {
|
||||
new lib.A();
|
||||
// ^
|
||||
// [diag.newWithNonType] The name 'A' isn't a class.
|
||||
}
|
||||
lib.B b = lib.B();
|
||||
''',
|
||||
[error(diag.newWithNonType, 47, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_local() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var A = 0;
|
||||
void f() {
|
||||
new A();
|
||||
// ^
|
||||
// [diag.newWithNonType] The name 'A' isn't a class.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithNonType, 28, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.namedType('A()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -73,15 +71,14 @@ NamedType
|
||||
}
|
||||
|
||||
test_local_withTypeArguments() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var A = 0;
|
||||
void f() {
|
||||
new A<int>();
|
||||
// ^
|
||||
// [diag.newWithNonType] The name 'A' isn't a class.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithNonType, 28, 1)],
|
||||
);
|
||||
''');
|
||||
|
||||
var node = findNode.namedType('A<int>()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -101,27 +98,25 @@ NamedType
|
||||
}
|
||||
|
||||
test_malformed_constructor_call() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
C.x();
|
||||
}
|
||||
main() {
|
||||
new C.x.y();
|
||||
// ^^^
|
||||
// [diag.newWithNonType] The name 'x' isn't a class.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithNonType, 36, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void foo<T>() {
|
||||
new T();
|
||||
// ^
|
||||
// [diag.newWithNonType] The name 'T' isn't a class.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithNonType, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -13,6 +13,7 @@ main() {
|
||||
defineReflectiveTests(
|
||||
NewWithUndefinedConstructorWithoutConstructorTearoffsTest,
|
||||
);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,38 +23,29 @@ class NewWithUndefinedConstructorTest extends PubPackageResolutionTest
|
||||
|
||||
mixin NewWithUndefinedConstructorTestCases on PubPackageResolutionTest {
|
||||
test_default() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A.name() {}
|
||||
}
|
||||
f() {
|
||||
new A();
|
||||
// ^
|
||||
// [diag.newWithUndefinedConstructorDefault] The class 'A' doesn't have an unnamed constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.newWithUndefinedConstructorDefault,
|
||||
38,
|
||||
1,
|
||||
messageContains: ["'A'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_default_noKeyword() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A.name() {}
|
||||
}
|
||||
f() {
|
||||
A();
|
||||
//^
|
||||
// [diag.newWithUndefinedConstructorDefault] The class 'A' doesn't have an unnamed constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithUndefinedConstructorDefault, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_default_prefixed() async {
|
||||
@@ -62,41 +54,32 @@ class A {
|
||||
A.name() {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'lib1.dart' as lib1;
|
||||
|
||||
f() {
|
||||
new lib1.A();
|
||||
// ^^^^^^
|
||||
// [diag.newWithUndefinedConstructorDefault] The class 'lib1.A' doesn't have an unnamed constructor.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.newWithUndefinedConstructorDefault,
|
||||
41,
|
||||
6,
|
||||
messageContains: ["'lib1.A'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_default_unnamedViaNew() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A.name() {}
|
||||
}
|
||||
f() {
|
||||
A.new();
|
||||
// ^^^
|
||||
// [diag.newWithUndefinedConstructorDefault] The class 'A' doesn't have an unnamed constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithUndefinedConstructorDefault, 36, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_defaultViaNew() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A.new() {}
|
||||
}
|
||||
@@ -107,7 +90,7 @@ f() {
|
||||
}
|
||||
|
||||
test_defined_named() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.name() {}
|
||||
}
|
||||
@@ -118,7 +101,7 @@ f() {
|
||||
}
|
||||
|
||||
test_defined_unnamed() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
@@ -129,24 +112,16 @@ f() {
|
||||
}
|
||||
|
||||
test_named() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
f() {
|
||||
new A.name();
|
||||
// ^^^^
|
||||
// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named 'name'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.newWithUndefinedConstructor,
|
||||
35,
|
||||
4,
|
||||
messageContains: ["class 'A'", "named 'name'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_named_prefixed() async {
|
||||
@@ -155,22 +130,14 @@ class A {
|
||||
A() {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'lib1.dart' as lib1;
|
||||
f() {
|
||||
new lib1.A.name();
|
||||
// ^^^^
|
||||
// [diag.newWithUndefinedConstructor] The class 'lib1.A' doesn't have a constructor named 'name'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.newWithUndefinedConstructor,
|
||||
47,
|
||||
4,
|
||||
messageContains: ["class 'lib1.A'", "named 'name'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_named() async {
|
||||
@@ -179,15 +146,14 @@ class A {
|
||||
A._named() {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
void f() {
|
||||
new A._named();
|
||||
// ^^^^^^
|
||||
// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named '_named'.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithUndefinedConstructor, 36, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_named_genericClass_noTypeArguments() async {
|
||||
@@ -196,15 +162,14 @@ class A<T> {
|
||||
A._named() {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
void f() {
|
||||
new A._named();
|
||||
// ^^^^^^
|
||||
// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named '_named'.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithUndefinedConstructor, 36, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_named_genericClass_withTypeArguments() async {
|
||||
@@ -213,15 +178,14 @@ class A<T> {
|
||||
A._named() {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
void f() {
|
||||
new A<int>._named();
|
||||
// ^^^^^^
|
||||
// [diag.newWithUndefinedConstructor] The class 'A' doesn't have a constructor named '_named'.
|
||||
}
|
||||
''',
|
||||
[error(diag.newWithUndefinedConstructor, 41, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,30 +194,28 @@ class NewWithUndefinedConstructorWithoutConstructorTearoffsTest
|
||||
extends PubPackageResolutionTest
|
||||
with WithoutConstructorTearoffsMixin {
|
||||
test_defaultViaNew() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A.new() {}
|
||||
// ^^^
|
||||
// [diag.experimentNotEnabled] This requires the 'constructor-tearoffs' language feature to be enabled.
|
||||
}
|
||||
f() {
|
||||
A();
|
||||
}
|
||||
''',
|
||||
[error(diag.experimentNotEnabled, 14, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_unnamedViaNew() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
A.named() {}
|
||||
}
|
||||
f() {
|
||||
A.new();
|
||||
// ^^^
|
||||
// [diag.experimentNotEnabled] This requires the 'constructor-tearoffs' language feature to be enabled.
|
||||
}
|
||||
''',
|
||||
[error(diag.experimentNotEnabled, 37, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +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(NoAnnotationConstructorArgumentsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NoAnnotationConstructorArgumentsTest extends PubPackageResolutionTest {
|
||||
test_missingArgumentList() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
@A
|
||||
// [diag.noAnnotationConstructorArguments][column 1][length 2] Annotation creation must have arguments.
|
||||
main() {
|
||||
}
|
||||
''',
|
||||
[error(diag.noAnnotationConstructorArguments, 25, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NoCombinedSuperSignatureTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NoCombinedSuperSignatureTest extends PubPackageResolutionTest {
|
||||
test_conflictingParameter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
void foo(int x);
|
||||
}
|
||||
@@ -28,10 +28,10 @@ abstract class B {
|
||||
|
||||
abstract class C implements A, B {
|
||||
foo(num x);
|
||||
//^^^
|
||||
// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.foo (void Function(int)), B.foo (void Function(double)).
|
||||
}
|
||||
''',
|
||||
[error(diag.noCombinedSuperSignature, 122, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
/// If the method is subject to override inference, it is already an error
|
||||
@@ -40,8 +40,7 @@ abstract class C implements A, B {
|
||||
/// It does not matter that the conflicting component (the return type here)
|
||||
/// was resolved.
|
||||
test_conflictingReturnType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
int foo(int x);
|
||||
}
|
||||
@@ -52,15 +51,14 @@ abstract class B {
|
||||
|
||||
abstract class C implements A, B {
|
||||
Never foo(x);
|
||||
// ^^^
|
||||
// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.foo (int Function(int)), B.foo (double Function(int)).
|
||||
}
|
||||
''',
|
||||
[error(diag.noCombinedSuperSignature, 126, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noInvalidOverrideErrors() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
String foo(String a);
|
||||
}
|
||||
@@ -71,9 +69,9 @@ abstract class B {
|
||||
|
||||
abstract class C implements A, B {
|
||||
foo(a);
|
||||
//^^^
|
||||
// [diag.noCombinedSuperSignature] Can't infer missing types in 'C' from overridden methods: A.foo (String Function(String)), B.foo (int Function(int)).
|
||||
}
|
||||
''',
|
||||
[error(diag.noCombinedSuperSignature, 123, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,46 +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(NoDefaultSuperConstructorExplicitTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NoDefaultSuperConstructorExplicitTest extends PubPackageResolutionTest {
|
||||
test_requiredNamed_constructor_typeName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.16
|
||||
class A {
|
||||
A({required int a});
|
||||
}
|
||||
class B extends A {
|
||||
B.foo();
|
||||
//^^^^^
|
||||
// [diag.noDefaultSuperConstructorExplicit] The superclass 'A' doesn't have a zero argument constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.noDefaultSuperConstructorExplicit, 73, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_requiredPositional_constructor_typeName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.16
|
||||
class A {
|
||||
A(int a);
|
||||
}
|
||||
class B extends A {
|
||||
B.foo();
|
||||
//^^^^^
|
||||
// [diag.noDefaultSuperConstructorExplicit] The superclass 'A' doesn't have a zero argument constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.noDefaultSuperConstructorExplicit, 62, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NoDefaultSuperConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NoDefaultSuperConstructorTest extends PubPackageResolutionTest {
|
||||
test_super_implicit_subclass_explicit_constructor_newHead() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B extends A {
|
||||
new named();
|
||||
@@ -25,7 +26,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_implicit_subclass_explicit_constructor_typeName() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B extends A {
|
||||
B.named();
|
||||
@@ -34,7 +35,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_implicit_subclass_explicit_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B() extends A {
|
||||
this;
|
||||
@@ -43,21 +44,21 @@ class B() extends A {
|
||||
}
|
||||
|
||||
test_super_implicit_subclass_explicit_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B() extends A;
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_implicit_subclass_implicit() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
class B extends A {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_noParameters() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A();
|
||||
}
|
||||
@@ -68,7 +69,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_explicit_constructor_newHead() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -79,7 +80,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_explicit_constructor_typeName() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -90,7 +91,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_explicit_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -101,7 +102,7 @@ class B() extends A {
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_explicit_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -110,7 +111,7 @@ class B() extends A;
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_implicit() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -119,7 +120,7 @@ class B extends A {}
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_superParameter_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -130,7 +131,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_superParameter_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -141,7 +142,7 @@ class B({super.a}) extends A {
|
||||
}
|
||||
|
||||
test_super_optionalNamed_subclass_superParameter_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({int? a});
|
||||
}
|
||||
@@ -150,7 +151,7 @@ class B({super.a}) extends A;
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_explicit_constructor_newHead() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -161,7 +162,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_explicit_constructor_typeName() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -172,7 +173,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_explicit_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -183,7 +184,7 @@ class B() extends A {
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_explicit_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -192,7 +193,7 @@ class B() extends A;
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_implicit() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -201,7 +202,7 @@ class B extends A {}
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_superParameter_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -212,7 +213,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_superParameter_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -223,7 +224,7 @@ class B([super.a]) extends A {
|
||||
}
|
||||
|
||||
test_super_optionalPositional_subclass_superParameter_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A([int? a]);
|
||||
}
|
||||
@@ -232,73 +233,68 @@ class B([super.a]) extends A;
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_explicit_constructor_newHead() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
class B extends A {
|
||||
new named();
|
||||
//^^^^^^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 58, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_explicit_constructor_typeName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
class B extends A {
|
||||
B.named();
|
||||
//^^^^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 58, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_explicit_primaryConstructor_hasBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
class B() extends A {
|
||||
this;
|
||||
//^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 60, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_explicit_primaryConstructor_noBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
class B() extends A;
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_implicit() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.noDefaultSuperConstructorImplicit, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.noDefaultSuperConstructorImplicit] The superclass 'A' doesn't have a zero argument constructor.
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -309,47 +305,44 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_oneLeft_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a, required int? b});
|
||||
}
|
||||
class B extends A {
|
||||
B({required super.a});
|
||||
//^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 75, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_oneLeft_primaryConstructor_hasBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a, required int? b});
|
||||
}
|
||||
class B({required super.a}) extends A {
|
||||
this;
|
||||
//^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 95, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_oneLeft_primaryConstructor_noBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a, required int? b});
|
||||
}
|
||||
class B({required super.a}) extends A;
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 59, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_optionalNamed_hasDefault_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -360,7 +353,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_optionalNamed_hasDefault_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -371,7 +364,7 @@ class B({super.a = 0}) extends A {
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_optionalNamed_hasDefault_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -380,7 +373,7 @@ class B({super.a = 0}) extends A;
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_optionalNamed_noDefault_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -391,7 +384,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_optionalNamed_noDefault_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -402,7 +395,7 @@ class B({super.a}) extends A {
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_optionalNamed_noDefault_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -411,7 +404,7 @@ class B({super.a}) extends A;
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -422,7 +415,7 @@ class B({required super.a}) extends A {
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_superParameter_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A({required int? a});
|
||||
}
|
||||
@@ -431,61 +424,57 @@ class B({required super.a}) extends A;
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_explicit_constructor_newHead() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int p);
|
||||
}
|
||||
class B extends A {
|
||||
new named();
|
||||
//^^^^^^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 46, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_explicit_constructor_typeName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int p);
|
||||
}
|
||||
class B extends A {
|
||||
B.named();
|
||||
//^^^^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 46, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_explicit_primaryConstructor_hasBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int p);
|
||||
}
|
||||
class B() extends A {
|
||||
this;
|
||||
//^^^^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
}
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 48, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_explicit_primaryConstructor_noBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int p);
|
||||
}
|
||||
class B() extends A;
|
||||
''',
|
||||
[error(diag.implicitSuperInitializerMissingArguments, 30, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.implicitSuperInitializerMissingArguments] The implicitly invoked unnamed constructor from 'A' has required parameters.
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_external() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int p);
|
||||
}
|
||||
@@ -496,19 +485,18 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_implicit() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int p);
|
||||
}
|
||||
class B extends A {}
|
||||
''',
|
||||
[error(diag.noDefaultSuperConstructorImplicit, 30, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.noDefaultSuperConstructorImplicit] The superclass 'A' doesn't have a zero argument constructor.
|
||||
''');
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_optionalPositional_withDefault_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -519,7 +507,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_optionalPositional_withDefault_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -530,7 +518,7 @@ class B([super.a = 0]) extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_optionalPositional_withDefault_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -539,7 +527,7 @@ class B([super.a = 0]) extends A;
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_optionalPositional_withoutDefault_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -550,7 +538,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_optionalPositional_withoutDefault_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -561,7 +549,7 @@ class B([super.a]) extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_optionalPositional_withoutDefault_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -570,7 +558,7 @@ class B([super.a]) extends A;
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_requiredPositional_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -581,7 +569,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_requiredPositional_primaryConstructor_hasBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
@@ -592,7 +580,7 @@ class B(super.a) extends A {
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_superParameter_requiredPositional_primaryConstructor_noBody() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A(int? a);
|
||||
}
|
||||
|
||||
+20
-23
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NoGenerativeConstructorsInSuperclassTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,36 +18,34 @@ main() {
|
||||
class NoGenerativeConstructorsInSuperclassTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_explicit() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw '';
|
||||
}
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor.
|
||||
B() : super();
|
||||
}
|
||||
''',
|
||||
[error(diag.noGenerativeConstructorsInSuperclass, 55, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_explicit_oneFactory() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw '';
|
||||
}
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor.
|
||||
B() : super();
|
||||
factory B.second() => throw '';
|
||||
}
|
||||
''',
|
||||
[error(diag.noGenerativeConstructorsInSuperclass, 55, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_hasFactories() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw '';
|
||||
}
|
||||
@@ -58,7 +57,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_hasFactory() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw '';
|
||||
}
|
||||
@@ -69,29 +68,27 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_implicit() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw '';
|
||||
}
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor.
|
||||
B();
|
||||
}
|
||||
''',
|
||||
[error(diag.noGenerativeConstructorsInSuperclass, 55, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_implicit2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw '';
|
||||
}
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.noGenerativeConstructorsInSuperclass] The class 'B' can't extend 'A' because 'A' only has factory constructors (no generative constructors), and 'B' has at least one generative constructor.
|
||||
}
|
||||
''',
|
||||
[error(diag.noGenerativeConstructorsInSuperclass, 55, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+187
-290
@@ -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(NonAbstractClassInheritsAbstractMemberTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +19,7 @@ main() {
|
||||
class NonAbstractClassInheritsAbstractMemberTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_abstract_field_final_implement_getter() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
}
|
||||
@@ -28,40 +30,31 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_abstract_field_final_implement_none() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
abstract final int x;
|
||||
}
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberOne,
|
||||
51,
|
||||
1,
|
||||
messageContains: ["'getter A.x'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_implement_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
}
|
||||
class B implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.x'.
|
||||
int get x => 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 45, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_implement_getter_and_setter() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
}
|
||||
@@ -73,47 +66,31 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_abstract_field_implement_none() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
}
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberTwo,
|
||||
45,
|
||||
1,
|
||||
messageContains: ["'getter A.x' and 'setter A.x'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'getter A.x' and 'setter A.x'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstract_field_implement_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
abstract int x;
|
||||
}
|
||||
class B implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'.
|
||||
void set x(int value) {}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberOne,
|
||||
45,
|
||||
1,
|
||||
messageContains: ["'getter A.x'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_abstractsDontOverrideConcretes_getter() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int get g => 0;
|
||||
}
|
||||
@@ -125,7 +102,7 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_abstractsDontOverrideConcretes_method() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
m(p) {}
|
||||
}
|
||||
@@ -137,7 +114,7 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_abstractsDontOverrideConcretes_setter() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set s(v) {}
|
||||
}
|
||||
@@ -174,43 +151,40 @@ augment class A with M {}
|
||||
}
|
||||
|
||||
test_augment_withClause_sameFile_error_nonAbstractClassInheritsAbstractMember() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
mixin M {
|
||||
int foo();
|
||||
}
|
||||
|
||||
class A {}
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.foo'.
|
||||
|
||||
augment class A with M {}
|
||||
''',
|
||||
[
|
||||
error(diag.nonAbstractClassInheritsAbstractMemberOne, 32, 1),
|
||||
error(diag.nonAbstractClassInheritsAbstractMemberOne, 52, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.foo'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_notAbstract_hasConcreteSubtype_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
void foo();
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.foo'.
|
||||
|
||||
class C extends B {}
|
||||
|
||||
class D extends C {}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 42, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_classTypeAlias_interface() async {
|
||||
// issue 15979
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
abstract class M {}
|
||||
abstract class A {}
|
||||
@@ -223,7 +197,7 @@ abstract class B = A with M implements I;
|
||||
|
||||
test_classTypeAlias_mixin() async {
|
||||
// issue 15979
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
abstract class M {
|
||||
m();
|
||||
@@ -235,7 +209,7 @@ abstract class B = A with M;
|
||||
|
||||
test_classTypeAlias_superclass() async {
|
||||
// issue 15979
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
class M {}
|
||||
abstract class A {
|
||||
@@ -246,97 +220,91 @@ abstract class B = A with M;
|
||||
}
|
||||
|
||||
test_enum_getter_fromInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int get foo => 0;
|
||||
}
|
||||
|
||||
enum E implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.foo'.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 38, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_getter_fromMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
mixin M {
|
||||
int get foo;
|
||||
}
|
||||
|
||||
enum E with M {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter M.foo'.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_method_fromInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
void foo() {}
|
||||
}
|
||||
|
||||
enum E implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.foo'.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_method_fromMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
mixin M {
|
||||
void foo();
|
||||
}
|
||||
|
||||
enum E with M {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.foo'.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 32, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_setter_fromInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
set foo(int _) {}
|
||||
}
|
||||
|
||||
enum E implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.foo'.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 38, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_setter_fromMixin() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
mixin M {
|
||||
set foo(int _);
|
||||
}
|
||||
|
||||
enum E with M {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter M.foo'.
|
||||
v;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_external_field_final_implement_getter() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
external final int x;
|
||||
}
|
||||
@@ -347,33 +315,31 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_external_field_final_implement_none() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
external final int x;
|
||||
}
|
||||
class B implements A {}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_external_field_implement_getter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
external int x;
|
||||
}
|
||||
class B implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.x'.
|
||||
int get x => 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_external_field_implement_getter_and_setter() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
external int x;
|
||||
}
|
||||
@@ -385,41 +351,31 @@ class B implements A {
|
||||
}
|
||||
|
||||
test_external_field_implement_none() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
external int x;
|
||||
}
|
||||
class B implements A {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberTwo,
|
||||
36,
|
||||
1,
|
||||
messageContains: ["'getter A.x' and 'setter A.x'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'getter A.x' and 'setter A.x'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_external_field_implement_setter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
external int x;
|
||||
}
|
||||
class B implements A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.x'.
|
||||
void set x(int value) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fivePlus() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
m();
|
||||
n();
|
||||
@@ -428,22 +384,14 @@ abstract class A {
|
||||
q();
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberFivePlus] Missing concrete implementations of 'A.m', 'A.n', 'A.o', 'A.p', and 1 more.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberFivePlus,
|
||||
62,
|
||||
1,
|
||||
messageContains: ["'A.m', 'A.n', 'A.o', 'A.p'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_four() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
m();
|
||||
n();
|
||||
@@ -451,22 +399,15 @@ abstract class A {
|
||||
p();
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberFour] Missing concrete implementations of 'A.m', 'A.n', 'A.o', and 'A.p'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberFour,
|
||||
55,
|
||||
1,
|
||||
messageContains: ["'A.m', 'A.n', 'A.o', and 'A.p'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_mixin_concreteGetter() async {
|
||||
// issue 17034
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
class A {
|
||||
var a;
|
||||
@@ -480,7 +421,7 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_mixin_concreteMethod() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
class A {
|
||||
m() {}
|
||||
@@ -494,7 +435,7 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_mixin_concreteSetter() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
class A {
|
||||
var a;
|
||||
@@ -508,7 +449,7 @@ class C extends B {}
|
||||
}
|
||||
|
||||
test_noSuchMethod_concreteAccessor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
int get g;
|
||||
}
|
||||
@@ -519,7 +460,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_noSuchMethod_concreteMethod() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
m(p);
|
||||
}
|
||||
@@ -530,7 +471,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_noSuchMethod_mixin() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
class A {
|
||||
noSuchMethod(v) => '';
|
||||
@@ -542,7 +483,7 @@ class B extends Object with A {
|
||||
}
|
||||
|
||||
test_noSuchMethod_superclass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
noSuchMethod(v) => '';
|
||||
}
|
||||
@@ -554,8 +495,7 @@ class B extends A {
|
||||
|
||||
test_one_classTypeAlias_interface() async {
|
||||
// issue 15979
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//@dart=2.19
|
||||
abstract class M {}
|
||||
abstract class A {}
|
||||
@@ -563,96 +503,90 @@ abstract class I {
|
||||
m();
|
||||
}
|
||||
class B = A with M implements I;
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 87, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_classTypeAlias_mixin() async {
|
||||
// issue 15979
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//@dart=2.19
|
||||
abstract class M {
|
||||
m();
|
||||
}
|
||||
abstract class A {}
|
||||
class B = A with M;
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 67, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'M.m'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_classTypeAlias_superclass() async {
|
||||
// issue 15979
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//@dart=2.19
|
||||
class M {}
|
||||
abstract class A {
|
||||
m();
|
||||
}
|
||||
class B = A with M;
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 58, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_getter_fromInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
int get g {return 1;}
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter I.g'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 42, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_getter_fromSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
int get g;
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.g'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 40, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_method_fromInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
m(p) {}
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 28, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_method_fromInterface_abstractNSM() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
m(p) {}
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'.
|
||||
noSuchMethod(v);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 28, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_method_fromInterface_abstractOverrideNSM() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
m(p) {}
|
||||
}
|
||||
@@ -666,36 +600,33 @@ class C extends B implements I {
|
||||
}
|
||||
|
||||
test_one_method_fromInterface_ifcNSM() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
m(p) {}
|
||||
noSuchMethod(v) => null;
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'I.m'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 55, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_method_fromSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
m(p);
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 35, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_method_optionalParamCount() async {
|
||||
// issue 7640
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
int x(int a);
|
||||
}
|
||||
@@ -703,55 +634,51 @@ abstract class B {
|
||||
int x(int a, [int b]);
|
||||
}
|
||||
class C implements A, B {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'B.x'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 89, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_mixinInherits_getter() async {
|
||||
// issue 15001
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//@dart=2.19
|
||||
abstract class A { get g1; get g2; }
|
||||
abstract class B implements A { get g1 => 1; }
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 103, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.g2'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_mixinInherits_method() async {
|
||||
// issue 15001
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//@dart=2.19
|
||||
abstract class A { m1(); m2(); }
|
||||
abstract class B implements A { m1() => 1; }
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 97, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m2'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_mixinInherits_setter() async {
|
||||
// issue 15001
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
//@dart=2.19
|
||||
abstract class A { set s1(v); set s2(v); }
|
||||
abstract class B implements A { set s1(v) {} }
|
||||
class C extends Object with B {}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 109, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.s2'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_noSuchMethod_interface() async {
|
||||
// issue 15979
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
noSuchMethod(v) => '';
|
||||
}
|
||||
@@ -759,16 +686,15 @@ abstract class A {
|
||||
m();
|
||||
}
|
||||
class B extends A implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'A.m'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 71, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_setter_and_implicitSetter() async {
|
||||
// test from language/override_inheritance_abstract_test_14.dart
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
set field(_);
|
||||
}
|
||||
@@ -776,43 +702,40 @@ abstract class I {
|
||||
var field;
|
||||
}
|
||||
class B extends A implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.field'.
|
||||
get field => 0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 77, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_setter_fromInterface() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
set s(int i) {}
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter I.s'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 36, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_setter_fromSuperclass() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
set s(int i);
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter A.s'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 43, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_superclasses_interface() async {
|
||||
// issue 11154
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
get a => 'a';
|
||||
}
|
||||
@@ -820,44 +743,42 @@ abstract class B implements A {
|
||||
get b => 'b';
|
||||
}
|
||||
class C extends B {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter A.a'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 84, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_variable_fromInterface_missingGetter() async {
|
||||
// issue 16133
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
var v;
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'getter I.v'.
|
||||
set v(_) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_one_variable_fromInterface_missingSetter() async {
|
||||
// issue 16133
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
var v;
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberOne] Missing concrete implementation of 'setter I.v'.
|
||||
get v => 1;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonAbstractClassInheritsAbstractMemberOne, 27, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_overridesConcreteMethodInObject() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
//@dart=2.19
|
||||
class A {
|
||||
String toString([String prefix = '']) => '${prefix}Hello';
|
||||
@@ -868,66 +789,42 @@ class B extends A with C {}
|
||||
}
|
||||
|
||||
test_three() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
m();
|
||||
n();
|
||||
o();
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberThree] Missing concrete implementations of 'A.m', 'A.n', and 'A.o'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberThree,
|
||||
48,
|
||||
1,
|
||||
messageContains: ["'A.m', 'A.n', and 'A.o'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_two() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
abstract class A {
|
||||
m();
|
||||
n();
|
||||
}
|
||||
class C extends A {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'A.m' and 'A.n'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberTwo,
|
||||
41,
|
||||
1,
|
||||
messageContains: ["'A.m' and 'A.n'"],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_two_fromInterface_missingBoth() async {
|
||||
// issue 16133
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class I {
|
||||
var v;
|
||||
}
|
||||
class C implements I {
|
||||
// ^
|
||||
// [diag.nonAbstractClassInheritsAbstractMemberTwo] Missing concrete implementations of 'getter I.v' and 'setter I.v'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonAbstractClassInheritsAbstractMemberTwo,
|
||||
27,
|
||||
1,
|
||||
messageContains: ["'getter I.v' and 'setter I.v'."],
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,313 +6,285 @@ 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(NonBoolConditionTest);
|
||||
defineReflectiveTests(NonBoolConditionWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonBoolConditionTest extends PubPackageResolutionTest {
|
||||
test_conditional() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() { return 3 ? 2 : 1; }
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 13, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_conditional_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() { return [1, 2, 3] ? 2 : 1; }
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 13, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_conditional_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) { return o ? 2 : 1; }
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 21, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_list_ifElement() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic c = 2;
|
||||
const x = [1, if (c) 2 else 3, 4];
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 39, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_list_ifElement_static() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const x = [1, if (1) 2 else 3, 4];
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 18, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_do() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
do {} while (3);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 21, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_do_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) {
|
||||
do {} while ([1, 2, 3]);
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 29, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_do_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) {
|
||||
do {} while (o);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 29, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_for() async {
|
||||
// https://github.com/dart-lang/sdk/issues/24713
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
for (;3;) {}
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 14, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_for_declaration() async {
|
||||
// https://github.com/dart-lang/sdk/issues/24713
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
for (int i = 0; 3;) {}
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 17, 1),
|
||||
error(diag.nonBoolCondition, 24, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_for_expression() async {
|
||||
// https://github.com/dart-lang/sdk/issues/24713
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
int i;
|
||||
// ^
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'i' isn't used.
|
||||
for (i = 0; 3;) {}
|
||||
}''',
|
||||
[
|
||||
error(diag.unusedLocalVariable, 12, 1),
|
||||
error(diag.nonBoolCondition, 29, 1),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_for_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
for (;[1, 2, 3];) {}
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 14, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_for_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) {
|
||||
for (;o;) {}
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 22, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_forElement() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = [for (; 0;) 1];
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 16, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_guardedPattern_whenClause() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f() {
|
||||
if (0 case _ when 1) {}
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 31, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_if() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
if (3) return 2; else return 1;
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 12, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_if_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
if ([1, 2, 3]) return 2; else return 1;
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 12, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_if_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) {
|
||||
if (o) return 2; else return 1;
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_if_map() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic nonBool = null;
|
||||
const c = const {if (nonBool) 'a' : 1};
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 51, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_if_null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Null a) {
|
||||
if (a) {}
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_if_set() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const dynamic nonBool = 'a';
|
||||
const c = const {if (nonBool) 3};
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 50, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ifElement() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = [if (3) 1];
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 13, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ifElement_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var v = [if ([1, 2, 3]) 'x'];
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 13, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ifElement_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final o = Object();
|
||||
var v = [if (o) 'x'];
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 33, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_ternary_condition_null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Null a) {
|
||||
a ? 0 : 1;
|
||||
//^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 19, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_while() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
while (3) {}
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 15, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_while_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
while ([1, 2, 3]) {}
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 15, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_while_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) {
|
||||
while (o) {}
|
||||
// ^
|
||||
// [diag.nonBoolCondition] Conditions must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolCondition, 23, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,49 +6,48 @@ 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(NonBoolExpressionTest);
|
||||
defineReflectiveTests(NonBoolExpressionWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonBoolExpressionTest extends PubPackageResolutionTest {
|
||||
test_functionType_bool() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool makeAssertion() => true;
|
||||
f() {
|
||||
assert(makeAssertion);
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.nonBoolExpression] The expression in an assert must be of type 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolExpression, 45, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_functionType_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int makeAssertion() => 1;
|
||||
f() {
|
||||
assert(makeAssertion);
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.nonBoolExpression] The expression in an assert must be of type 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolExpression, 41, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_interfaceType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
assert(0);
|
||||
// ^
|
||||
// [diag.nonBoolExpression] The expression in an assert must be of type 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolExpression, 15, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,58 +6,56 @@ 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(NonBoolNegationExpressionTest);
|
||||
defineReflectiveTests(NonBoolNegationExpressionWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonBoolNegationExpressionTest extends PubPackageResolutionTest {
|
||||
test_nonBool() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
!42;
|
||||
// ^^
|
||||
// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolNegationExpression, 9, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonBool_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
![1, 2, 3];
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolNegationExpression, 9, 9)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonBool_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(Object o) {
|
||||
!o;
|
||||
// ^
|
||||
// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolNegationExpression, 17, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_null() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void m(Null x) {
|
||||
!x;
|
||||
// ^
|
||||
// [diag.nonBoolNegationExpression] A negation operand must have a static type of 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolNegationExpression, 20, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,115 +6,108 @@ 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(NonBoolOperandTest);
|
||||
defineReflectiveTests(NonBoolOperandWithStrictCastsTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonBoolOperandTest extends PubPackageResolutionTest {
|
||||
test_and_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool f(int left, bool right) {
|
||||
return left && right;
|
||||
// ^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 40, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_and_left_fromInstanceCreationExpression() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {
|
||||
new Object() && true;
|
||||
//^^^^^^^^^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 11, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_and_left_fromLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool f(List<int> left, bool right) {
|
||||
return left && right;
|
||||
// ^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 46, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_and_left_fromSupertype() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool f(Object left, bool right) {
|
||||
return left && right;
|
||||
// ^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 43, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_and_null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
Null x;
|
||||
if(x && true) {}
|
||||
// ^
|
||||
// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 21, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_and_right() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool f(bool left, String right) {
|
||||
return left && right;
|
||||
// ^^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '&&' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 51, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_or_left() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool f(List<int> left, bool right) {
|
||||
return left || right;
|
||||
// ^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '||' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 46, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_or_null() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
m() {
|
||||
Null x;
|
||||
if(x || false) {}
|
||||
// ^
|
||||
// [diag.nonBoolOperand] The operands of the operator '||' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 21, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_or_right() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
bool f(bool left, double right) {
|
||||
return left || right;
|
||||
// ^^^^^
|
||||
// [diag.nonBoolOperand] The operands of the operator '||' must be assignable to 'bool'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonBoolOperand, 51, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+328
-399
File diff suppressed because it is too large
Load Diff
@@ -2,14 +2,15 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonConstCallToLiteralConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ class NonConstCallToLiteralConstructorTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
test_class_primaryConstructor_constContext() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class const A() {
|
||||
@literal
|
||||
@@ -33,49 +34,46 @@ const a = A();
|
||||
}
|
||||
|
||||
test_class_primaryConstructor_dotShorthand_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class const A() {
|
||||
@literal
|
||||
this;
|
||||
}
|
||||
A a = .new();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 78, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_primaryConstructor_nonConstContext() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class const A() {
|
||||
@literal
|
||||
this;
|
||||
}
|
||||
var a = A();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 80, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
const A.named();
|
||||
}
|
||||
var a = A.named();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 83, 9)],
|
||||
);
|
||||
// ^^^^^^^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A.named constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
@@ -85,7 +83,7 @@ class A {
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_constContextCreation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
@@ -96,7 +94,7 @@ const a = A();
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_constCreation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
@@ -107,49 +105,46 @@ const a = const A();
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_dotShorthand() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
const A.named();
|
||||
}
|
||||
A a = .named();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 81, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A.named constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_dotShorthand_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
const A();
|
||||
}
|
||||
A a = .new();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 75, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_nonConstContext() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
const A();
|
||||
}
|
||||
var a = A();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 77, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the A constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_unconstableCreation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
@@ -160,21 +155,20 @@ var a = A(new List.filled(1, ''));
|
||||
}
|
||||
|
||||
test_class_secondaryConstructor_usingNew() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class A {
|
||||
@literal
|
||||
const A();
|
||||
}
|
||||
var a = new A();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructorUsingNew, 77, 7)],
|
||||
);
|
||||
// ^^^^^^^
|
||||
// [diag.nonConstCallToLiteralConstructorUsingNew] This instance creation must be 'const', because the A constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_extensionType_constCreation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
extension type const E(int i) {
|
||||
@literal
|
||||
@@ -185,16 +179,15 @@ E e = const E.zero();
|
||||
}
|
||||
|
||||
test_extensionType_usingNew() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
extension type const E(int i) {
|
||||
@literal
|
||||
const E.zero(): this(0);
|
||||
}
|
||||
E e = E.zero();
|
||||
''',
|
||||
[error(diag.nonConstCallToLiteralConstructor, 111, 8)],
|
||||
);
|
||||
// ^^^^^^^^
|
||||
// [diag.nonConstCallToLiteralConstructor] This instance creation must be 'const', because the E.zero constructor is marked as '@literal'.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(NonConstGenerativeEnumConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstGenerativeEnumConstructorTest extends PubPackageResolutionTest {
|
||||
test_factoryHead_unnamed() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v.named();
|
||||
const E.named();
|
||||
@@ -26,7 +27,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_const_newHead_named() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v.named();
|
||||
const new named();
|
||||
@@ -35,7 +36,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_const_newHead_unnamed() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const new ();
|
||||
@@ -44,7 +45,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_const_typeName() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E();
|
||||
@@ -53,7 +54,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_nonConst_newHead_unnamed() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
new ();
|
||||
@@ -62,7 +63,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_nonConst_typeName_named() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v.named();
|
||||
E.named();
|
||||
@@ -71,20 +72,19 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_nonConst_typeName_named_language310() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
enum E {
|
||||
v.named();
|
||||
E.named();
|
||||
//^^^^^^^
|
||||
// [diag.nonConstGenerativeEnumConstructor] Generative enum constructors must be 'const'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstGenerativeEnumConstructor, 40, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_generative_nonConst_typeName_unnamed() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
E();
|
||||
@@ -93,20 +93,19 @@ enum E {
|
||||
}
|
||||
|
||||
test_generative_nonConst_typeName_unnamed_language310() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 3.10
|
||||
enum E {
|
||||
v;
|
||||
E();
|
||||
//^
|
||||
// [diag.nonConstGenerativeEnumConstructor] Generative enum constructors must be 'const'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstGenerativeEnumConstructor, 32, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeName_factory_named() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
factory E.foo() => v;
|
||||
|
||||
@@ -2,44 +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(NonConstantAnnotationConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantAnnotationConstructorTest extends PubPackageResolutionTest {
|
||||
test_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.fromInt() {}
|
||||
}
|
||||
@A.fromInt()
|
||||
// [diag.nonConstantAnnotationConstructor][column 1][length 12] Annotation creation can only call a const constructor.
|
||||
main() {
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantAnnotationConstructor, 29, 12)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_unnamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
@A()
|
||||
// [diag.nonConstantAnnotationConstructor][column 1][length 4] Annotation creation can only call a const constructor.
|
||||
main() {
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantAnnotationConstructor, 21, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+75
-75
@@ -2,11 +2,10 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -14,98 +13,49 @@ main() {
|
||||
defineReflectiveTests(
|
||||
NonConstantCaseExpressionFromDeferredLibraryTest_Language219,
|
||||
);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantCaseExpressionFromDeferredLibraryTest
|
||||
extends PubPackageResolutionTest
|
||||
with NonConstantCaseExpressionFromDeferredLibraryTestCases {
|
||||
@override
|
||||
_Variant get _variant => _Variant.patterns;
|
||||
|
||||
extends PubPackageResolutionTest {
|
||||
test_nested() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
const int c = 0;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(int e) {
|
||||
switch (e) {
|
||||
case const (a.c + 1):
|
||||
// ^
|
||||
// [diag.patternConstantFromDeferredLibrary] Constant values from a deferred library can't be used in patterns.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.patternConstantFromDeferredLibrary, 81, 1)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantCaseExpressionFromDeferredLibraryTest_Language219
|
||||
extends PubPackageResolutionTest
|
||||
with
|
||||
WithLanguage219Mixin,
|
||||
NonConstantCaseExpressionFromDeferredLibraryTestCases {
|
||||
@override
|
||||
_Variant get _variant => _Variant.nullSafe;
|
||||
|
||||
test_nested() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
const int c = 0;
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(int e) {
|
||||
switch (e) {
|
||||
case a.c + 1:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantCaseExpressionFromDeferredLibrary, 74, 1)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mixin NonConstantCaseExpressionFromDeferredLibraryTestCases
|
||||
on PubPackageResolutionTest {
|
||||
_Variant get _variant;
|
||||
|
||||
test_simple() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
const int c = 0;
|
||||
''');
|
||||
|
||||
DiagnosticCode expectedDiagnosticCode;
|
||||
switch (_variant) {
|
||||
case _Variant.nullSafe:
|
||||
expectedDiagnosticCode =
|
||||
diag.nonConstantCaseExpressionFromDeferredLibrary;
|
||||
case _Variant.patterns:
|
||||
expectedDiagnosticCode = diag.patternConstantFromDeferredLibrary;
|
||||
}
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(int e) {
|
||||
switch (e) {
|
||||
case a.c:
|
||||
// ^
|
||||
// [diag.patternConstantFromDeferredLibrary] Constant values from a deferred library can't be used in patterns.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(expectedDiagnosticCode, 74, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_simple_typeLiteral() async {
|
||||
@@ -113,29 +63,79 @@ void f(int e) {
|
||||
class A {}
|
||||
''');
|
||||
|
||||
DiagnosticCode expectedDiagnosticCode;
|
||||
switch (_variant) {
|
||||
case _Variant.nullSafe:
|
||||
expectedDiagnosticCode =
|
||||
diag.nonConstantCaseExpressionFromDeferredLibrary;
|
||||
case _Variant.patterns:
|
||||
expectedDiagnosticCode = diag.patternConstantFromDeferredLibrary;
|
||||
}
|
||||
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(Object? x) {
|
||||
switch (x) {
|
||||
case a.A:
|
||||
// ^
|
||||
// [diag.patternConstantFromDeferredLibrary] Constant values from a deferred library can't be used in patterns.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(expectedDiagnosticCode, 78, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
enum _Variant { nullSafe, patterns }
|
||||
@reflectiveTest
|
||||
class NonConstantCaseExpressionFromDeferredLibraryTest_Language219
|
||||
extends PubPackageResolutionTest
|
||||
with WithLanguage219Mixin {
|
||||
test_nested() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
const int c = 0;
|
||||
''');
|
||||
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(int e) {
|
||||
switch (e) {
|
||||
case a.c + 1:
|
||||
// ^
|
||||
// [diag.nonConstantCaseExpressionFromDeferredLibrary] Constant values from a deferred library can't be used as a case expression.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_simple() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
const int c = 0;
|
||||
''');
|
||||
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(int e) {
|
||||
switch (e) {
|
||||
case a.c:
|
||||
// ^
|
||||
// [diag.nonConstantCaseExpressionFromDeferredLibrary] Constant values from a deferred library can't be used as a case expression.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_simple_typeLiteral() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
void f(Object? x) {
|
||||
switch (x) {
|
||||
case a.A:
|
||||
// ^
|
||||
// [diag.nonConstantCaseExpressionFromDeferredLibrary] Constant values from a deferred library can't be used as a case expression.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,43 +2,23 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonConstantCaseExpressionTest);
|
||||
defineReflectiveTests(NonConstantCaseExpressionTest_Language219);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantCaseExpressionTest extends PubPackageResolutionTest
|
||||
with NonConstantCaseExpressionTestCases {}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantCaseExpressionTest_Language219 extends PubPackageResolutionTest
|
||||
with WithLanguage219Mixin, NonConstantCaseExpressionTestCases {
|
||||
test_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
void f(var e, int a) {
|
||||
switch (e) {
|
||||
case 3 + a:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantCaseExpression, 51, 1)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mixin NonConstantCaseExpressionTestCases on PubPackageResolutionTest {
|
||||
class NonConstantCaseExpressionTest extends PubPackageResolutionTest {
|
||||
test_constField() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(C e) {
|
||||
switch (e) {
|
||||
case C.zero:
|
||||
@@ -58,7 +38,58 @@ class C {
|
||||
}
|
||||
|
||||
test_typeLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(e) {
|
||||
switch (e) {
|
||||
case bool:
|
||||
case int:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantCaseExpressionTest_Language219 extends PubPackageResolutionTest
|
||||
with WithLanguage219Mixin {
|
||||
test_constField() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(C e) {
|
||||
switch (e) {
|
||||
case C.zero:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
static const zero = C(0);
|
||||
|
||||
final int a;
|
||||
const C(this.a);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_parameter() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(var e, int a) {
|
||||
switch (e) {
|
||||
case 3 + a:
|
||||
// ^
|
||||
// [diag.nonConstantCaseExpression] Case expressions must be constant.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeLiteral() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(e) {
|
||||
switch (e) {
|
||||
case bool:
|
||||
|
||||
+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(NonConstantDefaultValueFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,14 +22,13 @@ class NonConstantDefaultValueFromDeferredLibraryTest
|
||||
library lib1;
|
||||
const V = 1;
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f({x = a.V}) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValueFromDeferredLibrary, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValueFromDeferredLibrary] Constant values from a deferred library can't be used as a default parameter value.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nested() async {
|
||||
@@ -36,13 +36,12 @@ f({x = a.V}) {}
|
||||
library lib1;
|
||||
const V = 1;
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
library root;
|
||||
import 'lib1.dart' deferred as a;
|
||||
f({x = a.V + 1}) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValueFromDeferredLibrary, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValueFromDeferredLibrary] Constant values from a deferred library can't be used as a default parameter value.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,60 +2,54 @@
|
||||
// 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(NonConstantDefaultValueTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantDefaultValueTest extends PubPackageResolutionTest {
|
||||
test_constructor_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int y = 0;
|
||||
A({x = y}) {}
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonConstantDefaultValue, 32, 1),
|
||||
error(diag.implicitThisReferenceInInitializer, 32, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constructor_positional() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int y = 0;
|
||||
A([x = y]) {}
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonConstantDefaultValue, 32, 1),
|
||||
error(diag.implicitThisReferenceInInitializer, 32, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_dotShorthand_issue60962() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
|
||||
void f([A a = .new()]) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 40, 6)],
|
||||
);
|
||||
// ^^^^^^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_issue49097() async {
|
||||
@@ -66,7 +60,7 @@ class A {
|
||||
const A();
|
||||
}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
|
||||
enum E {
|
||||
@@ -78,147 +72,135 @@ enum E {
|
||||
}
|
||||
|
||||
test_function_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int y = 0;
|
||||
f({x = y}) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 18, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_constList() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = const [0, 1]}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_constList_elements_listLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = const [0, [1]]}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_constRecord() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = const (0, 1)}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_constRecord_namedFields_listLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = const (0, foo: [1])}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_constRecord_positionalFields_listLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = const (0, [1])}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_record_namedFields_integerLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = (a: 0, b: 1)}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_record_namedFields_listLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = (a: 0, b: [1])}) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 22, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_record_namedFields_listLiteral_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = (a: 0, b: const [1])}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_record_positionalFields_integerLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = (0, 1)}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_record_positionalFields_listLiteral() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = (0, [1])}) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 16, 3)],
|
||||
);
|
||||
// ^^^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_record_positionalFields_listLiteral_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({x = (0, const [1])}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_named_undefinedIdentifier() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int x = X}) {}
|
||||
''',
|
||||
[error(diag.undefinedIdentifier, 16, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.undefinedIdentifier] Undefined name 'X'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_positional() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int y = 0;
|
||||
f([x = y]) {}
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 18, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_positional_undefinedIdentifier() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f([int x = X]) {}
|
||||
''',
|
||||
[error(diag.undefinedIdentifier, 16, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.undefinedIdentifier] Undefined name 'X'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_named() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int y = 0;
|
||||
m({x = y}) {}
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonConstantDefaultValue, 32, 1),
|
||||
error(diag.implicitThisReferenceInInitializer, 32, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_method_positional() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int y = 0;
|
||||
m([x = y]) {}
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
// [diag.implicitThisReferenceInInitializer] The instance member 'y' can't be accessed in an initializer.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonConstantDefaultValue, 32, 1),
|
||||
error(diag.implicitThisReferenceInInitializer, 32, 1),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noAppliedTypeParameters_defaultConstructorValue_dynamic() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T t) => t;
|
||||
|
||||
class C<T> {
|
||||
@@ -229,7 +211,7 @@ class C<T> {
|
||||
}
|
||||
|
||||
test_noAppliedTypeParameters_defaultConstructorValue_genericFn() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T t) => t;
|
||||
|
||||
class C<T> {
|
||||
@@ -240,7 +222,7 @@ class C<T> {
|
||||
}
|
||||
|
||||
test_noAppliedTypeParameters_defaultFunctionValue_genericFn() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T t) => t;
|
||||
|
||||
void bar<T>([void Function<T>(T) p = f]) {}
|
||||
@@ -248,7 +230,7 @@ void bar<T>([void Function<T>(T) p = f]) {}
|
||||
}
|
||||
|
||||
test_noAppliedTypeParameters_defaultMethodValue_genericFn() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T t) => t;
|
||||
|
||||
class C<T> {
|
||||
@@ -258,22 +240,20 @@ class C<T> {
|
||||
}
|
||||
|
||||
test_primaryConstructor_optionalNamed() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int y = 0;
|
||||
class A({int x = y});
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_primaryConstructor_optionalPositional() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int y = 0;
|
||||
class A([int x = y]);
|
||||
''',
|
||||
[error(diag.nonConstantDefaultValue, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantDefaultValue] The default value of an optional parameter must be constant.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+15
-16
@@ -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(NonConstantListElementFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,47 +38,44 @@ var v = const [ if (cond) 'a' else a.c ];
|
||||
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.nonConstantListElementFromDeferredLibrary, 81, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' list 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.nonConstantListElementFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' list 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.nonConstantListElementFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' list literal.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topLevel_notDeferred() async {
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const int c = 1;
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as a;
|
||||
var v = const [a.c];
|
||||
''');
|
||||
|
||||
@@ -2,118 +2,108 @@
|
||||
// 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(NonConstantListElementTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantListElementTest extends PubPackageResolutionTest
|
||||
with NonConstantListElementTestCases {}
|
||||
|
||||
mixin NonConstantListElementTestCases on PubPackageResolutionTest {
|
||||
class NonConstantListElementTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [if (1 < 0) 0 else a];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 54, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [if (1 < 0) a else 0];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [if (1 > 0) 0 else a];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 54, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [if (1 > 0) a else 0];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const [if (1 < 0) a];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [if (1 < 0) a];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const [if (1 > 0) a];
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [if (1 > 0) a];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 47, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topVar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const [a];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topVar_nested() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
var v = const [a + 1];
|
||||
''',
|
||||
[error(diag.nonConstantListElement, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantListElement] The values in a const list literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_topVar() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = [a];
|
||||
''');
|
||||
|
||||
@@ -2,26 +2,24 @@
|
||||
// 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(NonConstantMapElementTest);
|
||||
defineReflectiveTests(NonConstantMapKeyTest);
|
||||
defineReflectiveTests(NonConstantMapValueTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapElementTest extends PubPackageResolutionTest
|
||||
with NonConstantMapElementTestCases {}
|
||||
|
||||
mixin NonConstantMapElementTestCases on PubPackageResolutionTest {
|
||||
class NonConstantMapElementTest extends PubPackageResolutionTest {
|
||||
test_forElement_notConst_noError() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
var x;
|
||||
print({x: x, for (final x2 in [x]) x2: x2});
|
||||
@@ -30,7 +28,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_ifElement_mayBeConst() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
const {1: null, if (true) null: null};
|
||||
}
|
||||
@@ -38,7 +36,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_ifElement_nested_mayBeConst() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
const {1: null, if (true) if (true) null: null};
|
||||
}
|
||||
@@ -46,31 +44,29 @@ void main() {
|
||||
}
|
||||
|
||||
test_ifElement_notConstCondition() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
bool notConst = true;
|
||||
const {1: null, if (notConst) null: null};
|
||||
// ^^^^^^^^
|
||||
// [diag.nonConstantMapElement] The elements in a const map literal must be constant.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantMapElement, 60, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_ifElementWithElse_mayBeConst() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
const isTrue = true;
|
||||
const {1: null, if (isTrue) null: null else null: null};
|
||||
// ^^^^^^^^^^
|
||||
// [diag.deadCode] Dead code.
|
||||
}
|
||||
''',
|
||||
[error(diag.deadCode, 83, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_spreadElement_mayBeConst() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
const {1: null, ...{null: null}};
|
||||
}
|
||||
@@ -78,110 +74,98 @@ void main() {
|
||||
}
|
||||
|
||||
test_spreadElement_notConst() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void main() {
|
||||
var notConst = {};
|
||||
const {1: null, ...notConst};
|
||||
// ^^^^^^^^
|
||||
// [diag.nonConstantMapElement] The elements in a const map literal must be constant.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantMapElement, 56, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapKeyTest extends PubPackageResolutionTest
|
||||
with NonConstantMapKeyTestCases {}
|
||||
|
||||
@reflectiveTest
|
||||
mixin NonConstantMapKeyTestCases on PubPackageResolutionTest {
|
||||
class NonConstantMapKeyTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) 0: 0 else a: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 67, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) a: 0 else 0: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) 0: 0 else a: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 67, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) a: 0 else 0: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) a: 0};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) a: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) a: 0};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) a: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topVar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{a: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 46, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_topVar() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = <int, int>{a: 0};
|
||||
''');
|
||||
@@ -189,96 +173,86 @@ var v = <int, int>{a: 0};
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapValueTest extends PubPackageResolutionTest
|
||||
with NonConstantMapValueTestCases {}
|
||||
|
||||
mixin NonConstantMapValueTestCases on PubPackageResolutionTest {
|
||||
class NonConstantMapValueTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) 0: 0 else 0: a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 70, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) 0: a else 0: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 60, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) 0: 0 else 0: a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 70, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) 0: a else 0: 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 60, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) 0: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 < 0) 0: a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 60, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) 0: a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{if (1 > 0) 0: a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 60, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topVar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int, int>{0: a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 49, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_topVar() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = <int, int>{0: a};
|
||||
''');
|
||||
|
||||
+16
-20
@@ -6,19 +6,18 @@ 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(NonConstantMapKeyFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapKeyFromDeferredLibraryTest extends PubPackageResolutionTest
|
||||
with NonConstantMapKeyFromDeferredLibraryTestCases {}
|
||||
|
||||
mixin NonConstantMapKeyFromDeferredLibraryTestCases
|
||||
on PubPackageResolutionTest {
|
||||
class NonConstantMapKeyFromDeferredLibraryTest
|
||||
extends PubPackageResolutionTest {
|
||||
@failingTest
|
||||
test_const_ifElement_thenTrue_deferredElse() async {
|
||||
// reports wrong error code
|
||||
@@ -37,37 +36,34 @@ var v = const { if (cond) 0: 1 else a.c : 0};
|
||||
test_const_ifElement_thenTrue_deferredThen() 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 : 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKeyFromDeferredLibrary, 81, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKeyFromDeferredLibrary] Constant values from a deferred library can't be used as keys in a 'const' map 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 : 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKeyFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKeyFromDeferredLibrary] Constant values from a deferred library can't be used as keys in a 'const' map 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 : 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKeyFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKeyFromDeferredLibrary] Constant values from a deferred library can't be used as keys in a 'const' map literal.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,51 +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(NonConstantMapKeyTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapKeyTest extends PubPackageResolutionTest
|
||||
with NonConstantMapKeyTestCases {}
|
||||
|
||||
mixin NonConstantMapKeyTestCases on PubPackageResolutionTest {
|
||||
class NonConstantMapKeyTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenTrue_elseFinal() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
const cond = true;
|
||||
var v = const {if (cond) 0: 1 else a : 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 75, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_thenFinal() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
const cond = true;
|
||||
var v = const {if (cond) a : 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 65, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topLevel() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
var v = const {a : 0};
|
||||
''',
|
||||
[error(diag.nonConstantMapKey, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapKey] The keys in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(NonConstantMapPatternKeyTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapPatternKeyTest extends PubPackageResolutionTest {
|
||||
test_formalParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(x, int a) {
|
||||
if (x case {a: 0}) {}
|
||||
// ^
|
||||
// [diag.nonConstantMapPatternKey] Key expressions in map patterns must be constants.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantMapPatternKey, 33, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_instanceCreation_noConst() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(x) {
|
||||
if (x case {A(): 0}) {}
|
||||
// ^^^
|
||||
// [diag.nonConstantMapPatternKey] Key expressions in map patterns must be constants.
|
||||
}
|
||||
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantMapPatternKey, 26, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_integerLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(x) {
|
||||
if (x case {0: 1}) {}
|
||||
}
|
||||
|
||||
+15
-20
@@ -6,20 +6,18 @@ 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(NonConstantMapValueFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapValueFromDeferredLibraryTest
|
||||
extends PubPackageResolutionTest
|
||||
with NonConstantMapValueFromDeferredLibraryTestCases {}
|
||||
|
||||
mixin NonConstantMapValueFromDeferredLibraryTestCases
|
||||
on PubPackageResolutionTest {
|
||||
extends PubPackageResolutionTest {
|
||||
@failingTest
|
||||
test_const_ifElement_thenTrue_elseDeferred() async {
|
||||
// reports wrong error code
|
||||
@@ -38,37 +36,34 @@ var v = const { if (cond) 'a': 'b' else 'c' : a.c};
|
||||
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' : a.c};
|
||||
''',
|
||||
[error(diag.nonConstantMapValueFromDeferredLibrary, 87, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValueFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' map 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' : a.c};
|
||||
''',
|
||||
[error(diag.nonConstantMapValueFromDeferredLibrary, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValueFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' map 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' : a.c + 1};
|
||||
''',
|
||||
[error(diag.nonConstantMapValueFromDeferredLibrary, 57, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValueFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' map literal.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,51 +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(NonConstantMapValueTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantMapValueTest extends PubPackageResolutionTest
|
||||
with NonConstantMapValueTestCases {}
|
||||
|
||||
mixin NonConstantMapValueTestCases on PubPackageResolutionTest {
|
||||
class NonConstantMapValueTest extends PubPackageResolutionTest {
|
||||
test_const_ifTrue_elseFinal() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
const cond = true;
|
||||
var v = const {if (cond) 'a': 'b', 'c' : a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 81, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifTrue_thenFinal() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
const cond = true;
|
||||
var v = const {if (cond) 'a' : a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 71, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topLevel() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final dynamic a = 0;
|
||||
var v = const {'a' : a};
|
||||
''',
|
||||
[error(diag.nonConstantMapValue, 42, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantMapValue] The values in a const map literal must be constant.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -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(NonConstantRecordFieldFromDeferredLibraryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,13 +21,12 @@ class NonConstantRecordFieldFromDeferredLibraryTest
|
||||
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.nonConstantRecordFieldFromDeferredLibrary, 51, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantRecordFieldFromDeferredLibrary] Constant values from a deferred library can't be used as fields in a 'const' record literal.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_notDeferred() async {
|
||||
@@ -34,7 +34,7 @@ var v = const (a.c, );
|
||||
const int c = 1;
|
||||
const int d = 2;
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' as a;
|
||||
var v = const (a.c, d: a.d);
|
||||
''');
|
||||
@@ -44,7 +44,7 @@ var v = const (a.c, d: a.d);
|
||||
newFile('$testPackageLibPath/lib1.dart', r'''
|
||||
const int c = 1;
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib1.dart' deferred as a;
|
||||
var v = (a.c, );
|
||||
''');
|
||||
|
||||
@@ -2,41 +2,40 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonConstantRecordFieldTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantRecordFieldTest extends PubPackageResolutionTest {
|
||||
test_const_namedField() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final a = 0;
|
||||
var v = const (a: a);
|
||||
''',
|
||||
[error(diag.nonConstantRecordField, 31, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantRecordField] The fields in a const record literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_positionalField() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final a = 0;
|
||||
var v = const (a, );
|
||||
''',
|
||||
[error(diag.nonConstantRecordField, 28, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantRecordField] The fields in a const record literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final a = 0;
|
||||
var v = (a, );
|
||||
''');
|
||||
|
||||
+14
-15
@@ -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(NonConstantRelationalPatternExpressionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +24,7 @@ class NonConstantRelationalPatternExpressionTest
|
||||
const int a = 0;
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
|
||||
void f(int x) {
|
||||
@@ -33,7 +34,7 @@ void f(int x) {
|
||||
}
|
||||
|
||||
test_const_integerLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(x) {
|
||||
if (x case > 0) {}
|
||||
}
|
||||
@@ -41,7 +42,7 @@ void f(x) {
|
||||
}
|
||||
|
||||
test_const_localVariable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(x) {
|
||||
const a = 0;
|
||||
if (x case > a) {}
|
||||
@@ -50,7 +51,7 @@ void f(x) {
|
||||
}
|
||||
|
||||
test_const_topLevelVariable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
const a = 0;
|
||||
|
||||
void f(x) {
|
||||
@@ -60,26 +61,24 @@ void f(x) {
|
||||
}
|
||||
|
||||
test_notConst_formalParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(x, int a) {
|
||||
if (x case > a) {}
|
||||
// ^
|
||||
// [diag.nonConstantRelationalPatternExpression] The relational pattern expression must be a constant.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantRelationalPatternExpression, 34, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notConst_topLevelVariable() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final a = 0;
|
||||
|
||||
void f(x) {
|
||||
if (x case > a) {}
|
||||
// ^
|
||||
// [diag.nonConstantRelationalPatternExpression] The relational pattern expression must be a constant.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantRelationalPatternExpression, 41, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,128 +2,117 @@
|
||||
// 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(NonConstantSetElementTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantSetElementTest extends PubPackageResolutionTest
|
||||
with NonConstantSetElementTestCases {}
|
||||
|
||||
mixin NonConstantSetElementTestCases on PubPackageResolutionTest {
|
||||
class NonConstantSetElementTest extends PubPackageResolutionTest {
|
||||
test_const_ifElement_thenElseFalse_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{if (1 < 0) 0 else a};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 59, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{if (1 < 0) a else 0};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalElse() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{if (1 > 0) 0 else a};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 59, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenElseTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{if (1 > 0) a else 0};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int>{if (1 < 0) a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenFalse_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{if (1 < 0) a};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_constThen() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
const dynamic a = 0;
|
||||
var v = const <int>{if (1 > 0) a};
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_ifElement_thenTrue_finalThen() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{if (1 > 0) a};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 52, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_parameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f(a) {
|
||||
return const {a};
|
||||
}''',
|
||||
[error(diag.nonConstantSetElement, 23, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_const_spread_final() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
final Set x = {};
|
||||
var v = const {...x};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 36, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_const_topVar() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = const <int>{a};
|
||||
''',
|
||||
[error(diag.nonConstantSetElement, 41, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonConstantSetElement] The values in a const set literal must be constants.
|
||||
''');
|
||||
}
|
||||
|
||||
test_nonConst_topVar() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
final dynamic a = 0;
|
||||
var v = <int>{a};
|
||||
''');
|
||||
|
||||
@@ -2,40 +2,40 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonConstantTypeArgumentTest);
|
||||
defineReflectiveTests(NonConstantTypeArgumentWarningTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantTypeArgumentTest extends PubPackageResolutionTest {
|
||||
test_asFunction_R() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef T = int Function(int);
|
||||
class C<R extends int Function(int)> {
|
||||
void f(Pointer<NativeFunction<T>> p) {
|
||||
p.asFunction<R>();
|
||||
// ^
|
||||
// [diag.nonConstantTypeArgument] The type arguments to 'asFunction' must be known at compile time, so they can't be type parameters.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantTypeArgument, 147, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonConstantTypeArgumentWarningTest extends PubPackageResolutionTest {
|
||||
test_ref_class() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@@ -51,7 +51,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_ref_class_cascade() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@@ -68,19 +68,18 @@ void main() {
|
||||
}
|
||||
|
||||
test_ref_typeParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
T genericRef<T extends Struct>(Pointer<T> p) =>
|
||||
p.ref;
|
||||
''',
|
||||
[error(diag.nonConstantTypeArgument, 72, 5)],
|
||||
);
|
||||
// ^^^^^
|
||||
// [diag.nonConstantTypeArgument] The type arguments to 'ref' must be known at compile time, so they can't be type parameters.
|
||||
''');
|
||||
}
|
||||
|
||||
test_refWithFinalizer_class() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@@ -96,7 +95,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_refWithFinalizer_class_cascade() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@@ -113,14 +112,13 @@ void main() {
|
||||
}
|
||||
|
||||
test_refWithFinalizer_typeParameter() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
T genericRefWithFinalizer<T extends Struct>(Pointer<T> p) =>
|
||||
p.refWithFinalizer(nullptr);
|
||||
''',
|
||||
[error(diag.nonConstantTypeArgument, 85, 27)],
|
||||
);
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [diag.nonConstantTypeArgument] The type arguments to 'refWithFinalizer' must be known at compile time, so they can't be type parameters.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+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(
|
||||
NonCovariantTypeParameterPositionInRepresentationTypeTest,
|
||||
);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,38 +20,24 @@ main() {
|
||||
class NonCovariantTypeParameterPositionInRepresentationTypeTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_contravariant() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(void Function(T) it) {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonCovariantTypeParameterPositionInRepresentationType,
|
||||
17,
|
||||
1,
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonCovariantTypeParameterPositionInRepresentationType] An extension type parameter can't be used in a non-covariant position of its representation type.
|
||||
''');
|
||||
}
|
||||
|
||||
test_covariant() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(T Function() it) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_invariant() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type A<T>(T Function(T) it) {}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonCovariantTypeParameterPositionInRepresentationType,
|
||||
17,
|
||||
1,
|
||||
),
|
||||
],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonCovariantTypeParameterPositionInRepresentationType] An extension type parameter can't be used in a non-covariant position of its representation type.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,35 @@
|
||||
// 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(NonExhaustiveSwitchExpressionTest);
|
||||
defineReflectiveTests(NonExhaustiveSwitchStatementTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonExhaustiveSwitchExpressionTest extends PubPackageResolutionTest {
|
||||
test_bool_true() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Object f(bool x) {
|
||||
return switch (x) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpression] The type 'bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'.
|
||||
true => 0,
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchExpression, 28, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_bool_true_false() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Object f(bool x) {
|
||||
return switch (x) {
|
||||
true => 1,
|
||||
@@ -41,7 +41,7 @@ Object f(bool x) {
|
||||
}
|
||||
|
||||
test_class_int_wildcard() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Object f(int x) {
|
||||
return switch (x) {
|
||||
0 => 0,
|
||||
@@ -52,7 +52,7 @@ Object f(int x) {
|
||||
}
|
||||
|
||||
test_class_withField_wildcard() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
Object f(int x) {
|
||||
return switch (x) {
|
||||
int(isEven: true) => 0,
|
||||
@@ -63,37 +63,28 @@ Object f(int x) {
|
||||
}
|
||||
|
||||
test_enum_2at2_hasWhen() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a, b
|
||||
}
|
||||
|
||||
Object f(E x) {
|
||||
return switch (x) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpression] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.a'.
|
||||
E.a when 1 == 0 => 0,
|
||||
E.b => 1,
|
||||
};
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonExhaustiveSwitchExpression,
|
||||
44,
|
||||
6,
|
||||
correctionContains: 'E.a',
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_invalidType_empty() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Unresolved x) => switch (x) {};
|
||||
''',
|
||||
[error(diag.undefinedClass, 7, 10)],
|
||||
);
|
||||
// ^^^^^^^^^^
|
||||
// [diag.undefinedClass] Undefined class 'Unresolved'.
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enum() async {
|
||||
@@ -101,90 +92,84 @@ void f(Unresolved x) => switch (x) {};
|
||||
enum _E { a, b }
|
||||
_E e() => _E.a;
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_enum.dart';
|
||||
|
||||
Object f() {
|
||||
return switch (e()) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpressionPrivate] The enum '_E' isn't exhaustively matched by the switch cases because some of the enum constants are private.
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchExpressionPrivate, 51, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enum_sameLibrary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum _E { a, b }
|
||||
// ^
|
||||
// [diag.unusedField] The value of the field 'a' isn't used.
|
||||
// ^
|
||||
// [diag.unusedField] The value of the field 'b' isn't used.
|
||||
|
||||
Object f(_E e) {
|
||||
return switch (e) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpression] The type '_E' isn't exhaustively matched by the switch cases since it doesn't match the pattern '_E.a'.
|
||||
};
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedField, 10, 1),
|
||||
error(diag.unusedField, 13, 1),
|
||||
error(diag.nonExhaustiveSwitchExpression, 44, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enumConstant() async {
|
||||
newFile(join(testPackageLibPath, 'private_enum.dart'), r'''
|
||||
enum E { a, b, _c }
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_enum.dart';
|
||||
|
||||
Object f(E e) {
|
||||
return switch (e) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpression] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'.
|
||||
E.a => 0,
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchExpression, 54, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enumConstant_only() async {
|
||||
newFile(join(testPackageLibPath, 'private_enum.dart'), r'''
|
||||
enum E { a, b, _c }
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_enum.dart';
|
||||
|
||||
Object f(E e) {
|
||||
return switch (e) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpressionPrivate] The enum 'E' isn't exhaustively matched by the switch cases because some of the enum constants are private.
|
||||
E.a => 0,
|
||||
E.b => 1,
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchExpressionPrivate, 54, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enumConstant_sameLibrary() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
enum E { a, b, _c }
|
||||
// ^^
|
||||
// [diag.unusedField] The value of the field '_c' isn't used.
|
||||
Object f(E e) {
|
||||
return switch (e) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpression] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E._c'.
|
||||
E.a => 0,
|
||||
E.b => 1,
|
||||
};
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.unusedField, 15, 2),
|
||||
error(diag.nonExhaustiveSwitchExpression, 45, 6),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_sealed() async {
|
||||
@@ -193,38 +178,36 @@ sealed class _A {}
|
||||
class B extends _A {}
|
||||
_A a() => B();
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_sealed.dart';
|
||||
|
||||
Object f() {
|
||||
return switch (a()) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchExpression] The type '_A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'B()'.
|
||||
};
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchExpression, 53, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonExhaustiveSwitchStatementTest extends PubPackageResolutionTest {
|
||||
test_alwaysExhaustive_bool_true() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'.
|
||||
case true:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 19, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_bool_true_false() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool x) {
|
||||
switch (x) {
|
||||
case true:
|
||||
@@ -236,7 +219,7 @@ void f(bool x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_bool_wildcard_typed_bool() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool x) {
|
||||
switch (x) {
|
||||
case bool _:
|
||||
@@ -247,24 +230,22 @@ void f(bool x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_bool_wildcard_typed_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'true'.
|
||||
case int _:
|
||||
// ^^^
|
||||
// [diag.patternNeverMatchesValueType] The matched value type 'bool' can never match the required type 'int'.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonExhaustiveSwitchStatement, 19, 6),
|
||||
error(diag.patternNeverMatchesValueType, 41, 3),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_bool_wildcard_untyped() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool x) {
|
||||
switch (x) {
|
||||
case _:
|
||||
@@ -275,22 +256,21 @@ void f(bool x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_boolNullable_true_false() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool? x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'bool?' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'null'.
|
||||
case true:
|
||||
case false:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 20, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_boolNullable_true_false_null() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(bool? x) {
|
||||
switch (x) {
|
||||
case true:
|
||||
@@ -303,25 +283,24 @@ void f(bool? x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_enum_2at1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a, b
|
||||
}
|
||||
|
||||
void f(E x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'.
|
||||
case E.a:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 35, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_enum_2at2_cases() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a, b
|
||||
}
|
||||
@@ -337,33 +316,25 @@ void f(E x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_enum_2at2_hasWhen() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a, b
|
||||
}
|
||||
|
||||
void f(E x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.a'.
|
||||
case E.a when 1 == 0:
|
||||
case E.b:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(
|
||||
diag.nonExhaustiveSwitchStatement,
|
||||
35,
|
||||
6,
|
||||
correctionContains: 'E.a',
|
||||
),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_enum_2at2_logicalOr() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
a, b
|
||||
}
|
||||
@@ -378,10 +349,13 @@ void f(E x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_enum_cannotCompute() 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(Object f);
|
||||
}
|
||||
|
||||
@@ -392,27 +366,21 @@ void f(E x) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.recursiveCompileTimeConstant, 11, 2),
|
||||
error(diag.recursiveCompileTimeConstant, 19, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_Null_hasError() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Null x) {
|
||||
switch (x) {}
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'Null' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'null'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 19, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_Null_noError() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Null x) {
|
||||
switch (x) {
|
||||
case null:
|
||||
@@ -423,7 +391,7 @@ void f(Null x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_recordType_bool_bool_4at4() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f((bool, bool) x) {
|
||||
switch (x) {
|
||||
case (false, false):
|
||||
@@ -437,25 +405,24 @@ void f((bool, bool) x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_2at1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
class C extends A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'C()'.
|
||||
case B():
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 77, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_2at2() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
class C extends A {}
|
||||
@@ -472,7 +439,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_2at2_wildcard() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
class C extends A {}
|
||||
@@ -489,8 +456,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_constraintsMixin() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
|
||||
class B extends A {}
|
||||
@@ -499,17 +465,17 @@ mixin M on A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'M()'.
|
||||
case B _:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 74, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_hasExtensionType_1of1() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
extension type EA(A it) implements A {}
|
||||
@@ -524,8 +490,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_hasExtensionType_1of2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
class C extends A {}
|
||||
@@ -533,18 +498,17 @@ extension type EA(A it) implements A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'C()'.
|
||||
case B():
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 117, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_implementedByEnum_3at2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
|
||||
class B implements A {}
|
||||
@@ -555,18 +519,18 @@ enum E implements A {
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'.
|
||||
case B _:
|
||||
case E.a:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 92, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_implementedByEnum_3at3() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
|
||||
class B implements A {}
|
||||
@@ -587,8 +551,7 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_implementedByMixin_2at1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
|
||||
class B implements A {}
|
||||
@@ -597,17 +560,17 @@ mixin M implements A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'M()'.
|
||||
case B _:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 85, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_implementedByMixin_2at2() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
|
||||
class B implements A {}
|
||||
@@ -625,55 +588,52 @@ void f(A x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_unresolvedIdentifier() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
case unresolved:
|
||||
// ^^^^^^^^^^
|
||||
// [diag.undefinedIdentifier] Undefined name 'unresolved'.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedIdentifier, 78, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_sealedClass_unresolvedObject() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class A {}
|
||||
class B extends A {}
|
||||
|
||||
void f(A x) {
|
||||
switch (x) {
|
||||
case Unresolved():
|
||||
// ^^^^^^^^^^
|
||||
// [diag.undefinedClass] Undefined class 'Unresolved'.
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedClass, 78, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_typeVariable_bound_bool_true() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T extends bool>(T x) {
|
||||
switch (x) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'T' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'.
|
||||
case true:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 32, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_typeVariable_bound_bool_true_false() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T extends bool>(T x) {
|
||||
switch (x) {
|
||||
case true:
|
||||
@@ -685,23 +645,22 @@ void f<T extends bool>(T x) {
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_typeVariable_promoted_bool_true() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T x) {
|
||||
if (x is bool) {
|
||||
switch (x) {
|
||||
// ^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'T & bool' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'false'.
|
||||
case true:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 40, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_typeVariable_promoted_bool_true_false() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f<T>(T x) {
|
||||
if (x is bool) {
|
||||
switch (x) {
|
||||
@@ -715,18 +674,17 @@ void f<T>(T x) {
|
||||
}
|
||||
|
||||
test_invalidType_empty() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(Unresolved x) {
|
||||
// ^^^^^^^^^^
|
||||
// [diag.undefinedClass] Undefined class 'Unresolved'.
|
||||
switch (x) {}
|
||||
}
|
||||
''',
|
||||
[error(diag.undefinedClass, 7, 10)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notAlwaysExhaustive_int() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int x) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
@@ -741,56 +699,53 @@ void f(int x) {
|
||||
enum _E { a, b }
|
||||
_E e() => _E.a;
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_enum.dart';
|
||||
|
||||
void f() {
|
||||
switch (e()) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatementPrivate] The enum '_E' isn't exhaustively matched by the switch cases because some of the enum constants are private.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatementPrivate, 42, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enumConstant() async {
|
||||
newFile(join(testPackageLibPath, 'private_enum.dart'), r'''
|
||||
enum E { a, b, _c }
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_enum.dart';
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type 'E' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'E.b'.
|
||||
case E.a:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 45, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_enumConstant_only() async {
|
||||
newFile(join(testPackageLibPath, 'private_enum.dart'), r'''
|
||||
enum E { a, b, _c }
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_enum.dart';
|
||||
|
||||
void f(E e) {
|
||||
switch (e) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatementPrivate] The enum 'E' isn't exhaustively matched by the switch cases because some of the enum constants are private.
|
||||
case E.a:
|
||||
case E.b:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatementPrivate, 45, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_private_sealed() async {
|
||||
@@ -799,16 +754,15 @@ sealed class _A {}
|
||||
class B extends _A {}
|
||||
_A a() => B();
|
||||
''');
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import 'private_sealed.dart';
|
||||
|
||||
Object f() {
|
||||
switch (a()) {
|
||||
//^^^^^^
|
||||
// [diag.nonExhaustiveSwitchStatement] The type '_A' isn't exhaustively matched by the switch cases since it doesn't match the pattern 'B()'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonExhaustiveSwitchStatement, 46, 6)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(NonFinalFieldInEnumTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonFinalFieldInEnumTest extends PubPackageResolutionTest {
|
||||
test_declaringFormalParameter_optionalNamed_typeInt_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E({final int foo = 0}) {
|
||||
v(foo: 0);
|
||||
}
|
||||
@@ -24,18 +25,17 @@ enum E({final int foo = 0}) {
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_optionalNamed_typeInt_var() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E({var int foo = 0}) {
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
v(foo: 0);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 16, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_optionalPositional_typeInt_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E([final int foo = 0]) {
|
||||
v(0);
|
||||
}
|
||||
@@ -43,18 +43,17 @@ enum E([final int foo = 0]) {
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_optionalPositional_typeInt_var() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E([var int foo = 0]) {
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
v(0);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 16, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_requiredNamed_typeInt_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E({required final int foo}) {
|
||||
v(foo: 0);
|
||||
}
|
||||
@@ -62,18 +61,17 @@ enum E({required final int foo}) {
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_requiredNamed_typeInt_var() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E({required var int foo}) {
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
v(foo: 0);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 25, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_requiredPositional_functionTyped_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(final void foo()?) {
|
||||
v(null);
|
||||
}
|
||||
@@ -81,18 +79,17 @@ enum E(final void foo()?) {
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_requiredPositional_functionTyped_var() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(var void foo()?) {
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
v(null);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 16, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_requiredPositional_typeInt_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(final int foo) {
|
||||
v(0);
|
||||
}
|
||||
@@ -100,42 +97,39 @@ enum E(final int foo) {
|
||||
}
|
||||
|
||||
test_declaringFormalParameter_requiredPositional_typeInt_var() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(var int foo) {
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
v(0);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 15, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldDeclaration_instance() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
int foo = 0;
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 20, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldDeclaration_instance_covariant() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
covariant int foo = 0;
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 30, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldDeclaration_instance_external() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
external int foo;
|
||||
@@ -144,7 +138,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_fieldDeclaration_instance_external_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
external final int foo;
|
||||
@@ -153,7 +147,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_fieldDeclaration_instance_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
final int foo = 0;
|
||||
@@ -162,19 +156,18 @@ enum E {
|
||||
}
|
||||
|
||||
test_fieldDeclaration_instance_late() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
late int foo = 0;
|
||||
// ^^^
|
||||
// [diag.nonFinalFieldInEnum] Enums can only declare final fields.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonFinalFieldInEnum, 25, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_fieldDeclaration_static() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
static int foo = 0;
|
||||
@@ -183,7 +176,7 @@ enum E {
|
||||
}
|
||||
|
||||
test_fieldDeclaration_static_final() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
static final int foo = 0;
|
||||
|
||||
@@ -2,81 +2,78 @@
|
||||
// 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(NonGenerativeConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonGenerativeConstructorTest extends PubPackageResolutionTest {
|
||||
test_factory_explicit_constructor() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A.named() => throw 0;
|
||||
A.generative();
|
||||
}
|
||||
class B extends A {
|
||||
B() : super.named();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.nonGenerativeConstructor] The generative constructor 'A.named()' is expected, but a factory was found.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonGenerativeConstructor, 90, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factory_explicit_primaryConstructor_hasBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A.named() => throw 0;
|
||||
A.generative();
|
||||
}
|
||||
class B() extends A {
|
||||
this : super.named();
|
||||
// ^^^^^^^^^^^^^
|
||||
// [diag.nonGenerativeConstructor] The generative constructor 'A.named()' is expected, but a factory was found.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonGenerativeConstructor, 93, 13)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factory_implicit_constructor_newHead() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw 0;
|
||||
A.named();
|
||||
}
|
||||
class B extends A {
|
||||
new foo();
|
||||
//^^^^^^^
|
||||
// [diag.nonGenerativeConstructor] The generative constructor 'A()' is expected, but a factory was found.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonGenerativeConstructor, 73, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factory_implicit_constructor_typeName() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw 0;
|
||||
A.named();
|
||||
}
|
||||
class B extends A {
|
||||
B.foo();
|
||||
//^^^^^
|
||||
// [diag.nonGenerativeConstructor] The generative constructor 'A()' is expected, but a factory was found.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonGenerativeConstructor, 73, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_factory_implicit_constructor_typeName_external() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.named() {}
|
||||
factory A() => throw 0;
|
||||
@@ -88,22 +85,21 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_factory_implicit_primaryConstructor_hasBody() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw 0;
|
||||
A.named();
|
||||
}
|
||||
class B() extends A {
|
||||
this;
|
||||
//^^^^
|
||||
// [diag.nonGenerativeConstructor] The generative constructor 'A()' is expected, but a factory was found.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonGenerativeConstructor, 75, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_generative_constructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.named() {}
|
||||
factory A() => throw 0;
|
||||
@@ -115,7 +111,7 @@ class B extends A {
|
||||
}
|
||||
|
||||
test_generative_primaryConstructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.named() {}
|
||||
factory A() => throw 0;
|
||||
@@ -127,7 +123,7 @@ class B() extends A {
|
||||
}
|
||||
|
||||
test_generative_primaryContructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A.named() {}
|
||||
factory A() => throw 0;
|
||||
|
||||
@@ -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(NonGenerativeImplicitConstructorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,7 +26,7 @@ augment class B {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
part 'a.dart';
|
||||
|
||||
class A {}
|
||||
@@ -34,16 +35,15 @@ class B extends A {}
|
||||
}
|
||||
|
||||
test_implicit() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
factory A() => throw 0;
|
||||
A.named();
|
||||
}
|
||||
class B extends A {
|
||||
// ^
|
||||
// [diag.nonGenerativeImplicitConstructor] The unnamed constructor of superclass 'A' (called by the default constructor of 'B') must be a generative constructor, but factory found.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonGenerativeImplicitConstructor, 57, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+15
-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(NonNativeFunctionTypeArgumentToPointerTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,57 +18,50 @@ main() {
|
||||
class NonNativeFunctionTypeArgumentToPointerTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_asFunction_1() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef R = Int8 Function(Int8);
|
||||
class C {
|
||||
void f(Pointer<Double> p) {
|
||||
p.asFunction<R>();
|
||||
// ^^^^^^^^^^
|
||||
// [diag.undefinedMethod] The method 'asFunction' isn't defined for the type 'Pointer'.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[
|
||||
// This changed from a method to a extension method, uses Dart semantics
|
||||
// instead of manual check now.
|
||||
error(diag.undefinedMethod, 98, 10),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_asFunction_2() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef TPrime = int Function(int);
|
||||
typedef F = String Function(String);
|
||||
class C {
|
||||
void f(Pointer<NativeFunction<TPrime>> p) {
|
||||
p.asFunction<F>();
|
||||
// ^
|
||||
// [diag.nonNativeFunctionTypeArgumentToPointer] Can't invoke 'asFunction' because the function signature 'NativeFunction<TPrime>' for the pointer isn't a valid C function signature.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonNativeFunctionTypeArgumentToPointer, 165, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_asFunction_F() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
typedef R = int Function(int);
|
||||
class C<T extends Function> {
|
||||
void f(Pointer<NativeFunction<T>> p) {
|
||||
p.asFunction<R>();
|
||||
// ^
|
||||
// [diag.nonConstantTypeArgument] The type arguments to 'asFunction' must be known at compile time, so they can't be type parameters.
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonConstantTypeArgument, 125, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_asFunction_Pointer_Opaque() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
main() {
|
||||
DynamicLibrary.open('dontcare')
|
||||
|
||||
@@ -2,52 +2,50 @@
|
||||
// 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(NonNullableEqualsParameterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonNullableEqualsParameterTest extends PubPackageResolutionTest {
|
||||
test_dynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
@override
|
||||
bool operator ==(dynamic other) => false;
|
||||
// ^^
|
||||
// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonNullableEqualsParameter, 38, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_inheritedDynamic() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
@override
|
||||
bool operator ==(dynamic other) => false;
|
||||
// ^^
|
||||
// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable.
|
||||
}
|
||||
class D extends C {
|
||||
@override
|
||||
bool operator ==(other) => false;
|
||||
// ^^
|
||||
// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonNullableEqualsParameter, 38, 2),
|
||||
error(diag.nonNullableEqualsParameter, 116, 2),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_inheritedFromObject() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
@override
|
||||
bool operator ==(other) => false;
|
||||
@@ -56,7 +54,7 @@ class C {
|
||||
}
|
||||
|
||||
test_int() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
@override
|
||||
bool operator ==(covariant int other) => false;
|
||||
@@ -65,19 +63,18 @@ class C {
|
||||
}
|
||||
|
||||
test_nullableObject() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
@override
|
||||
bool operator ==(Object? other) => false;
|
||||
// ^^
|
||||
// [diag.nonNullableEqualsParameter] The parameter type of '==' operators should be non-nullable.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonNullableEqualsParameter, 38, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
@override
|
||||
bool operator ==(Object other) => false;
|
||||
|
||||
@@ -2,49 +2,48 @@
|
||||
// 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(NonPositiveArrayDimensionTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonPositiveArrayDimensionTest extends PubPackageResolutionTest {
|
||||
test_multi_negative() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@Array.multi([-1])
|
||||
// ^^
|
||||
// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers.
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonPositiveArrayDimension, 74, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_multi_oneOfMany() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@Array.multi([1, 2, 3, -4, 5, 6])
|
||||
// ^^
|
||||
// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers.
|
||||
external Array<Array<Array<Array<Array<Array<Uint8>>>>>> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonPositiveArrayDimension, 83, 2)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_multi_positive() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@@ -55,35 +54,33 @@ final class MyStruct extends Struct {
|
||||
}
|
||||
|
||||
test_multi_zero() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@Array.multi([0])
|
||||
// ^
|
||||
// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers.
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonPositiveArrayDimension, 74, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_single_negative() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@Array(-12)
|
||||
// ^^^
|
||||
// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers.
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonPositiveArrayDimension, 67, 3)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_single_positive() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@@ -94,16 +91,15 @@ final class MyStruct extends Struct {
|
||||
}
|
||||
|
||||
test_single_zero() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
import "dart:ffi";
|
||||
|
||||
final class MyStruct extends Struct {
|
||||
@Array(0)
|
||||
// ^
|
||||
// [diag.nonPositiveArrayDimension] Array dimensions must be positive numbers.
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''',
|
||||
[error(diag.nonPositiveArrayDimension, 67, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
+26
-30
@@ -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(NonRedirectingGenerativeConstructorWithPrimaryTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ main() {
|
||||
class NonRedirectingGenerativeConstructorWithPrimaryTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_class_factory() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C(int x) {
|
||||
factory C.named() => C(0);
|
||||
}
|
||||
@@ -25,30 +26,28 @@ class C(int x) {
|
||||
}
|
||||
|
||||
test_class_generative_nonRedirecting() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C(int x) {
|
||||
C.named();
|
||||
//^^^^^^^
|
||||
// [diag.nonRedirectingGenerativeConstructorWithPrimary] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonRedirectingGenerativeConstructorWithPrimary, 19, 7)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_generative_redirectingToNonPrimary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C(int x) {
|
||||
C.named1() : this.named2();
|
||||
C.named2();
|
||||
//^^^^^^^^
|
||||
// [diag.nonRedirectingGenerativeConstructorWithPrimary] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonRedirectingGenerativeConstructorWithPrimary, 49, 8)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_generative_redirectingToPrimary() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C(int x) {
|
||||
C.named() : this(0);
|
||||
}
|
||||
@@ -56,7 +55,7 @@ class C(int x) {
|
||||
}
|
||||
|
||||
test_class_noPrimaryConstructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
C.named();
|
||||
}
|
||||
@@ -64,7 +63,7 @@ class C {
|
||||
}
|
||||
|
||||
test_enum_factory() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(int x) {
|
||||
v(0);
|
||||
factory E.named() => E.v;
|
||||
@@ -73,34 +72,31 @@ enum E(int x) {
|
||||
}
|
||||
|
||||
test_enum_generative_nonRedirecting() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(int x) {
|
||||
v(0);
|
||||
const E.named();
|
||||
// ^^^^^^^
|
||||
// [diag.nonRedirectingGenerativeConstructorWithPrimary] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
// ^^^^^
|
||||
// [diag.unusedElement] The declaration 'E.named' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[
|
||||
error(diag.nonRedirectingGenerativeConstructorWithPrimary, 32, 7),
|
||||
error(diag.unusedElement, 34, 5),
|
||||
],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_generative_redirectingToPrimary() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E(int x) {
|
||||
v(0);
|
||||
const E.named(int x) : this(x);
|
||||
// ^^^^^
|
||||
// [diag.unusedElement] The declaration 'E.named' isn't referenced.
|
||||
}
|
||||
''',
|
||||
[error(diag.unusedElement, 34, 5)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_enum_noPrimaryConstructor() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
enum E {
|
||||
v;
|
||||
const E();
|
||||
@@ -110,7 +106,7 @@ enum E {
|
||||
|
||||
test_extensionType_generative_nonRedirecting() async {
|
||||
// Extension types can have non-redirecting generative constructors.
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
extension type E(int x) {
|
||||
E.named(this.x);
|
||||
}
|
||||
|
||||
@@ -2,49 +2,48 @@
|
||||
// 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(NonSizedTypeArgument);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonSizedTypeArgument extends PubPackageResolutionTest {
|
||||
test_invalid_struct() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
@Array(8)
|
||||
external Array<Void> a0;
|
||||
// ^^^^
|
||||
// [diag.nonSizedTypeArgument] The type 'Void' isn't a valid type argument for 'Array'. The type argument must be a native integer, 'Float', 'Double', 'Pointer', or subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonSizedTypeArgument, 80, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_invalid_union() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Union {
|
||||
@Array(8)
|
||||
external Array<Void> a0;
|
||||
// ^^^^
|
||||
// [diag.nonSizedTypeArgument] The type 'Void' isn't a valid type argument for 'Array'. The type argument must be a native integer, 'Float', 'Double', 'Pointer', or subtype of 'Struct', 'Union', or 'AbiSpecificInteger'.
|
||||
}
|
||||
''',
|
||||
[error(diag.nonSizedTypeArgument, 79, 4)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_valid() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:ffi';
|
||||
|
||||
final class C extends Struct {
|
||||
|
||||
@@ -2,25 +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(NonTypeAsTypeArgumentTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonTypeAsTypeArgumentTest extends PubPackageResolutionTest {
|
||||
test_issue54388() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
sealed class Option<A> {}
|
||||
|
||||
final class None implements Option<A> {
|
||||
// ^
|
||||
// [diag.nonTypeAsTypeArgument] The name 'A' isn't a type, so it can't be used as a type argument.
|
||||
const None();
|
||||
}
|
||||
|
||||
@@ -33,29 +35,25 @@ A doOption<A>(
|
||||
},
|
||||
);
|
||||
}
|
||||
''',
|
||||
[error(diag.nonTypeAsTypeArgument, 62, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notAType() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int A = 0;
|
||||
class B<E> {}
|
||||
f(B<A> b) {}
|
||||
''',
|
||||
[error(diag.nonTypeAsTypeArgument, 29, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonTypeAsTypeArgument] The name 'A' isn't a type, so it can't be used as a type argument.
|
||||
''');
|
||||
}
|
||||
|
||||
test_undefinedIdentifier() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class B<E> {}
|
||||
f(B<A> b) {}
|
||||
''',
|
||||
[error(diag.nonTypeAsTypeArgument, 18, 1)],
|
||||
);
|
||||
// ^
|
||||
// [diag.nonTypeAsTypeArgument] The name 'A' isn't a type, so it can't be used as a type argument.
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(NonTypeInCatchClauseTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonTypeInCatchClauseTest extends PubPackageResolutionTest {
|
||||
test_isClass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
try {
|
||||
} on String catch (e) {
|
||||
@@ -27,7 +28,7 @@ f() {
|
||||
}
|
||||
|
||||
test_isFunctionTypeAlias() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F();
|
||||
f() {
|
||||
try {
|
||||
@@ -39,7 +40,7 @@ f() {
|
||||
}
|
||||
|
||||
test_isGenericFunctionTypeAlias() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F<T> = void Function(T);
|
||||
f() {
|
||||
try {
|
||||
@@ -51,7 +52,7 @@ f() {
|
||||
}
|
||||
|
||||
test_isInterfaceTypeTypeAlias() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef F = String;
|
||||
f() {
|
||||
try {
|
||||
@@ -63,7 +64,7 @@ f() {
|
||||
}
|
||||
|
||||
test_isTypeParameter() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A<T extends Object> {
|
||||
f() {
|
||||
try {
|
||||
@@ -76,36 +77,34 @@ class A<T extends Object> {
|
||||
}
|
||||
|
||||
test_notDefined() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
f() {
|
||||
try {
|
||||
} on T catch (e) {
|
||||
// ^
|
||||
// [diag.nonTypeInCatchClause] The name 'T' isn't a type and can't be used in an on-catch clause.
|
||||
e;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonTypeInCatchClause, 21, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notType() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var T = 0;
|
||||
f() {
|
||||
try {
|
||||
} on T catch (e) {
|
||||
// ^
|
||||
// [diag.nonTypeInCatchClause] The name 'T' isn't a type and can't be used in an on-catch clause.
|
||||
e;
|
||||
}
|
||||
}
|
||||
''',
|
||||
[error(diag.nonTypeInCatchClause, 32, 1)],
|
||||
);
|
||||
''');
|
||||
}
|
||||
|
||||
test_noType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
f() {
|
||||
try {
|
||||
} catch (e) {
|
||||
|
||||
@@ -2,31 +2,31 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(NonVoidReturnForOperatorTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonVoidReturnForOperatorTest extends PubPackageResolutionTest {
|
||||
test_indexSetter() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int operator []=(a, b) { return a; }
|
||||
}''',
|
||||
[error(diag.nonVoidReturnForOperator, 12, 3)],
|
||||
);
|
||||
//^^^
|
||||
// [diag.nonVoidReturnForOperator] The return type of the operator []= must be 'void'.
|
||||
}''');
|
||||
}
|
||||
|
||||
test_no_return() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
operator []=(a, b) {}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class A {
|
||||
}
|
||||
|
||||
test_void() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void operator []=(a, b) {}
|
||||
}
|
||||
|
||||
@@ -2,55 +2,53 @@
|
||||
// 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(NonVoidReturnForSetterTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class NonVoidReturnForSetterTest extends PubPackageResolutionTest {
|
||||
test_function() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
int set x(int v) {
|
||||
// [diag.nonVoidReturnForSetter][column 1][length 3] The return type of the setter must be 'void' or absent.
|
||||
return 42;
|
||||
}''',
|
||||
[error(diag.nonVoidReturnForSetter, 0, 3)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_function_no_return() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
set x(v) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_function_void() async {
|
||||
await assertNoErrorsInCode('''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
void set x(v) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_method() async {
|
||||
await assertErrorsInCode(
|
||||
'''
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
class A {
|
||||
int set x(int v) {
|
||||
//^^^
|
||||
// [diag.nonVoidReturnForSetter] The return type of the setter must be 'void' or absent.
|
||||
return 42;
|
||||
}
|
||||
}''',
|
||||
[error(diag.nonVoidReturnForSetter, 12, 3)],
|
||||
);
|
||||
}''');
|
||||
}
|
||||
|
||||
test_method_no_return() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
set x(v) {}
|
||||
}
|
||||
@@ -58,7 +56,7 @@ class A {
|
||||
}
|
||||
|
||||
test_method_void() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
void set x(v) {}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user