Skip to content

Fix an enum-related assert in canonicalization #2812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/src/model/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/enum_field_renderer.dart';
import 'package:dartdoc/src/special_elements.dart';

class Enum extends InheritingContainer {
class Enum extends InheritingContainer with TypeImplementing {
Enum(ClassElement element, Library library, PackageGraph packageGraph)
: super(element, library, packageGraph);

List<InheritingContainer> _inheritanceChain;

@override
List<InheritingContainer> get inheritanceChain {
if (_inheritanceChain == null) {
Expand All @@ -23,6 +23,12 @@ class Enum extends InheritingContainer {
in superChain.map((e) => (e.modelElement as InheritingContainer))) {
_inheritanceChain.addAll(c.inheritanceChain);
}

_inheritanceChain.addAll(interfaces.expand(
(e) => (e.modelElement as InheritingContainer).inheritanceChain));

assert(_inheritanceChain
.contains(packageGraph.specialClasses[SpecialClass.enumClass]));
}
return _inheritanceChain.toList(growable: false);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/special_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ enum SpecialClass {

/// From dart:core, pragma
pragma,

/// From dart:core, Enum
enumClass,
}

/// A declaration of a special [Class] and how to find it.
Expand Down Expand Up @@ -70,6 +73,8 @@ class _SpecialClassDefinition {
const Map<String, _SpecialClassDefinition> _specialClassDefinitions = {
'Object': _SpecialClassDefinition(
SpecialClass.object, 'Object', 'dart.core', 'dart:core'),
'Enum': _SpecialClassDefinition(
SpecialClass.enumClass, 'Enum', 'dart.core', 'dart:core'),
'Interceptor': _SpecialClassDefinition(SpecialClass.interceptor,
'Interceptor', '_interceptors', 'dart:_interceptors',
required: false),
Expand Down