Index: pkg/analyzer/lib/src/generated/resolver.dart |
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart |
index a009cde3fe705736e4d5f691fb2a8546948df3d2..2bb7b178458652486a914dee54f1621f39d9e919 100644 |
--- a/pkg/analyzer/lib/src/generated/resolver.dart |
+++ b/pkg/analyzer/lib/src/generated/resolver.dart |
@@ -5784,8 +5784,7 @@ class ResolverVisitor extends ScopedVisitor { |
} |
// Clone the ASTs for default formal parameters, so that we can use them |
// during constant evaluation. |
- if (!LibraryElementImpl.hasResolutionCapability( |
- definingLibrary, LibraryResolutionCapability.constantExpressions)) { |
+ if (!_hasSerializedConstantInitializer(element)) { |
(element as ConstVariableElement).constantInitializer = |
new ConstantAstCloner().cloneNode(node.defaultValue); |
} |
@@ -6643,6 +6642,25 @@ class ResolverVisitor extends ScopedVisitor { |
return null; |
} |
+ /** |
+ * Return `true` if the given [parameter] element of the AST being resolved |
+ * is resynthesized and is an API-level, not local, so has its initializer |
+ * serialized. |
+ */ |
+ bool _hasSerializedConstantInitializer(ParameterElement parameter) { |
+ if (LibraryElementImpl.hasResolutionCapability( |
+ definingLibrary, LibraryResolutionCapability.constantExpressions)) { |
+ Element executable = parameter.enclosingElement; |
+ if (executable is MethodElement) { |
+ return true; |
+ } |
+ if (executable is FunctionElement) { |
+ return executable.enclosingElement is CompilationUnitElement; |
+ } |
+ } |
+ return false; |
+ } |
+ |
void _inferArgumentTypesFromContext(InvocationExpression node) { |
if (!strongMode) { |
// Use propagated type inference for lambdas if not in strong mode. |