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

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

Issue 3000743002: Check for null constructor field initializer expression. (Closed)
Patch Set: Check for null in ConstantEvaluationEngine instead. 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 | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698