Skip to content

Commit 15cdd91

Browse files
rootvector2Commit Queue
authored andcommitted
Fix unused_element false positive for constructors used via mixin
Closes #62922 GitOrigin-RevId: 72f0d5d Change-Id: Ib0857acdb71c38cd6c2cef0cb418ca40a8968ee1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488526 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
1 parent c1ebd22 commit 15cdd91

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,12 @@ class UsedLocalElements {
12331233
elements.add(element.baseElement);
12341234
} else if (element != null) {
12351235
elements.add(element);
1236+
var enclosingElement = element.enclosingElement;
1237+
if (element is ConstructorElementImpl &&
1238+
enclosingElement is ClassElementImpl &&
1239+
enclosingElement.isMixinApplication) {
1240+
addElement(element.superConstructor);
1241+
}
12361242
}
12371243
}
12381244

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,26 @@ A f() => A._constructor();
372372
''');
373373
}
374374

375+
test_constructor_isUsed_mixinApplicationRedirect() async {
376+
await assertNoErrorsInCode(r'''
377+
abstract class Foo {
378+
factory Foo({required String thing}) = _Foo._;
379+
Foo._({required this.thing});
380+
381+
final String thing;
382+
383+
void bar();
384+
}
385+
386+
mixin _$Foo on Foo {
387+
@override
388+
void bar() {}
389+
}
390+
391+
class _Foo = Foo with _$Foo;
392+
''');
393+
}
394+
375395
test_constructor_notUsed_multiple() async {
376396
await assertErrorsInCode(
377397
r'''

0 commit comments

Comments
 (0)