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

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

Issue 2668493002: Issue 28547. Fix for summarizing code with invalid type parameter reference. (Closed)
Patch Set: Handle invalid type parameter reference in expressions. Created 3 years, 11 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_common.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_ast.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_ast.dart b/pkg/analyzer/lib/src/summary/summarize_ast.dart
index f423cbf9291096e2e32d6a6ef16179f0fe893812..ce0307d1bb984e2ebffae41e4c5da86b7cb27445 100644
--- a/pkg/analyzer/lib/src/summary/summarize_ast.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_ast.dart
@@ -99,8 +99,7 @@ class _ConstExprSerializer extends AbstractConstExprSerializer {
EntityRefBuilder serializeIdentifier(Identifier identifier) {
EntityRefBuilder b = new EntityRefBuilder();
if (identifier is SimpleIdentifier) {
- int index = visitor.serializeSimpleReference(identifier.name,
- allowTypeParameter: true);
+ int index = visitor.serializeSimpleReference(identifier.name);
if (index < 0) {
b.paramReference = -index;
} else {
@@ -108,6 +107,9 @@ class _ConstExprSerializer extends AbstractConstExprSerializer {
}
} else if (identifier is PrefixedIdentifier) {
int prefix = visitor.serializeSimpleReference(identifier.prefix.name);
+ if (prefix < 0) {
+ throw new StateError('Invalid type parameter usage: $identifier}');
+ }
b.reference =
visitor.serializeReference(prefix, identifier.identifier.name);
} else {
@@ -266,7 +268,6 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
final List<UnlinkedReferenceBuilder> unlinkedReferences =
<UnlinkedReferenceBuilder>[new UnlinkedReferenceBuilder()];
-
/**
* List of [_Scope]s currently in effect. This is used to resolve type names
* to type parameters within classes, typedefs, and executables, as well as
@@ -842,10 +843,9 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
* Serialize a reference to a name declared either at top level or in a
* nested scope.
*
- * If [allowTypeParameter] is `true`, then references to type
- * parameters are allowed, and are returned as negative numbers.
+ * References to type parameters are returned as negative numbers.
*/
- int serializeSimpleReference(String name, {bool allowTypeParameter: false}) {
+ int serializeSimpleReference(String name) {
int indexOffset = 0;
for (int i = scopes.length - 1; i >= 0; i--) {
_Scope scope = scopes[i];
@@ -854,15 +854,9 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
if (entity is _ScopedClassMember) {
return serializeReference(
serializeReference(null, entity.className), name);
- } else if (allowTypeParameter && entity is _ScopedTypeParameter) {
+ } else if (entity is _ScopedTypeParameter) {
int paramReference = indexOffset + entity.index;
return -paramReference;
- } else {
- // Invalid reference to a type parameter. Should never happen in
- // legal Dart code.
- // TODO(paulberry): could this exception ever be uncaught in illegal
- // code?
- throw new StateError('Invalid identifier reference');
}
}
if (scope is _TypeParameterScope) {
@@ -909,8 +903,15 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
b.reference = serializeReference(null, name);
} else if (identifier is PrefixedIdentifier) {
int prefixIndex = serializeSimpleReference(identifier.prefix.name);
- b.reference =
- serializeReference(prefixIndex, identifier.identifier.name);
+ if (prefixIndex < 0) {
+ // Type parameters are not expected here, so this is an error and the
+ // type should be treated as a reference to `dynamic`.
+ b.reference = serializeReference(null, 'dynamic');
+ return b;
+ } else {
+ b.reference =
+ serializeReference(prefixIndex, identifier.identifier.name);
+ }
} else {
throw new StateError(
'Unexpected identifier type: ${identifier.runtimeType}');
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698