Skip to content

Commit 6655850

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: For Deprecated.optional warnings, test indirect constructor invocations
In this CL we add tests that assert that redirected constructors are not visited indirectly / transitively when checking for `@Deprecated.optional` parameters. This is a follow-up from comments in https://dart-review.googlesource.com/c/sdk/+/457120. Change-Id: I00d489cc22f928fbb538f4fd3c0ca9fb5cb19b3b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458081 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 207d00e commit 6655850

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,26 @@ class C {
290290
);
291291
}
292292

293+
test_argumentOmitted_redirectedConstructor_indirectlyDeprecated() async {
294+
// This test asserts that we do _not_ report the `C.three` constructor.
295+
// While the `C.two` constructor must deal with the deprecation of the
296+
// optionality of `C.new`'s `p` parameter, there is nothing to do for
297+
// `C.three`. (For example, we can't pass a positional argument to
298+
// `this.two()`, because `C.two` does not accept a positional parameter.)
299+
// Whether and how `C.three` must change depends on how `C.two` is changed
300+
// to handle the deprecation.
301+
await assertErrorsInCode(
302+
r'''
303+
class C {
304+
C([@Deprecated.optional() int? p]);
305+
C.two() : this();
306+
C.three() : this.two();
307+
}
308+
''',
309+
[error(WarningCode.deprecatedOptional, 60, 4)],
310+
);
311+
}
312+
293313
test_argumentOmitted_redirectedConstructor_named() async {
294314
await assertErrorsInCode(
295315
r'''
@@ -378,6 +398,31 @@ class D extends C {
378398
);
379399
}
380400

401+
test_argumentOmitted_superInvocation_indirectlyDeprecated() async {
402+
// This test asserts that we do _not_ report the `E.new` constructor. While
403+
// the `D.new` constructor must deal with the deprecation of the optionality
404+
// of `C.new`'s `p` parameter, there is nothing to do for `E.new`. (For
405+
// example, we can't pass a positional argument to `super()`, because
406+
// `D.new` does not accept a positional parameter.) Whether and how `E.new`
407+
// must change depends on how `D.new` is changed to handle the deprecation.
408+
await assertErrorsInCode(
409+
r'''
410+
class C {
411+
C([@Deprecated.optional() int? p]);
412+
}
413+
414+
class D extends C {
415+
D() : super();
416+
}
417+
418+
class E extends D {
419+
E() : super();
420+
}
421+
''',
422+
[error(WarningCode.deprecatedOptional, 79, 5)],
423+
);
424+
}
425+
381426
test_argumentOmitted_superInvocation_namedParameter() async {
382427
await assertErrorsInCode(
383428
r'''

0 commit comments

Comments
 (0)