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.constant; | 5 library engine.constant; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/utilities_general.dart'; | 10 import 'package:analyzer/src/generated/utilities_general.dart'; |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 } | 697 } |
698 HashMap<String, DartObjectImpl> fieldMap = | 698 HashMap<String, DartObjectImpl> fieldMap = |
699 new HashMap<String, DartObjectImpl>(); | 699 new HashMap<String, DartObjectImpl>(); |
700 // Start with final fields that are initialized at their declaration site. | 700 // Start with final fields that are initialized at their declaration site. |
701 for (FieldElement field in constructor.enclosingElement.fields) { | 701 for (FieldElement field in constructor.enclosingElement.fields) { |
702 if ((field.isFinal || field.isConst) && | 702 if ((field.isFinal || field.isConst) && |
703 !field.isStatic && | 703 !field.isStatic && |
704 field is ConstFieldElementImpl) { | 704 field is ConstFieldElementImpl) { |
705 validator.beforeGetFieldEvaluationResult(field); | 705 validator.beforeGetFieldEvaluationResult(field); |
706 EvaluationResultImpl evaluationResult = field.evaluationResult; | 706 EvaluationResultImpl evaluationResult = field.evaluationResult; |
| 707 // It is possible that the evaluation result is null. |
| 708 // This happens for example when we have duplicate fields. |
| 709 // class Test {final x = 1; final x = 2; const Test();} |
| 710 if (evaluationResult == null) { |
| 711 continue; |
| 712 } |
| 713 // Match the value and the type. |
707 DartType fieldType = | 714 DartType fieldType = |
708 FieldMember.from(field, constructor.returnType).type; | 715 FieldMember.from(field, constructor.returnType).type; |
709 DartObjectImpl fieldValue = evaluationResult.value; | 716 DartObjectImpl fieldValue = evaluationResult.value; |
710 if (fieldValue != null && !runtimeTypeMatch(fieldValue, fieldType)) { | 717 if (fieldValue != null && !runtimeTypeMatch(fieldValue, fieldType)) { |
711 errorReporter.reportErrorForNode( | 718 errorReporter.reportErrorForNode( |
712 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA
TCH, | 719 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA
TCH, |
713 node, | 720 node, |
714 [fieldValue.type, field.name, fieldType]); | 721 [fieldValue.type, field.name, fieldType]); |
715 } | 722 } |
716 fieldMap[field.name] = evaluationResult.value; | 723 fieldMap[field.name] = fieldValue; |
717 } | 724 } |
718 } | 725 } |
719 // Now evaluate the constructor declaration. | 726 // Now evaluate the constructor declaration. |
720 HashMap<String, DartObjectImpl> parameterMap = | 727 HashMap<String, DartObjectImpl> parameterMap = |
721 new HashMap<String, DartObjectImpl>(); | 728 new HashMap<String, DartObjectImpl>(); |
722 List<ParameterElement> parameters = constructor.parameters; | 729 List<ParameterElement> parameters = constructor.parameters; |
723 int parameterCount = parameters.length; | 730 int parameterCount = parameters.length; |
724 for (int i = 0; i < parameterCount; i++) { | 731 for (int i = 0; i < parameterCount; i++) { |
725 ParameterElement parameter = parameters[i]; | 732 ParameterElement parameter = parameters[i]; |
726 ParameterElement baseParameter = parameter; | 733 ParameterElement baseParameter = parameter; |
(...skipping 4833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5560 return BoolState.from(_element == rightElement); | 5567 return BoolState.from(_element == rightElement); |
5561 } else if (rightOperand is DynamicState) { | 5568 } else if (rightOperand is DynamicState) { |
5562 return BoolState.UNKNOWN_VALUE; | 5569 return BoolState.UNKNOWN_VALUE; |
5563 } | 5570 } |
5564 return BoolState.FALSE_STATE; | 5571 return BoolState.FALSE_STATE; |
5565 } | 5572 } |
5566 | 5573 |
5567 @override | 5574 @override |
5568 String toString() => _element == null ? "-unknown-" : _element.name; | 5575 String toString() => _element == null ? "-unknown-" : _element.name; |
5569 } | 5576 } |
OLD | NEW |