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

Side by Side Diff: pkg/analyzer/lib/src/dart/constant/evaluation.dart

Issue 2989193002: Prevent an exception (issue 30307) (Closed)
Patch Set: Created 3 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 List<FieldElement> fields = constructor.enclosingElement.fields; 584 List<FieldElement> fields = constructor.enclosingElement.fields;
585 for (int i = 0; i < fields.length; i++) { 585 for (int i = 0; i < fields.length; i++) {
586 FieldElement field = fields[i]; 586 FieldElement field = fields[i];
587 if ((field.isFinal || field.isConst) && 587 if ((field.isFinal || field.isConst) &&
588 !field.isStatic && 588 !field.isStatic &&
589 field is ConstFieldElementImpl) { 589 field is ConstFieldElementImpl) {
590 validator.beforeGetFieldEvaluationResult(field); 590 validator.beforeGetFieldEvaluationResult(field);
591 591
592 DartObjectImpl fieldValue; 592 DartObjectImpl fieldValue;
593 if (strongMode) { 593 if (strongMode) {
594 fieldValue = field.constantInitializer.accept(fieldInitVisitor); 594 fieldValue = field.constantInitializer?.accept(fieldInitVisitor);
595 } else { 595 } else {
596 fieldValue = field.evaluationResult?.value; 596 fieldValue = field.evaluationResult?.value;
597 } 597 }
598 // It is possible that the evaluation result is null. 598 // It is possible that the evaluation result is null.
599 // This happens for example when we have duplicate fields. 599 // This happens for example when we have duplicate fields.
600 // class Test {final x = 1; final x = 2; const Test();} 600 // class Test {final x = 1; final x = 2; const Test();}
601 if (fieldValue == null) { 601 if (fieldValue == null) {
602 continue; 602 continue;
603 } 603 }
604 // Match the value and the type. 604 // Match the value and the type.
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 } 2130 }
2131 2131
2132 @override 2132 @override
2133 String toString() { 2133 String toString() {
2134 if (value == null) { 2134 if (value == null) {
2135 return "error"; 2135 return "error";
2136 } 2136 }
2137 return value.toString(); 2137 return value.toString();
2138 } 2138 }
2139 } 2139 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698