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

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

Issue 183743031: Introduce constraints of deferred constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
index 1a57ccb93d2975cc7688b5ed89bb012874ad8439..5ab38e2a75e5ce84a6cf24776573969cbdce78d4 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -628,6 +628,21 @@ class CompileTimeConstantEvaluator extends Visitor {
if (Elements.isUnresolved(constructor)) {
return signalNotCompileTimeConstant(node);
}
+
+ // Deferred types can not be used in const instance creation expressions.
+ // Check if the constructor comes from a deferred library.
+ Send selectorSend = node.send.selector.asSend();
+ if (selectorSend != null) {
+ Identifier receiver = selectorSend.receiver.asIdentifier();
+ if (receiver != null) {
+ Element element = elements[receiver];
+ if (element.isPrefix() && (element as PrefixElement).isDeferred) {
+ return signalNotCompileTimeConstant(node,
+ message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
+ }
+ }
+ }
+
// TODO(ahe): This is nasty: we must eagerly analyze the
// constructor to ensure the redirectionTarget has been computed
// correctly. Find a way to avoid this.
@@ -739,16 +754,17 @@ class CompileTimeConstantEvaluator extends Visitor {
return node.expression.accept(this);
}
- error(Node node) {
+ error(Node node, MessageKind message) {
// TODO(floitsch): get the list of constants that are currently compiled
// and present some kind of stack-trace.
compiler.reportFatalError(
floitsch 2014/03/06 15:32:58 move on same line.
sigurdm 2014/03/07 12:50:49 Done.
- node, MessageKind.NOT_A_COMPILE_TIME_CONSTANT);
+ node, message);
}
- Constant signalNotCompileTimeConstant(Node node) {
+ Constant signalNotCompileTimeConstant(Node node,
+ {MessageKind message: MessageKind.NOT_A_COMPILE_TIME_CONSTANT}) {
if (isEvaluatingConstant) {
- error(node);
+ error(node, message);
}
// Else we don't need to do anything. The final handler is only
// optimistically trying to compile constants. So it is normal that we
@@ -765,10 +781,10 @@ class TryCompileTimeConstantEvaluator extends CompileTimeConstantEvaluator {
Compiler compiler)
: super(handler, elements, compiler, isConst: true);
- error(Node node) {
+ error(Node node, MessageKind message) {
// Just fail without reporting it anywhere.
throw new CompileTimeConstantError(
- MessageKind.NOT_A_COMPILE_TIME_CONSTANT, const {},
+ message, const {},
compiler.terseDiagnostics);
floitsch 2014/03/06 15:32:58 move one line up.
sigurdm 2014/03/07 12:50:49 Done.
}
}

Powered by Google App Engine
This is Rietveld 408576698