| Index: pkg/analyzer/lib/src/summary/summarize_const_expr.dart
|
| diff --git a/pkg/analyzer/lib/src/summary/summarize_const_expr.dart b/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
|
| index def774ad9858df6a56aa379d34b20335f9587f7d..6212f5d5d76e1f505e2872f71143f16807e545e7 100644
|
| --- a/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
|
| +++ b/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
|
| @@ -69,6 +69,16 @@ UnlinkedConstructorInitializer serializeConstructorInitializer(
|
| */
|
| abstract class AbstractConstExprSerializer {
|
| /**
|
| + * Whether an expression that should be a constant is being serialized.
|
| + *
|
| + * For constants we need to store more than we need just for type inference,
|
| + * because we need to be able to restore these AST to evaluate actual values
|
| + * of constants. So, we need to store constructor arguments, elements for
|
| + * list and map literals even if these literals are typed.
|
| + */
|
| + final bool forConst;
|
| +
|
| + /**
|
| * See [UnlinkedExprBuilder.isValidConst].
|
| */
|
| bool isValidConst = true;
|
| @@ -109,6 +119,8 @@ abstract class AbstractConstExprSerializer {
|
| */
|
| final List<EntityRefBuilder> references = <EntityRefBuilder>[];
|
|
|
| + AbstractConstExprSerializer(this.forConst);
|
| +
|
| /**
|
| * Return `true` if the given [name] is a parameter reference.
|
| */
|
| @@ -413,21 +425,26 @@ abstract class AbstractConstExprSerializer {
|
| }
|
|
|
| void _serializeArguments(ArgumentList argumentList) {
|
| - List<Expression> arguments = argumentList.arguments;
|
| - // Serialize the arguments.
|
| - List<String> argumentNames = <String>[];
|
| - arguments.forEach((arg) {
|
| - if (arg is NamedExpression) {
|
| - argumentNames.add(arg.name.label.name);
|
| - _serialize(arg.expression);
|
| - } else {
|
| - _serialize(arg);
|
| - }
|
| - });
|
| - // Add numbers of named and positional arguments, and the op-code.
|
| - ints.add(argumentNames.length);
|
| - strings.addAll(argumentNames);
|
| - ints.add(arguments.length - argumentNames.length);
|
| + if (forConst) {
|
| + List<Expression> arguments = argumentList.arguments;
|
| + // Serialize the arguments.
|
| + List<String> argumentNames = <String>[];
|
| + arguments.forEach((arg) {
|
| + if (arg is NamedExpression) {
|
| + argumentNames.add(arg.name.label.name);
|
| + _serialize(arg.expression);
|
| + } else {
|
| + _serialize(arg);
|
| + }
|
| + });
|
| + // Add numbers of named and positional arguments, and the op-code.
|
| + ints.add(argumentNames.length);
|
| + strings.addAll(argumentNames);
|
| + ints.add(arguments.length - argumentNames.length);
|
| + } else {
|
| + ints.add(0);
|
| + ints.add(0);
|
| + }
|
| }
|
|
|
| void _serializeAssignment(AssignmentExpression expr) {
|
| @@ -521,9 +538,13 @@ abstract class AbstractConstExprSerializer {
|
| }
|
|
|
| void _serializeListLiteral(ListLiteral expr) {
|
| - List<Expression> elements = expr.elements;
|
| - elements.forEach(_serialize);
|
| - ints.add(elements.length);
|
| + if (forConst || expr.typeArguments == null) {
|
| + List<Expression> elements = expr.elements;
|
| + elements.forEach(_serialize);
|
| + ints.add(elements.length);
|
| + } else {
|
| + ints.add(0);
|
| + }
|
| if (expr.typeArguments != null &&
|
| expr.typeArguments.arguments.length == 1) {
|
| references.add(serializeTypeName(expr.typeArguments.arguments[0]));
|
| @@ -534,11 +555,15 @@ abstract class AbstractConstExprSerializer {
|
| }
|
|
|
| void _serializeMapLiteral(MapLiteral expr) {
|
| - for (MapLiteralEntry entry in expr.entries) {
|
| - _serialize(entry.key);
|
| - _serialize(entry.value);
|
| + if (forConst || expr.typeArguments == null) {
|
| + for (MapLiteralEntry entry in expr.entries) {
|
| + _serialize(entry.key);
|
| + _serialize(entry.value);
|
| + }
|
| + ints.add(expr.entries.length);
|
| + } else {
|
| + ints.add(0);
|
| }
|
| - ints.add(expr.entries.length);
|
| if (expr.typeArguments != null &&
|
| expr.typeArguments.arguments.length == 2) {
|
| references.add(serializeTypeName(expr.typeArguments.arguments[0]));
|
|
|