| 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 a9fe8221fc4b989450592c48b1797b53780088d0..f11967cd15adc2a8a740af99ce12cf3e02321d9a 100644
|
| --- a/pkg/analyzer/lib/src/summary/link.dart
|
| +++ b/pkg/analyzer/lib/src/summary/link.dart
|
| @@ -224,21 +224,13 @@ EntityRefBuilder _createLinkedType(
|
| if (element is FunctionElement && element.enclosingElement == null) {
|
| // Element is a synthetic function element that was generated on the fly
|
| // to represent a type that has no associated source code location.
|
| - result.syntheticReturnType = _createLinkedType(
|
| - element.returnType, compilationUnit, typeParameterContext);
|
| - result.entityKind =
|
| - element.returnType?.element is GenericFunctionTypeElement
|
| - ? EntityRefKind.genericFunctionType
|
| - : EntityRefKind.syntheticFunction;
|
| - result.syntheticParams = element.parameters
|
| - .map((ParameterElement param) => _serializeSyntheticParam(
|
| - param, compilationUnit, typeParameterContext))
|
| - .toList();
|
| + _storeFunctionElementByValue(result, element, compilationUnit);
|
| return result;
|
| }
|
| if (element is FunctionElement) {
|
| // Element is a local function inside another executable.
|
| result.reference = compilationUnit.addReference(element);
|
| + _storeFunctionElementByValue(result, element, compilationUnit);
|
| // TODO(paulberry): do I need to store type arguments?
|
| return result;
|
| }
|
| @@ -307,6 +299,55 @@ UnlinkedParamBuilder _serializeSyntheticParam(
|
| }
|
|
|
| /**
|
| + * Create an [UnlinkedTypeParamBuilder] representing the given [typeParameter],
|
| + * which should be a type parameter of a synthetic function type (e.g. one
|
| + * produced during type inference as a result of computing the least upper
|
| + * bound of two function types).
|
| + */
|
| +UnlinkedTypeParamBuilder _serializeSyntheticTypeParameter(
|
| + TypeParameterElement typeParameter,
|
| + CompilationUnitElementInBuildUnit compilationUnit,
|
| + TypeParameterizedElementMixin typeParameterContext) {
|
| + TypeParameterElementImpl impl = typeParameter as TypeParameterElementImpl;
|
| + EntityRefBuilder boundBuilder = typeParameter.bound != null
|
| + ? _createLinkedType(
|
| + typeParameter.bound, compilationUnit, typeParameterContext)
|
| + : null;
|
| + CodeRangeBuilder codeRangeBuilder =
|
| + new CodeRangeBuilder(offset: impl.codeOffset, length: impl.codeLength);
|
| + return new UnlinkedTypeParamBuilder(
|
| + name: typeParameter.name,
|
| + nameOffset: typeParameter.nameOffset,
|
| + bound: boundBuilder,
|
| + codeRange: codeRangeBuilder);
|
| +}
|
| +
|
| +/**
|
| + * Store the given function [element] into the [entity] by value.
|
| + */
|
| +void _storeFunctionElementByValue(
|
| + EntityRefBuilder entity,
|
| + FunctionElement element,
|
| + CompilationUnitElementInBuildUnit compilationUnit) {
|
| + // Element is a local function, or a synthetic function element that was
|
| + // generated on the fly to represent a type that has no associated source
|
| + // code location. Store it as value.
|
| + if (element is FunctionElementImpl) {
|
| + entity.syntheticReturnType =
|
| + _createLinkedType(element.returnType, compilationUnit, element);
|
| + entity.entityKind = EntityRefKind.syntheticFunction;
|
| + entity.syntheticParams = element.parameters
|
| + .map((ParameterElement param) =>
|
| + _serializeSyntheticParam(param, compilationUnit, element))
|
| + .toList();
|
| + entity.typeParameters = element.typeParameters
|
| + .map((TypeParameterElement e) =>
|
| + _serializeSyntheticTypeParameter(e, compilationUnit, element))
|
| + .toList();
|
| + }
|
| +}
|
| +
|
| +/**
|
| * Store the given [typeArguments] in [encodedType], using [compilationUnit] and
|
| * [typeParameterContext] to serialize them.
|
| */
|
| @@ -1103,7 +1144,11 @@ abstract class CompilationUnitElementForLink
|
| .getTypeParameterType(entity.paramReference);
|
| } else if (entity.entityKind == EntityRefKind.genericFunctionType) {
|
| return new GenericFunctionTypeElementForLink(this, context, entity).type;
|
| - } else if (entity.syntheticReturnType != null) {
|
| + } else if (entity.syntheticReturnType != null && entity.reference == 0) {
|
| + // TODO(scheglov): Remove "&& entity.reference == 0" condition after
|
| + // rolling SDK with this change internally, so that we always store
|
| + // synthetic and local function types by value.
|
| +
|
| // TODO(paulberry): implement.
|
| throw new UnimplementedError();
|
| } else if (entity.implicitFunctionTypeIndices.isNotEmpty) {
|
| @@ -2881,6 +2926,9 @@ class FunctionElementForLink_FunctionTypedParam extends Object
|
| DartType _returnType;
|
| List<int> _implicitFunctionTypeIndices;
|
|
|
| + @override
|
| + bool get isSynthetic => true;
|
| +
|
| FunctionElementForLink_FunctionTypedParam(this.enclosingElement,
|
| this.typeParameterContext, this.unlinkedParameters);
|
|
|
|
|