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

Unified Diff: lib/compiler/implementation/compile_time_constants.dart

Issue 10908143: Support check mode for statics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | lib/compiler/implementation/constants.dart » ('j') | tests/language/language_dart2js.status » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/compile_time_constants.dart
===================================================================
--- lib/compiler/implementation/compile_time_constants.dart (revision 12037)
+++ lib/compiler/implementation/compile_time_constants.dart (working copy)
@@ -125,11 +125,24 @@
Node right = assignment.arguments.head;
value =
compileNodeWithDefinitions(right, definitions, isConst: isConst);
+ if (compiler.enableTypeAssertions
+ && value != null
+ && element.isField()) {
+ DartType elementType = element.computeType(compiler);
+ DartType constantType = value.computeType(compiler);
+ if (!compiler.types.isSubtype(constantType, elementType)) {
+ // If the type of the constant does not implement the
+ // declared type of the variable, we make the initialization
+ // of this variable lazy so that at runtime we get the type
+ // error only if the variable is used.
+ value = null;
+ }
+ }
}
if (value != null) {
initialVariableValues[element] = value;
} else {
- assert(!isConst);
+ assert(!isConst || compiler.enableTypeAssertions);
lazyStatics.add(element);
}
pendingVariables.remove(element);
@@ -273,8 +286,8 @@
link = link.tail) {
arguments.add(evaluateConstant(link.head));
}
- // TODO(floitsch): get type from somewhere.
- DartType type = null;
+ // TODO(floitsch): get type parameters.
+ DartType type = new InterfaceType(compiler.listClass);
Constant constant = new ListConstant(type, arguments);
compiler.constantHandler.registerCompileTimeConstant(constant);
return constant;
@@ -311,7 +324,7 @@
}
bool hasProtoKey = (protoValue !== null);
// TODO(floitsch): this should be a List<String> type.
- DartType keysType = null;
+ DartType keysType = new InterfaceType(compiler.listClass);
ListConstant keysList = new ListConstant(keysType, keys);
compiler.constantHandler.registerCompileTimeConstant(keysList);
SourceString className = hasProtoKey
« no previous file with comments | « no previous file | lib/compiler/implementation/constants.dart » ('j') | tests/language/language_dart2js.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698