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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 5766 matching lines...) Expand 10 before | Expand all | Expand 10 after
5777 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 5777 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
5778 InferenceContext.setType(node.defaultValue, node.parameter.element?.type); 5778 InferenceContext.setType(node.defaultValue, node.parameter.element?.type);
5779 super.visitDefaultFormalParameter(node); 5779 super.visitDefaultFormalParameter(node);
5780 ParameterElement element = node.element; 5780 ParameterElement element = node.element;
5781 if (element.initializer != null && node.defaultValue != null) { 5781 if (element.initializer != null && node.defaultValue != null) {
5782 (element.initializer as FunctionElementImpl).returnType = 5782 (element.initializer as FunctionElementImpl).returnType =
5783 node.defaultValue.staticType; 5783 node.defaultValue.staticType;
5784 } 5784 }
5785 // Clone the ASTs for default formal parameters, so that we can use them 5785 // Clone the ASTs for default formal parameters, so that we can use them
5786 // during constant evaluation. 5786 // during constant evaluation.
5787 if (!LibraryElementImpl.hasResolutionCapability( 5787 if (!_hasSerializedConstantInitializer(element)) {
5788 definingLibrary, LibraryResolutionCapability.constantExpressions)) {
5789 (element as ConstVariableElement).constantInitializer = 5788 (element as ConstVariableElement).constantInitializer =
5790 new ConstantAstCloner().cloneNode(node.defaultValue); 5789 new ConstantAstCloner().cloneNode(node.defaultValue);
5791 } 5790 }
5792 return null; 5791 return null;
5793 } 5792 }
5794 5793
5795 @override 5794 @override
5796 Object visitDoStatement(DoStatement node) { 5795 Object visitDoStatement(DoStatement node) {
5797 _overrideManager.enterScope(); 5796 _overrideManager.enterScope();
5798 try { 5797 try {
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
6636 List<ParameterElement> onDataParameters = onDataType.parameters; 6635 List<ParameterElement> onDataParameters = onDataType.parameters;
6637 if (onDataParameters == null || onDataParameters.isEmpty) { 6636 if (onDataParameters == null || onDataParameters.isEmpty) {
6638 return null; 6637 return null;
6639 } 6638 }
6640 return onDataParameters[0].type; 6639 return onDataParameters[0].type;
6641 } 6640 }
6642 } 6641 }
6643 return null; 6642 return null;
6644 } 6643 }
6645 6644
6645 /**
6646 * Return `true` if the given [parameter] element of the AST being resolved
6647 * is resynthesized and is an API-level, not local, so has its initializer
6648 * serialized.
6649 */
6650 bool _hasSerializedConstantInitializer(ParameterElement parameter) {
6651 if (LibraryElementImpl.hasResolutionCapability(
6652 definingLibrary, LibraryResolutionCapability.constantExpressions)) {
6653 Element executable = parameter.enclosingElement;
6654 if (executable is MethodElement) {
6655 return true;
6656 }
6657 if (executable is FunctionElement) {
6658 return executable.enclosingElement is CompilationUnitElement;
6659 }
6660 }
6661 return false;
6662 }
6663
6646 void _inferArgumentTypesFromContext(InvocationExpression node) { 6664 void _inferArgumentTypesFromContext(InvocationExpression node) {
6647 if (!strongMode) { 6665 if (!strongMode) {
6648 // Use propagated type inference for lambdas if not in strong mode. 6666 // Use propagated type inference for lambdas if not in strong mode.
6649 _inferFunctionExpressionsParametersTypes(node.argumentList); 6667 _inferFunctionExpressionsParametersTypes(node.argumentList);
6650 return; 6668 return;
6651 } 6669 }
6652 6670
6653 DartType contextType = node.staticInvokeType; 6671 DartType contextType = node.staticInvokeType;
6654 if (contextType is FunctionType) { 6672 if (contextType is FunctionType) {
6655 DartType originalType = node.function.staticType; 6673 DartType originalType = node.function.staticType;
(...skipping 4083 matching lines...) Expand 10 before | Expand all | Expand 10 after
10739 return null; 10757 return null;
10740 } 10758 }
10741 if (identical(node.staticElement, variable)) { 10759 if (identical(node.staticElement, variable)) {
10742 if (node.inSetterContext()) { 10760 if (node.inSetterContext()) {
10743 result = true; 10761 result = true;
10744 } 10762 }
10745 } 10763 }
10746 return null; 10764 return null;
10747 } 10765 }
10748 } 10766 }
OLDNEW
« 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