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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2489133002: Set initializer expressions for default values of parameters of local functions. (Closed)
Patch Set: Created 4 years, 1 month 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
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.
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698