Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1143)

Unified Diff: pkg/analyzer/lib/src/summary/index_unit.dart

Issue 1746963002: Follow ClassTypeAlias constructor redirections. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Simplify the method and fix the bug. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/index_unit_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/index_unit.dart
diff --git a/pkg/analyzer/lib/src/summary/index_unit.dart b/pkg/analyzer/lib/src/summary/index_unit.dart
index a1dd568b5a40ce25af041942374f3ed02f901a4c..0fa4ec868a1d9fdb3feb0f1cd718750d37624030 100644
--- a/pkg/analyzer/lib/src/summary/index_unit.dart
+++ b/pkg/analyzer/lib/src/summary/index_unit.dart
@@ -384,14 +384,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
@override
visitConstructorName(ConstructorName node) {
ConstructorElement element = node.staticElement;
- // in 'class B = A;' actually A constructors are invoked
- // TODO(scheglov) add support for multiple levels of redirection
- // TODO(scheglov) test for a loop of redirection
- if (element != null &&
- element.isSynthetic &&
- element.redirectedConstructor != null) {
- element = element.redirectedConstructor;
- }
+ element = _getActualConstructorElement(element);
// record relation
if (node.name != null) {
int offset = node.period.offset;
@@ -553,6 +546,26 @@ class _IndexContributor extends GeneralizingAstVisitor {
recordSuperType(typeName, IndexRelationKind.IS_MIXED_IN_BY);
}
}
+
+ /**
+ * If the given [constructor] is a synthetic constructor created for a
+ * [ClassTypeAlias], return the actual constructor of a [ClassDeclaration]
+ * which is invoked. Return `null` if a redirection cycle is detected.
+ */
+ ConstructorElement _getActualConstructorElement(
+ ConstructorElement constructor) {
+ Set<ConstructorElement> seenConstructors = new Set<ConstructorElement>();
+ while (constructor != null &&
+ constructor.isSynthetic &&
+ constructor.redirectedConstructor != null) {
+ constructor = constructor.redirectedConstructor;
+ // fail if a cycle is detected
+ if (!seenConstructors.add(constructor)) {
+ return null;
+ }
+ }
+ return constructor;
+ }
}
/**
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/index_unit_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698