Skip to content

Commit

Permalink
Remove all references to MultiplyInheritedExecutableElement (#3914)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Oct 23, 2024
1 parent 2e64c2b commit f5baa7c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 82 deletions.
2 changes: 1 addition & 1 deletion lib/src/model/inheriting_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ abstract class InheritingContainer extends Container {
var getter = containerAccessorFrom(getterElement);
var setter = containerAccessorFrom(setterElement);
// Rebind [getterElement], [setterElement] as [ModelElement.from] can
// resolve [MultiplyInheritedExecutableElement]s or resolve [Member]s.
// resolve [Member]s.
getterElement = getter?.element;
setterElement = setter?.element;
assert(getter != null || setter != null);
Expand Down
31 changes: 1 addition & 30 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ abstract class ModelElement
_cacheNewModelElement(e, newModelElement, library,
enclosingContainer: enclosingContainer);

assert(newModelElement.element is! MultiplyInheritedExecutableElement);
return newModelElement;
}

Expand Down Expand Up @@ -255,7 +254,6 @@ abstract class ModelElement
_cacheNewModelElement(e, newModelElement, library,
enclosingContainer: enclosingContainer);

assert(newModelElement.element is! MultiplyInheritedExecutableElement);
return newModelElement;
}

Expand Down Expand Up @@ -288,8 +286,6 @@ abstract class ModelElement
Member? originalMember,
}) {
return switch (e) {
MultiplyInheritedExecutableElement() => e.resolveMultiplyInheritedElement(
library, packageGraph, enclosingContainer as Class),
LibraryElement() => packageGraph.findButDoNotCreateLibraryFor(e)!,
PrefixElement() => Prefix(e, library, packageGraph),
EnumElement() => Enum(e, library, packageGraph),
Expand Down Expand Up @@ -349,8 +345,7 @@ abstract class ModelElement
}) {
// Accessors can be part of a [Container], or a part of a [Library].
if (e.enclosingElement3 is ExtensionElement ||
e.enclosingElement3 is InterfaceElement ||
e is MultiplyInheritedExecutableElement) {
e.enclosingElement3 is InterfaceElement) {
if (enclosingContainer == null || enclosingContainer is Extension) {
return ContainerAccessor(e, library, packageGraph, enclosingContainer);
}
Expand Down Expand Up @@ -796,27 +791,3 @@ abstract class ModelElement

String get linkedObjectType => _packageGraph.dartCoreObject;
}

extension on MultiplyInheritedExecutableElement {
/// Resolves this very rare case incorrectly by picking the closest element in
/// the inheritance and interface chains from the analyzer.
// TODO(jcollins-g): Implement resolution per ECMA-408 4th edition, page 39
// #22.
ModelElement resolveMultiplyInheritedElement(
Library library, PackageGraph packageGraph, Class enclosingClass) {
var inheritables = inheritedElements
.map((e) => ModelElement.forElement(e, packageGraph) as Inheritable);
late Inheritable foundInheritable;
var lowIndex = enclosingClass.inheritanceChain.length;
for (var inheritable in inheritables) {
var index = enclosingClass.inheritanceChain
.indexOf(inheritable.enclosingElement as InheritingContainer);
if (index < lowIndex) {
foundInheritable = inheritable;
lowIndex = index;
}
}
return ModelElement.for_(foundInheritable.element, library, packageGraph,
enclosingContainer: enclosingClass);
}
}
33 changes: 0 additions & 33 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1068,39 +1068,6 @@ void main() async {
});
});

group('MultiplyInheritedExecutableElement handling', () {
late final Class BaseThingy, BaseThingy2, ImplementingThingy2;
late final Method aImplementingThingyMethod;
late final Field aImplementingThingyField;
late final Field aImplementingThingy;
late final Accessor aImplementingThingyAccessor;

setUpAll(() {
BaseThingy = fakeLibrary.classes.named('BaseThingy');
BaseThingy2 = fakeLibrary.classes.named('BaseThingy2');
ImplementingThingy2 = fakeLibrary.classes.named('ImplementingThingy2');

aImplementingThingy =
ImplementingThingy2.instanceFields.named('aImplementingThingy');
aImplementingThingyMethod = ImplementingThingy2.instanceMethods
.named('aImplementingThingyMethod');
aImplementingThingyField =
ImplementingThingy2.instanceFields.named('aImplementingThingyField');
aImplementingThingyAccessor = aImplementingThingyField.getter!;
});

test('Verify behavior of imperfect resolver', () {
expect(aImplementingThingy.element.enclosingElement3,
equals(BaseThingy2.element));
expect(aImplementingThingyMethod.element.enclosingElement3,
equals(BaseThingy.element));
expect(aImplementingThingyField.element.enclosingElement3,
equals(BaseThingy.element));
expect(aImplementingThingyAccessor.element.enclosingElement3,
equals(BaseThingy.element));
});
});

group('Docs as HTML', () {
late final Class Apple, B, superAwesomeClass, foo2;
late final TopLevelVariable incorrectDocReferenceFromEx;
Expand Down
18 changes: 0 additions & 18 deletions testing/test_package/lib/fake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,6 @@ export 'src/reexport_this.dart';
/// Does not render with emoji 3ffe:2a00:100:7031::1
const int hasMarkdownInDoc = 1;

abstract class ImplementingThingy implements BaseThingy {}

abstract class BaseThingy {
// ignore: public_member_api_docs
ImplementingThingy get aImplementingThingy;
ImplementingThingy? aImplementingThingyField;
void aImplementingThingyMethod(ImplementingThingy parameter);
}

abstract class ImplementingThingy2 implements BaseThingy2, ImplementingThingy {}

/// Test for MultiplyInheritedExecutableElement handling.
abstract class BaseThingy2 implements BaseThingy {
/// BaseThingy2's doc for aImplementingThingy.
@override
ImplementingThingy2 get aImplementingThingy;
}

/// This function has a link to a renamed library class member.
///
/// Link to library: [renamedLib]
Expand Down

0 comments on commit f5baa7c

Please sign in to comment.