Skip to content

Commit 73344a2

Browse files
authored
Remove assertion that is no longer valid. (#3913)
I actually can't imagine how it was ever valid. The `InheritingContainer.inheritanceChain` implementations can always result in a list that contains two instances of Object. Also make `inheritance` private, and improve some related tests.
1 parent f5baa7c commit 73344a2

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

lib/src/generator/templates.runtime_renderers.dart

-14
Original file line numberDiff line numberDiff line change
@@ -6938,19 +6938,6 @@ class _Renderer_Inheritable extends RendererBase<Inheritable> {
69386938
parent: r);
69396939
},
69406940
),
6941-
'inheritance': Property(
6942-
getValue: (CT_ c) => c.inheritance,
6943-
renderVariable: (CT_ c, Property<CT_> self,
6944-
List<String> remainingNames) =>
6945-
self.renderSimpleVariable(
6946-
c, remainingNames, 'List<InheritingContainer>'),
6947-
renderIterable: (CT_ c, RendererBase<CT_> r,
6948-
List<MustachioNode> ast, StringSink sink) {
6949-
return c.inheritance.map((e) => _render_InheritingContainer(
6950-
e, ast, r.template, sink,
6951-
parent: r));
6952-
},
6953-
),
69546941
'isCovariant': Property(
69556942
getValue: (CT_ c) => c.isCovariant,
69566943
renderVariable: (CT_ c, Property<CT_> self,
@@ -16216,7 +16203,6 @@ const _invisibleGetters = {
1621616203
'attributes',
1621716204
'canonicalLibrary',
1621816205
'canonicalModelElement',
16219-
'inheritance',
1622016206
'isCovariant',
1622116207
'isInherited',
1622216208
'isOverride',

lib/src/model/inheritable.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mixin Inheritable on ContainerMember {
5858
Container? previous;
5959
Container? previousNonSkippable;
6060
Container? found;
61-
for (var c in inheritance.reversed) {
61+
for (var c in _inheritance.reversed) {
6262
// Filter out mixins.
6363
if (c.containsElement(searchElement)) {
6464
if ((packageGraph.inheritThrough.contains(previous) &&
@@ -96,7 +96,11 @@ mixin Inheritable on ContainerMember {
9696
return super.computeCanonicalEnclosingContainer();
9797
}
9898

99-
List<InheritingContainer> get inheritance {
99+
/// A roughly ordered list of this element's enclosing container's inheritance
100+
/// chain.
101+
///
102+
/// See [InheritingContainer.inheritanceChain] for details.
103+
List<InheritingContainer> get _inheritance {
100104
var inheritance = [
101105
...(enclosingElement as InheritingContainer).inheritanceChain,
102106
];
@@ -120,7 +124,6 @@ mixin Inheritable on ContainerMember {
120124
if (inheritance.last != object) {
121125
inheritance.add(object);
122126
}
123-
assert(inheritance.where((e) => e == object).length == 1);
124127
return inheritance;
125128
}
126129

test/classes_test.dart

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:dartdoc/src/special_elements.dart';
56
import 'package:test/test.dart';
67
import 'package:test_reflective_loader/test_reflective_loader.dart';
78

@@ -182,5 +183,21 @@ class C<T> implements A<T>, _B<T> {}
182183
expect(c.publicInterfaces.first.modelElement, library.classes.named('A'));
183184
}
184185

186+
void test_inheritanceOfObjectInstanceMethod() async {
187+
// This code is written such that `Inheritable._inheritance` for
188+
// `A.toString()` includes two copies of Object; one from walking up B's
189+
// chain, and then the second from walking up C's chain.
190+
var library = await bootPackageWithLibrary('''
191+
class A implements B, C {}
192+
class B implements C {}
193+
class C implements D {}
194+
class D implements Object {}
195+
''');
196+
197+
var object = library.packageGraph.specialClasses[SpecialClass.object]!;
198+
var toString = library.classes.named('A').instanceMethods.named('toString');
199+
expect(toString.canonicalEnclosingContainer, object);
200+
}
201+
185202
// TODO(srawlins): Test everything else about classes.
186203
}

test/end2end/model_special_cases_test.dart

+16-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
library;
1111

1212
import 'package:async/async.dart';
13+
import 'package:dartdoc/src/element_type.dart';
1314
import 'package:dartdoc/src/matching_link_result.dart';
1415
import 'package:dartdoc/src/model/model.dart';
1516
import 'package:dartdoc/src/model_utils.dart';
@@ -413,14 +414,21 @@ void main() {
413414
.singleWhere((f) => f.name == 'hashCode');
414415
var objectModelElement =
415416
sdkAsPackageGraph.specialClasses[SpecialClass.object];
416-
// If this fails, EventTarget might have been changed to no longer
417-
// inherit from Interceptor. If that's true, adjust test case to
418-
// another class that does.
419-
expect(hashCode.inheritance.any((c) => c.name == 'Interceptor'), isTrue);
420-
// If EventTarget really does start implementing hashCode, this will
421-
// fail.
422-
expect(hashCode.href,
423-
equals('${htmlBasePlaceholder}dart-core/Object/hashCode.html'));
417+
expect(
418+
eventTarget.superChain,
419+
contains(isA<ParameterizedElementType>()
420+
.having((t) => t.name, 'name', 'Interceptor')),
421+
reason: 'EventTarget appears to no longer subtype Interceptor, which '
422+
'makes the premise of this test invalid. To keep the test case '
423+
'valid, we need to use a class that subclasses Interceptor.',
424+
);
425+
expect(
426+
hashCode.href,
427+
equals('${htmlBasePlaceholder}dart-core/Object/hashCode.html'),
428+
reason:
429+
"EventTarget appears to have an explicit override of 'hashCode', "
430+
'which makes this test case invalid.',
431+
);
424432
expect(hashCode.canonicalEnclosingContainer, equals(objectModelElement));
425433
expect(
426434
eventTarget.publicSuperChainReversed

0 commit comments

Comments
 (0)