Skip to content

Commit 70cf68a

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Check deprecated member use on DotShorthandInvocation
Change-Id: Ie8cdb4f3b063cb8a5fdd2486ced421d481339f31 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451662 Reviewed-by: Kallen Tu <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 89380c5 commit 70cf68a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
374374
@override
375375
void visitDotShorthandInvocation(DotShorthandInvocation node) {
376376
_deprecatedFunctionalityVerifier.dotShorthandInvocation(node);
377-
// TODO(srawlins): I imagine we need to check with
378-
// `_deprecatedMemberUseVerifier` here...
377+
for (var v in _elementUsageFrontierDetectors) {
378+
v.dotShorthandInvocation(node);
379+
}
379380
super.visitDotShorthandInvocation(node);
380381
}
381382

pkg/analyzer/lib/src/error/element_usage_detector.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class ElementUsageDetector<TagInfo extends Object> {
131131
_invocationArguments(node.constructorName.element, node.argumentList);
132132
}
133133

134+
void dotShorthandInvocation(DotShorthandInvocation node) {
135+
_invocationArguments(node.memberName.element, node.argumentList);
136+
}
137+
134138
void exportDirective(ExportDirective node) {
135139
checkUsage(node.libraryExport?.exportedLibrary, node);
136140
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import '../dart/resolution/context_collection_resolution.dart';
1313

1414
main() {
1515
defineReflectiveSuite(() {
16-
defineReflectiveTests(DeprecatedMemberUse_PackageConfigWorkspaceTest);
1716
defineReflectiveTests(DeprecatedMemberUse_BlazeWorkspaceTest);
1817
defineReflectiveTests(DeprecatedMemberUse_GnWorkspaceTest);
1918
defineReflectiveTests(DeprecatedMemberUse_PackageBuildWorkspaceTest);
19+
defineReflectiveTests(DeprecatedMemberUse_PackageConfigWorkspaceTest);
2020
});
2121
}
2222

@@ -551,6 +551,29 @@ void f() {
551551
);
552552
}
553553

554+
test_dotShorthandInvocation_deprecatedMethod() async {
555+
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
556+
class A {
557+
@deprecated
558+
static A m() => A();
559+
}
560+
''');
561+
562+
await assertErrorsInCode(
563+
r'''
564+
import 'package:aaa/a.dart';
565+
566+
void f() {
567+
A a = .m();
568+
}
569+
''',
570+
[
571+
error(WarningCode.unusedLocalVariable, 45, 1),
572+
error(HintCode.deprecatedMemberUse, 50, 1),
573+
],
574+
);
575+
}
576+
554577
test_export() async {
555578
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
556579
@deprecated

0 commit comments

Comments
 (0)