Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
| =================================================================== |
| --- sdk/lib/_internal/compiler/implementation/compile_time_constants.dart (revision 29517) |
| +++ sdk/lib/_internal/compiler/implementation/compile_time_constants.dart (working copy) |
| @@ -634,7 +634,73 @@ |
| return evaluateArgumentsToConstructor( |
| node, selector, send.arguments, constructor); |
| } |
| - return makeConstructedConstant(node, type, constructor, evaluateArguments); |
| + |
| + if (constructor == compiler.intEnvironment |
| + || constructor == compiler.boolEnvironment |
| + || constructor == compiler.stringEnvironment) { |
| + List<Constant> arguments = evaluateArguments(constructor); |
| + var firstArgument = arguments[0]; |
| + Constant defaultValue = arguments[1]; |
| + |
| + if (firstArgument is NullConstant) { |
| + compiler.reportFatalError( |
| + send.arguments.head, MessageKind.NULL_NOT_ALLOWED); |
| + } |
| + |
| + if (firstArgument is! StringConstant) { |
| + DartType type = defaultValue.computeType(compiler); |
| + compiler.reportFatalError( |
| + send.arguments.head, MessageKind.NOT_ASSIGNABLE.error, |
| + {'fromType': type, 'toType': compiler.stringClass.rawType}); |
| + } |
| + |
| + if (constructor == compiler.intEnvironment |
| + && !(defaultValue is NullConstant || defaultValue is IntConstant)) { |
| + DartType type = defaultValue.computeType(compiler); |
| + compiler.reportFatalError( |
| + send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error, |
| + {'fromType': type, 'toType': compiler.intClass.rawType}); |
| + } |
| + |
| + if (constructor == compiler.boolEnvironment |
| + && !(defaultValue is NullConstant || defaultValue is BoolConstant)) { |
| + DartType type = defaultValue.computeType(compiler); |
| + compiler.reportFatalError( |
| + send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error, |
| + {'fromType': type, 'toType': compiler.boolClass.rawType}); |
| + } |
| + |
| + if (constructor == compiler.stringEnvironment |
| + && !(defaultValue is NullConstant |
| + || defaultValue is StringConstant)) { |
| + DartType type = defaultValue.computeType(compiler); |
| + compiler.reportFatalError( |
| + send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error, |
| + {'fromType': type, 'toType': compiler.stringClass.rawType}); |
| + } |
| + |
| + String value = |
| + compiler.fromEnvironment(firstArgument.value.slowToString()); |
| + |
| + if (value == null) { |
| + return defaultValue; |
| + } else if (constructor == compiler.intEnvironment) { |
| + int number = int.parse(value, onError: (_) => null); |
|
Lasse Reichstein Nielsen
2013/10/31 06:58:20
It should be fine to just do:
return constantSys
ngeoffray
2013/10/31 07:41:18
Done.
|
| + return (number == null) |
|
Søren Gjesse
2013/10/30 15:21:49
Re-reading the specification non-parseable integer
Lasse Reichstein Nielsen
2013/10/31 06:58:20
I'm open to changing it. I was working on the assu
|
| + ? defaultValue |
| + : constantSystem.createInt(number); |
| + } else if (constructor == compiler.boolEnvironment) { |
| + return (value == 'true') |
| + ? constantSystem.createBool(true) |
| + : constantSystem.createBool(false); |
| + } else { |
| + assert(constructor == compiler.stringEnvironment); |
| + return constantSystem.createString(new DartString.literal(value), node); |
| + } |
| + } else { |
| + return makeConstructedConstant( |
| + node, type, constructor, evaluateArguments); |
| + } |
| } |
| Constant makeConstructedConstant( |