[wilcards] `DUPLICATE_FIELD_FORMAL_PARAMETER` tests
Fixes: https://github.com/dart-lang/sdk/issues/56092
Change-Id: Iba8a273f5ddf47bd39916a7f19b6cd214dd57583
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_field_formal_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_field_formal_parameter_test.dart
index 45a7c5e..1b53d64 100644
--- a/pkg/analyzer/test/src/diagnostics/duplicate_field_formal_parameter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/duplicate_field_formal_parameter_test.dart
@@ -27,6 +27,39 @@
]);
}
+ test_optional_named_wildcard() async {
+ await assertErrorsInCode(r'''
+class A {
+ int _;
+ A({this._ = 0, this._ = 1});
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 16, 1),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 29, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 41, 1,
+ contextMessages: [message(testFile, 29, 1)]),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 41, 1),
+ ]);
+ }
+
+ test_optional_named_wildcard_preWildcards() async {
+ await assertErrorsInCode(r'''
+// @dart = 3.4
+// (pre wildcard-variables)
+
+class A {
+ int _;
+ A({this._ = 0, this._ = 1});
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 60, 1),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 73, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 85, 1,
+ contextMessages: [message(testFile, 73, 1)]),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 85, 1),
+ ]);
+ }
+
test_optional_positional() async {
await assertErrorsInCode(r'''
class A {
@@ -51,6 +84,64 @@
]);
}
+ test_optional_positional_final_wildcard() async {
+ await assertErrorsInCode(r'''
+class A {
+ final _;
+ A([this._ = 1, this._ = 2]) {}
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 18, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 43, 1,
+ contextMessages: [message(testFile, 31, 1)]),
+ ]);
+ }
+
+ test_optional_positional_final_wildcard_preWildcards() async {
+ await assertErrorsInCode(r'''
+// @dart = 3.4
+// (pre wildcard-variables)
+
+class A {
+ final _;
+ A([this._ = 1, this._ = 2]) {}
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 62, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 87, 1,
+ contextMessages: [message(testFile, 75, 1)]),
+ ]);
+ }
+
+ test_optional_positional_wildcard() async {
+ await assertErrorsInCode(r'''
+class A {
+ int _;
+ A([this._ = 0, this._ = 1]);
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 16, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 41, 1,
+ contextMessages: [message(testFile, 29, 1)]),
+ ]);
+ }
+
+ test_optional_positional_wildcard_preWildcards() async {
+ await assertErrorsInCode(r'''
+// @dart = 3.4
+// (pre wildcard-variables)
+
+class A {
+ int _;
+ A([this._ = 0, this._ = 1]);
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 60, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 85, 1,
+ contextMessages: [message(testFile, 73, 1)]),
+ ]);
+ }
+
test_required_named() async {
await assertErrorsInCode(r'''
class A {
@@ -63,6 +154,39 @@
]);
}
+ test_required_named_wildcard() async {
+ await assertErrorsInCode(r'''
+class A {
+ int _;
+ A({required this._, required this._});
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 16, 1),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 38, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 55, 1,
+ contextMessages: [message(testFile, 38, 1)]),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 55, 1),
+ ]);
+ }
+
+ test_required_named_wildcard_preWildcards() async {
+ await assertErrorsInCode(r'''
+// @dart = 3.4
+// (pre wildcard-variables)
+
+class A {
+ int _;
+ A({required this._, required this._});
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 60, 1),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 82, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 99, 1,
+ contextMessages: [message(testFile, 82, 1)]),
+ error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 99, 1),
+ ]);
+ }
+
test_required_positional() async {
await assertErrorsInCode(r'''
class A {
@@ -87,6 +211,35 @@
]);
}
+ test_required_positional_final_wildcard() async {
+ await assertErrorsInCode(r'''
+class A {
+ final _;
+ A(this._, this._) {}
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 18, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 38, 1,
+ contextMessages: [message(testFile, 30, 1)]),
+ ]);
+ }
+
+ test_required_positional_final_wildcard_preWildcards() async {
+ await assertErrorsInCode(r'''
+// @dart = 3.4
+// (pre wildcard-variables)
+
+class A {
+ final _;
+ A(this._, this._) {}
+}
+''', [
+ error(WarningCode.UNUSED_FIELD, 62, 1),
+ error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 82, 1,
+ contextMessages: [message(testFile, 74, 1)]),
+ ]);
+ }
+
test_required_positional_preWildcards() async {
await assertErrorsInCode(r'''
// @dart = 3.4