diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index cc7e979f8a..b12091d52d 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -204,13 +204,6 @@ abstract class ModelElement e.kind == ElementKind.DYNAMIC || e.kind == ElementKind.NEVER); - if (e.kind == ElementKind.DYNAMIC) { - return Dynamic(e, packageGraph); - } - if (e.kind == ElementKind.NEVER) { - return NeverType(e, packageGraph); - } - Member? originalMember; // TODO(jcollins-g): Refactor object model to instantiate 'ModelMembers' // for members? @@ -220,12 +213,21 @@ abstract class ModelElement } // Return the cached ModelElement if it exists. - var cachedModelElement = packageGraph.allConstructedModelElements[ - ConstructedModelElementsKey(e, library, enclosingContainer)]; + var key = ConstructedModelElementsKey(e, library, enclosingContainer); + var cachedModelElement = packageGraph.allConstructedModelElements[key]; if (cachedModelElement != null) { return cachedModelElement; } + if (e.kind == ElementKind.DYNAMIC) { + return packageGraph.allConstructedModelElements[key] = + Dynamic(e, packageGraph); + } + if (e.kind == ElementKind.NEVER) { + return packageGraph.allConstructedModelElements[key] = + NeverType(e, packageGraph); + } + var newModelElement = ModelElement._constructFromElementDeclaration( e, library,