| 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 analyzer.src.dart.constant.evaluation; | 5 library analyzer.src.dart.constant.evaluation; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/context/declared_variables.dart'; | 9 import 'package:analyzer/context/declared_variables.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 702 } |
| 703 ConstantVisitor initializerVisitor = new ConstantVisitor( | 703 ConstantVisitor initializerVisitor = new ConstantVisitor( |
| 704 this, externalErrorReporter, | 704 this, externalErrorReporter, |
| 705 lexicalEnvironment: parameterMap); | 705 lexicalEnvironment: parameterMap); |
| 706 String superName = null; | 706 String superName = null; |
| 707 NodeList<Expression> superArguments = null; | 707 NodeList<Expression> superArguments = null; |
| 708 for (ConstructorInitializer initializer in initializers) { | 708 for (ConstructorInitializer initializer in initializers) { |
| 709 if (initializer is ConstructorFieldInitializer) { | 709 if (initializer is ConstructorFieldInitializer) { |
| 710 Expression initializerExpression = initializer.expression; | 710 Expression initializerExpression = initializer.expression; |
| 711 DartObjectImpl evaluationResult = | 711 DartObjectImpl evaluationResult = |
| 712 initializerExpression.accept(initializerVisitor); | 712 initializerExpression?.accept(initializerVisitor); |
| 713 if (evaluationResult != null) { | 713 if (evaluationResult != null) { |
| 714 String fieldName = initializer.fieldName.name; | 714 String fieldName = initializer.fieldName.name; |
| 715 if (fieldMap.containsKey(fieldName)) { | 715 if (fieldMap.containsKey(fieldName)) { |
| 716 errorReporter.reportErrorForNode( | 716 errorReporter.reportErrorForNode( |
| 717 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); | 717 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); |
| 718 } | 718 } |
| 719 fieldMap[fieldName] = evaluationResult; | 719 fieldMap[fieldName] = evaluationResult; |
| 720 PropertyAccessorElement getter = definingClass.getGetter(fieldName); | 720 PropertyAccessorElement getter = definingClass.getGetter(fieldName); |
| 721 if (getter != null) { | 721 if (getter != null) { |
| 722 PropertyInducingElement field = getter.variable; | 722 PropertyInducingElement field = getter.variable; |
| 723 if (!runtimeTypeMatch(evaluationResult, field.type)) { | 723 if (!runtimeTypeMatch(evaluationResult, field.type)) { |
| 724 errorReporter.reportErrorForNode( | 724 errorReporter.reportErrorForNode( |
| 725 CheckedModeCompileTimeErrorCode | 725 CheckedModeCompileTimeErrorCode |
| 726 .CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, | 726 .CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
| 727 node, | 727 node, |
| 728 [evaluationResult.type, fieldName, field.type]); | 728 [evaluationResult.type, fieldName, field.type]); |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 } else { |
| 732 errorReporter.reportErrorForNode( |
| 733 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); |
| 731 } | 734 } |
| 732 } else if (initializer is SuperConstructorInvocation) { | 735 } else if (initializer is SuperConstructorInvocation) { |
| 733 SimpleIdentifier name = initializer.constructorName; | 736 SimpleIdentifier name = initializer.constructorName; |
| 734 if (name != null) { | 737 if (name != null) { |
| 735 superName = name.name; | 738 superName = name.name; |
| 736 } | 739 } |
| 737 superArguments = initializer.argumentList.arguments; | 740 superArguments = initializer.argumentList.arguments; |
| 738 } else if (initializer is RedirectingConstructorInvocation) { | 741 } else if (initializer is RedirectingConstructorInvocation) { |
| 739 // This is a redirecting constructor, so just evaluate the constructor | 742 // This is a redirecting constructor, so just evaluate the constructor |
| 740 // it redirects to. | 743 // it redirects to. |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 } | 2133 } |
| 2131 | 2134 |
| 2132 @override | 2135 @override |
| 2133 String toString() { | 2136 String toString() { |
| 2134 if (value == null) { | 2137 if (value == null) { |
| 2135 return "error"; | 2138 return "error"; |
| 2136 } | 2139 } |
| 2137 return value.toString(); | 2140 return value.toString(); |
| 2138 } | 2141 } |
| 2139 } | 2142 } |
| OLD | NEW |