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

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') | no next file with comments »
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 12170)
+++ lib/compiler/implementation/compile_time_constants.dart (working copy)
@@ -125,6 +125,23 @@
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 (isConst) {
+ MessageKind kind = MessageKind.NOT_ASSIGNABLE;
+ compiler.reportError(node, new CompileTimeConstantError(
+ kind, [elementType, constantType]));
+ } else {
+ // If the field can be lazily initialized, we will throw
+ // the exception at runtime.
+ value = null;
+ }
+ }
+ }
}
if (value != null) {
initialVariableValues[element] = value;
@@ -273,8 +290,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 +328,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698