OLD | NEW |
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 engine.resolver; | 5 library engine.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'ast.dart'; | 9 import 'ast.dart'; |
10 import 'constant.dart'; | 10 import 'constant.dart'; |
(...skipping 10688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10699 // of the statement. | 10699 // of the statement. |
10700 // | 10700 // |
10701 node.accept(elementResolver); | 10701 node.accept(elementResolver); |
10702 node.accept(typeAnalyzer); | 10702 node.accept(typeAnalyzer); |
10703 return null; | 10703 return null; |
10704 } | 10704 } |
10705 | 10705 |
10706 @override | 10706 @override |
10707 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 10707 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
10708 super.visitDefaultFormalParameter(node); | 10708 super.visitDefaultFormalParameter(node); |
| 10709 ParameterElement element = node.element; |
| 10710 if (element.initializer != null && node.defaultValue != null) { |
| 10711 (element.initializer as FunctionElementImpl).returnType = |
| 10712 node.defaultValue.staticType; |
| 10713 } |
10709 FormalParameterList parent = node.parent; | 10714 FormalParameterList parent = node.parent; |
10710 AstNode grandparent = parent.parent; | 10715 AstNode grandparent = parent.parent; |
10711 if (grandparent is ConstructorDeclaration && | 10716 if (grandparent is ConstructorDeclaration && |
10712 grandparent.constKeyword != null) { | 10717 grandparent.constKeyword != null) { |
10713 // For const constructors, we need to clone the ASTs for default formal | 10718 // For const constructors, we need to clone the ASTs for default formal |
10714 // parameters, so that we can use them during constant evaluation. | 10719 // parameters, so that we can use them during constant evaluation. |
10715 ParameterElement element = node.element; | 10720 ParameterElement element = node.element; |
10716 (element as ConstVariableElement).constantInitializer = | 10721 (element as ConstVariableElement).constantInitializer = |
10717 new ConstantAstCloner().cloneNode(node.defaultValue); | 10722 new ConstantAstCloner().cloneNode(node.defaultValue); |
10718 } | 10723 } |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11124 return null; | 11129 return null; |
11125 } | 11130 } |
11126 | 11131 |
11127 @override | 11132 @override |
11128 Object visitTypeName(TypeName node) => null; | 11133 Object visitTypeName(TypeName node) => null; |
11129 | 11134 |
11130 @override | 11135 @override |
11131 Object visitVariableDeclaration(VariableDeclaration node) { | 11136 Object visitVariableDeclaration(VariableDeclaration node) { |
11132 super.visitVariableDeclaration(node); | 11137 super.visitVariableDeclaration(node); |
11133 VariableElement element = node.element; | 11138 VariableElement element = node.element; |
| 11139 if (element.initializer != null && node.initializer != null) { |
| 11140 (element.initializer as FunctionElementImpl).returnType = |
| 11141 node.initializer.staticType; |
| 11142 } |
11134 // Note: in addition to cloning the initializers for const variables, we | 11143 // Note: in addition to cloning the initializers for const variables, we |
11135 // have to clone the initializers for non-static final fields (because if | 11144 // have to clone the initializers for non-static final fields (because if |
11136 // they occur in a class with a const constructor, they will be needed to | 11145 // they occur in a class with a const constructor, they will be needed to |
11137 // evaluate the const constructor). | 11146 // evaluate the const constructor). |
11138 if ((element.isConst || | 11147 if ((element.isConst || |
11139 (element is FieldElement && | 11148 (element is FieldElement && |
11140 element.isFinal && | 11149 element.isFinal && |
11141 !element.isStatic)) && | 11150 !element.isStatic)) && |
11142 node.initializer != null) { | 11151 node.initializer != null) { |
11143 (element as ConstVariableElement).constantInitializer = | 11152 (element as ConstVariableElement).constantInitializer = |
(...skipping 4179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15323 nonFields.add(node); | 15332 nonFields.add(node); |
15324 return null; | 15333 return null; |
15325 } | 15334 } |
15326 | 15335 |
15327 @override | 15336 @override |
15328 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15337 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
15329 | 15338 |
15330 @override | 15339 @override |
15331 Object visitWithClause(WithClause node) => null; | 15340 Object visitWithClause(WithClause node) => null; |
15332 } | 15341 } |
OLD | NEW |