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

Unified Diff: tools/gn/operators.cc

Issue 136723008: Remove some appending behavior from GN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | tools/gn/operators_unittest.cc » ('j') | tools/gn/operators_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/operators.cc
diff --git a/tools/gn/operators.cc b/tools/gn/operators.cc
index 94180130c67534be04ba207c91fe5796c015d787..62e0c57bad5e8b97bc6d3998d1640372e3b1f42f 100644
--- a/tools/gn/operators.cc
+++ b/tools/gn/operators.cc
@@ -103,44 +103,27 @@ Value ExecuteEquals(Scope* scope,
Err* err) {
const Value* old_value = scope->GetValue(left.value(), false);
if (old_value) {
- if (scope->IsSetButUnused(left.value())) {
- // Throw an error for re-assigning without using the value first. The
- // exception is that you can overwrite an empty list with another list
- // since this is the way to get around the "can't overwrite a nonempty
- // list with another nonempty list" restriction.
- if (old_value->type() != Value::LIST ||
- !old_value->list_value().empty()) {
- *err = Err(op_node->left()->GetRange(), "Overwriting unused variable.",
- "This overwrites a previous assignment to \"" +
- left.value().as_string() + "\" that had no effect.");
- err->AppendSubErr(Err(*scope->GetValue(left.value()),
- "Previously set here.",
- "Maybe you wanted \"+=\" to append instead?"));
- return Value();
- }
- } else {
- // Throw an error when overwriting a nonempty list with another nonempty
- // list item. This is to detect the case where you write
- // defines = ["FOO"]
- // and you overwrote inherited ones, when instead you mean to append:
- // defines += ["FOO"]
- if (old_value->type() == Value::LIST &&
- !old_value->list_value().empty() &&
- right.type() == Value::LIST &&
- !right.list_value().empty()) {
- *err = Err(op_node->left()->GetRange(), "Replacing nonempty list.",
- std::string("This overwrites a previously-defined nonempty list ") +
- "(length " +
- base::IntToString(static_cast<int>(old_value->list_value().size()))
- + ").");
- err->AppendSubErr(Err(*old_value, "for previous definition",
- "with another one (length " +
- base::IntToString(static_cast<int>(right.list_value().size())) +
- "). Did you mean " +
- "\"+=\" to append instead? If you\nreally want to do this, do\n " +
- left.value().as_string() + " = []\nbefore reassigning."));
- return Value();
- }
+ // Throw an error when overwriting a nonempty list with another nonempty
+ // list item. This is to detect the case where you write
+ // defines = ["FOO"]
+ // and you overwrote inherited ones, when instead you mean to append:
+ // defines += ["FOO"]
+ if (old_value->type() == Value::LIST &&
+ !old_value->list_value().empty() &&
+ right.type() == Value::LIST &&
+ !right.list_value().empty()) {
+ *err = Err(op_node->left()->GetRange(), "Replacing nonempty list.",
+ std::string("This overwrites a previously-defined nonempty list ") +
+ "(length " +
+ base::IntToString(static_cast<int>(old_value->list_value().size()))
+ + ").");
+ err->AppendSubErr(Err(*old_value, "for previous definition",
+ "with another one (length " +
+ base::IntToString(static_cast<int>(right.list_value().size())) +
+ "). Did you mean " +
+ "\"+=\" to append instead? If you\nreally want to do this, do\n " +
+ left.value().as_string() + " = []\nbefore reassigning."));
+ return Value();
}
}
if (err->has_error())
@@ -210,14 +193,6 @@ void ValuePlusEquals(const Scope* scope,
// Left-hand-side list.
case Value::LIST:
switch (right.type()) {
- case Value::INTEGER: // list + integer -> list append.
- case Value::STRING: // list + string -> list append.
- if (left_token.value() == kSourcesName)
- AppendFilteredSourcesToValue(scope, right, left);
- else
- left->list_value().push_back(right);
- return;
-
case Value::LIST: // list + list -> list concat.
if (left_token.value() == kSourcesName) {
// Filter additions through the assignment filter.
@@ -230,7 +205,9 @@ void ValuePlusEquals(const Scope* scope,
return;
default:
- break;
+ *err = Err(op_node->op(), "Incompatible types to add.",
+ "To append a single item to a list do \"foo += [ bar ]\".");
+ return;
}
default:
@@ -286,7 +263,12 @@ void ValueMinusEquals(const BinaryOpNode* op_node,
// Left-hand-side list.
case Value::LIST:
- RemoveMatchesFromList(op_node, left, right, err);
+ if (!right.type() != Value::LIST) {
scottmg 2014/01/15 00:32:07 is !right.type() what you meant?
+ *err = Err(op_node->op(), "Incompatible types to subtract.",
+ "To remove a single item from a list do \"foo -= [ bar ]\".");
+ } else {
+ RemoveMatchesFromList(op_node, left, right, err);
+ }
return;
default:
« no previous file with comments | « no previous file | tools/gn/operators_unittest.cc » ('j') | tools/gn/operators_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698