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

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

Issue 195983006: Constrain constant references from deferred libraries (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 aeeae126786c4360188fb355c1fe781567ad5501..dc1ba56296c82576e30b05d0fec6c9904aab8ae6 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -411,10 +411,47 @@ class CompileTimeConstantEvaluator extends Visitor {
return new TypeConstant(elementType, constantType);
}
+ /// Returns true if the prefix of the send resolves to a deferred import
+ /// prefix.
+ bool isDeferredUse(Send send) {
+ // We handle:
+ // 1. Send(Send(Send(null, Prefix), className), staticName)
+ // 2. Send(Send(Prefix, Classname), staticName)
+ // 3. Send(Send(null, Prefix), staticName | className)
+ // 4. Send(Send(Prefix), staticName | className)
+ // Nodes of the forms 2,4 occur in metadata.
+ if (send == null) return false;
+ if (send.receiver is Send) {
floitsch 2014/03/12 16:48:13 Can't you just do a loop here? while (send.receive
+ send = send.receiver;
+ if (send.receiver is Send) {
+ send = send.receiver;
+ }
+ }
+ Identifier prefixNode;
+ if (send.receiver is Identifier) {
+ prefixNode = send.receiver;
+ } else if (send.receiver == null &&
+ send.selector is Identifier) {
+ prefixNode = send.selector;
+ }
+ if (prefixNode != null) {
+ Element maybePrefix = elements[prefixNode.asIdentifier()];
+ if (maybePrefix != null && maybePrefix.isPrefix() &&
+ (maybePrefix as PrefixElement).isDeferred) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// TODO(floitsch): provide better error-messages.
Constant visitSend(Send send) {
Element element = elements[send];
if (send.isPropertyAccess) {
+ if (isDeferredUse(send)) {
+ return signalNotCompileTimeConstant(send,
+ message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
+ }
if (Elements.isStaticOrTopLevelFunction(element)) {
return new FunctionConstant(element);
} else if (Elements.isStaticOrTopLevelField(element)) {
@@ -630,16 +667,9 @@ class CompileTimeConstantEvaluator extends Visitor {
// 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);
- }
- }
+ if (isDeferredUse(node.send.selector.asSend())) {
+ return signalNotCompileTimeConstant(node,
+ message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT_CONSTRUCTION);
}
// TODO(ahe): This is nasty: we must eagerly analyze the

Powered by Google App Engine
This is Rietveld 408576698