Skip to content

Commit b7530a9

Browse files
pqCommit Queue
authored and
Commit Queue
committed
[wilcards] DUPLICATE_FIELD_FORMAL_PARAMETER tests
Fixes: #56092 Change-Id: Iba8a273f5ddf47bd39916a7f19b6cd214dd57583 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373540 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 6fcfa93 commit b7530a9

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

pkg/analyzer/test/src/diagnostics/duplicate_field_formal_parameter_test.dart

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,39 @@ class A {
2727
]);
2828
}
2929

30+
test_optional_named_wildcard() async {
31+
await assertErrorsInCode(r'''
32+
class A {
33+
int _;
34+
A({this._ = 0, this._ = 1});
35+
}
36+
''', [
37+
error(WarningCode.UNUSED_FIELD, 16, 1),
38+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 29, 1),
39+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 41, 1,
40+
contextMessages: [message(testFile, 29, 1)]),
41+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 41, 1),
42+
]);
43+
}
44+
45+
test_optional_named_wildcard_preWildcards() async {
46+
await assertErrorsInCode(r'''
47+
// @dart = 3.4
48+
// (pre wildcard-variables)
49+
50+
class A {
51+
int _;
52+
A({this._ = 0, this._ = 1});
53+
}
54+
''', [
55+
error(WarningCode.UNUSED_FIELD, 60, 1),
56+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 73, 1),
57+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 85, 1,
58+
contextMessages: [message(testFile, 73, 1)]),
59+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 85, 1),
60+
]);
61+
}
62+
3063
test_optional_positional() async {
3164
await assertErrorsInCode(r'''
3265
class A {
@@ -51,6 +84,64 @@ class A {
5184
]);
5285
}
5386

87+
test_optional_positional_final_wildcard() async {
88+
await assertErrorsInCode(r'''
89+
class A {
90+
final _;
91+
A([this._ = 1, this._ = 2]) {}
92+
}
93+
''', [
94+
error(WarningCode.UNUSED_FIELD, 18, 1),
95+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 43, 1,
96+
contextMessages: [message(testFile, 31, 1)]),
97+
]);
98+
}
99+
100+
test_optional_positional_final_wildcard_preWildcards() async {
101+
await assertErrorsInCode(r'''
102+
// @dart = 3.4
103+
// (pre wildcard-variables)
104+
105+
class A {
106+
final _;
107+
A([this._ = 1, this._ = 2]) {}
108+
}
109+
''', [
110+
error(WarningCode.UNUSED_FIELD, 62, 1),
111+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 87, 1,
112+
contextMessages: [message(testFile, 75, 1)]),
113+
]);
114+
}
115+
116+
test_optional_positional_wildcard() async {
117+
await assertErrorsInCode(r'''
118+
class A {
119+
int _;
120+
A([this._ = 0, this._ = 1]);
121+
}
122+
''', [
123+
error(WarningCode.UNUSED_FIELD, 16, 1),
124+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 41, 1,
125+
contextMessages: [message(testFile, 29, 1)]),
126+
]);
127+
}
128+
129+
test_optional_positional_wildcard_preWildcards() async {
130+
await assertErrorsInCode(r'''
131+
// @dart = 3.4
132+
// (pre wildcard-variables)
133+
134+
class A {
135+
int _;
136+
A([this._ = 0, this._ = 1]);
137+
}
138+
''', [
139+
error(WarningCode.UNUSED_FIELD, 60, 1),
140+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 85, 1,
141+
contextMessages: [message(testFile, 73, 1)]),
142+
]);
143+
}
144+
54145
test_required_named() async {
55146
await assertErrorsInCode(r'''
56147
class A {
@@ -63,6 +154,39 @@ class A {
63154
]);
64155
}
65156

157+
test_required_named_wildcard() async {
158+
await assertErrorsInCode(r'''
159+
class A {
160+
int _;
161+
A({required this._, required this._});
162+
}
163+
''', [
164+
error(WarningCode.UNUSED_FIELD, 16, 1),
165+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 38, 1),
166+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 55, 1,
167+
contextMessages: [message(testFile, 38, 1)]),
168+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 55, 1),
169+
]);
170+
}
171+
172+
test_required_named_wildcard_preWildcards() async {
173+
await assertErrorsInCode(r'''
174+
// @dart = 3.4
175+
// (pre wildcard-variables)
176+
177+
class A {
178+
int _;
179+
A({required this._, required this._});
180+
}
181+
''', [
182+
error(WarningCode.UNUSED_FIELD, 60, 1),
183+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 82, 1),
184+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 99, 1,
185+
contextMessages: [message(testFile, 82, 1)]),
186+
error(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, 99, 1),
187+
]);
188+
}
189+
66190
test_required_positional() async {
67191
await assertErrorsInCode(r'''
68192
class A {
@@ -87,6 +211,35 @@ class A {
87211
]);
88212
}
89213

214+
test_required_positional_final_wildcard() async {
215+
await assertErrorsInCode(r'''
216+
class A {
217+
final _;
218+
A(this._, this._) {}
219+
}
220+
''', [
221+
error(WarningCode.UNUSED_FIELD, 18, 1),
222+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 38, 1,
223+
contextMessages: [message(testFile, 30, 1)]),
224+
]);
225+
}
226+
227+
test_required_positional_final_wildcard_preWildcards() async {
228+
await assertErrorsInCode(r'''
229+
// @dart = 3.4
230+
// (pre wildcard-variables)
231+
232+
class A {
233+
final _;
234+
A(this._, this._) {}
235+
}
236+
''', [
237+
error(WarningCode.UNUSED_FIELD, 62, 1),
238+
error(CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER, 82, 1,
239+
contextMessages: [message(testFile, 74, 1)]),
240+
]);
241+
}
242+
90243
test_required_positional_preWildcards() async {
91244
await assertErrorsInCode(r'''
92245
// @dart = 3.4

0 commit comments

Comments
 (0)