aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/LValue.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/LValue.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/LValue.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LValue.java b/src/main/java/com/google/devtools/build/lib/syntax/LValue.java
index 729dd0c160..1f031d9cc2 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LValue.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LValue.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.syntax;
import static com.google.devtools.build.lib.syntax.compiler.ByteCodeUtils.append;
+import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.syntax.compiler.ByteCodeUtils;
import com.google.devtools.build.lib.syntax.compiler.DebugInfo.AstAccessors;
@@ -31,7 +32,9 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
/**
* Class representing an LValue.
@@ -103,20 +106,23 @@ public class LValue implements Serializable {
// Since dict is still immutable, the expression 'a[x] = b' creates a new dictionary and
// assigns it to 'a'.
- @SuppressWarnings("unchecked")
+ // TODO(bazel-team): make dict mutable - this function should be O(1) instead of O(n).
private static void assignItem(
Environment env, Location loc, Identifier ident, Object key, Object value)
throws EvalException, InterruptedException {
Object o = ident.eval(env);
- if (!(o instanceof SkylarkDict)) {
+ if (!(o instanceof Map)) {
throw new EvalException(
loc,
"can only assign an element in a dictionary, not in a '"
+ EvalUtils.getDataTypeName(o)
+ "'");
}
- SkylarkDict<Object, Object> dict = (SkylarkDict<Object, Object>) o;
- dict.put(key, value, loc, env);
+ Map<?, ?> dict = (Map<?, ?>) o;
+ Map<Object, Object> result = new LinkedHashMap<>(dict.size() + 1);
+ result.putAll(dict);
+ result.put(key, value);
+ env.update(ident.getName(), ImmutableMap.copyOf(result));
}
/**