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

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

Issue 1852883003: Fix summarizing of types with unused type parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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/resynthesize_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/summarize_elements.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_elements.dart b/pkg/analyzer/lib/src/summary/summarize_elements.dart
index b7ecd893c073277b3f9e4afa0054d97bba176d2a..e1fb9a145496102ecdc36e948d6fc74c2a6fdd42 100644
--- a/pkg/analyzer/lib/src/summary/summarize_elements.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_elements.dart
@@ -450,7 +450,7 @@ class _CompilationUnitSerializer {
/**
* Compute the appropriate De Bruijn index to represent the given type
- * parameter [type].
+ * parameter [type], or return `null` if the type parameter is not in scope.
*/
int findTypeParameterIndex(TypeParameterType type, Element context) {
Element originalContext = context;
@@ -475,8 +475,7 @@ class _CompilationUnitSerializer {
}
context = context.enclosingElement;
}
- throw new StateError(
- 'Unbound type parameter $type (${originalContext?.location})');
+ return null;
}
/**
@@ -1009,7 +1008,15 @@ class _CompilationUnitSerializer {
EntityRefBuilder b = new EntityRefBuilder(slot: slot);
Element typeElement = type.element;
if (type is TypeParameterType) {
- b.paramReference = findTypeParameterIndex(type, context);
+ int typeParameterIndex = findTypeParameterIndex(type, context);
+ if (typeParameterIndex != null) {
+ b.paramReference = typeParameterIndex;
+ } else {
+ // Out-of-scope type parameters only occur in circumstances where they
+ // are irrelevant (i.e. when a type parameter is unused). So we can
+ // safely convert them to `dynamic`.
+ b.reference = serializeReferenceForType(DynamicTypeImpl.instance);
+ }
} else if (type is FunctionType &&
typeElement is FunctionElement &&
typeElement.enclosingElement == null) {
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698