Skip to content

Commit

Permalink
analyzer: track used calls to 'call' on an extension
Browse files Browse the repository at this point in the history
Fixes #55781

Change-Id: I34eb02d4c0f6a44afe98c0224bed779972a415e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387560
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
srawlins authored and Commit Queue committed Sep 30, 2024
1 parent 1488e4d commit 4038b97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,8 @@ class UsedLocalElements {
void addElement(Element? element) {
if (element is JoinPatternVariableElementImpl) {
elements.addAll(element.transitiveVariables);
} else if (element is ExecutableMember) {
elements.add(element.declaration);
} else if (element != null) {
elements.add(element);
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/analyzer/test/src/diagnostics/unused_element_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,18 @@ main() {
]);
}

test_method_isUsed_call_inExtension() async {
await assertNoErrorsInCode(r'''
extension<T> on T {
void call() {}
}
void f() {
(<T>(T t) => t())(7);
}
''');
}

test_method_isUsed_hasPragma_vmEntryPoint() async {
pragma;
await assertNoErrorsInCode(r'''
Expand Down Expand Up @@ -1366,6 +1378,16 @@ void main() {
''');
}

test_method_notUsed_call_inExtension() async {
await assertErrorsInCode(r'''
extension<T> on T {
void call() {}
}
''', [
error(WarningCode.UNUSED_ELEMENT, 27, 4),
]);
}

test_method_notUsed_hasSameNameAsUsed() async {
await assertErrorsInCode(r'''
class A {
Expand Down

0 comments on commit 4038b97

Please sign in to comment.