| 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 {
|
|
|