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

Unified Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 1182663008: Typecheck const classes in the context of the constructor call. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/compile_time_constants.dart
diff --git a/pkg/compiler/lib/src/compile_time_constants.dart b/pkg/compiler/lib/src/compile_time_constants.dart
index b0c750267c7e3cb0fce9e5557088d6de2625e94b..4eb09a19ea262dc420ddab97690022ebf424290d 100644
--- a/pkg/compiler/lib/src/compile_time_constants.dart
+++ b/pkg/compiler/lib/src/compile_time_constants.dart
@@ -153,12 +153,14 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
return initialVariableValues[element.declaration];
}
- ConstantExpression compileConstant(VariableElement element) {
- return compileVariable(element, isConst: true);
+ ConstantExpression compileConstant(VariableElement element,
+ {bool checkType: true}) {
Johnni Winther 2015/06/17 06:56:29 This method overrides ConstantCompiler.compileCons
Harry Terkelsen 2015/08/10 23:49:34 Done.
+ return compileVariable(element, isConst: true, checkType: checkType);
}
ConstantExpression compileVariable(VariableElement element,
- {bool isConst: false}) {
+ {bool isConst: false,
+ bool checkType: true}) {
Johnni Winther 2015/06/17 06:56:29 Ditto.
Harry Terkelsen 2015/08/10 23:49:34 Done.
if (initialVariableValues.containsKey(element.declaration)) {
ConstantExpression result = initialVariableValues[element.declaration];
@@ -170,7 +172,8 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
_analyzeElementEagerly(compiler, currentElement);
ConstantExpression constant = compileVariableWithDefinitions(
- element, currentElement.resolvedAst.elements, isConst: isConst);
+ element, currentElement.resolvedAst.elements, isConst: isConst,
+ checkType: checkType);
return constant;
});
}
@@ -183,7 +186,8 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
*/
ConstantExpression compileVariableWithDefinitions(VariableElement element,
TreeElements definitions,
- {bool isConst: false}) {
+ {bool isConst: false,
+ bool checkType: true}) {
Node node = element.node;
if (pendingVariables.contains(element)) {
if (isConst) {
@@ -207,6 +211,7 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
expression = compileNodeWithDefinitions(
initializer, definitions, isConst: isConst);
if (compiler.enableTypeAssertions &&
+ checkType &&
expression != null &&
element.isField) {
DartType elementType = element.type;
@@ -1121,8 +1126,7 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
return super.visitSend(send);
}
- void potentiallyCheckType(Node node,
- TypedElement element,
+ void potentiallyCheckType(TypedElement element,
AstConstant constant) {
if (compiler.enableTypeAssertions) {
DartType elementType = element.type.substByContext(constructedType);
@@ -1141,7 +1145,7 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
void updateFieldValue(Node node,
TypedElement element,
AstConstant constant) {
- potentiallyCheckType(node, element, constant);
+ potentiallyCheckType(element, constant);
fieldValues[element] = constant;
}
@@ -1162,7 +1166,7 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
InitializingFormalElement initializingFormal = parameter;
updateFieldValue(node, initializingFormal.fieldElement, argument);
} else {
- potentiallyCheckType(node, parameter, argument);
+ potentiallyCheckType(parameter, argument);
definitions[parameter] = argument;
}
});
@@ -1279,11 +1283,13 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
AstConstant fieldValue = fieldValues[field];
if (fieldValue == null) {
// Use the default value.
- ConstantExpression fieldExpression = handler.compileConstant(field);
+ ConstantExpression fieldExpression =
+ handler.compileConstant(field, checkType: false);
fieldValue = new AstConstant.fromDefaultValue(
field,
fieldExpression,
handler.getConstantValue(fieldExpression));
+ potentiallyCheckType(field, fieldValue);
}
fieldConstants[field] = fieldValue;
},

Powered by Google App Engine
This is Rietveld 408576698