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

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

Issue 1956473004: Fix ast-based serialization of out-of-scope type parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove temporary debugging code. Created 4 years, 7 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/linker_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/link.dart
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 52b3243b6128cd12272b4874c563f160dd5de340..5f965ff78bbfb12639153e1085f9afda3b83a12e 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -180,8 +180,15 @@ EntityRefBuilder _createLinkedType(
return result;
} else if (type is TypeParameterType) {
TypeParameterElementForLink element = type.element;
- result.paramReference =
- typeParameterContext.typeParameterNestingLevel - element.nestingLevel;
+ if (typeParameterContext.isTypeParameterInScope(element)) {
+ result.paramReference =
+ typeParameterContext.typeParameterNestingLevel - element.nestingLevel;
+ } 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`.
+ result.reference = compilationUnit.addRawReference('dynamic');
+ }
return result;
} else if (type is FunctionType) {
Element element = type.element;
@@ -4197,6 +4204,20 @@ abstract class TypeParameterizedElementForLink
throw new RangeError('Invalid type parameter index');
}
}
+
+ /**
+ * Find out if the given [typeParameter] is in scope in this context.
+ */
+ bool isTypeParameterInScope(TypeParameterElementForLink typeParameter) {
+ if (typeParameter.enclosingElement == this) {
+ return true;
+ } else if (enclosingTypeParameterContext != null) {
+ return enclosingTypeParameterContext
+ .isTypeParameterInScope(typeParameter);
+ } else {
+ return false;
+ }
+ }
}
class TypeProviderForLink implements TypeProvider {
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698