Skip to content

Commit d6e562c

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate prefer_void_to_null
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: Ib02a59132056c0e2856eee30ac6cdc1a6e50cd67 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389200 Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 889e579 commit d6e562c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class InheritanceManager3 {
153153
@experimental
154154
ExecutableElement2? getInherited3(InterfaceType type, Name name) {
155155
var element = getInherited(type, name);
156+
if (element is ExecutableMember) {
157+
return element as ExecutableElement2;
158+
}
156159
return (element as ExecutableFragment?)?.element;
157160
}
158161

pkg/linter/lib/src/extensions.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,26 @@ extension InhertanceManager3Extension on InheritanceManager3 {
521521
var libraryUri = interfaceElement.library.source.uri;
522522
return getInherited(interfaceElement.thisType, Name(libraryUri, name));
523523
}
524+
525+
/// Returns the class member that is overridden by [member], if there is one,
526+
/// as defined by [getInherited].
527+
ExecutableElement2? overriddenMember2(Element2? member) {
528+
if (member == null) {
529+
return null;
530+
}
531+
532+
var interfaceElement = member.thisOrAncestorOfType2<InterfaceElement2>();
533+
if (interfaceElement == null) {
534+
return null;
535+
}
536+
var name = member.name;
537+
if (name == null) {
538+
return null;
539+
}
540+
541+
var libraryUri = interfaceElement.library2.firstFragment.source.uri;
542+
return getInherited3(interfaceElement.thisType, Name(libraryUri, name));
543+
}
524544
}
525545

526546
extension InterfaceElementExtension on InterfaceElement {

pkg/linter/lib/src/rules/prefer_void_to_null.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class _Visitor extends SimpleAstVisitor<void> {
4646
// Make sure we're checking a return type.
4747
if (parent.returnType?.offset != node.offset) return false;
4848

49-
var member =
50-
context.inheritanceManager.overriddenMember(parent.declaredElement);
49+
var member = context.inheritanceManager
50+
.overriddenMember2(parent.declaredFragment?.element);
5151
if (member == null) return false;
5252

5353
var returnType = member.returnType;

0 commit comments

Comments
 (0)