Don't report error for non-existent keys in not_needed
This matches the behavior of forward_variables_from which also doesn't
fail for non-existent keys.
Change-Id: I6ca4a33f1b85a91662ee9bf3fa7a1b3a217c0cfa
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/6160
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Petr Hosek <phosek@google.com>
diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc
index 937ffd2..47d987c 100644
--- a/tools/gn/functions.cc
+++ b/tools/gn/functions.cc
@@ -778,10 +778,10 @@
for (const Value& cur : value->list_value()) {
if (!cur.VerifyTypeIs(Value::STRING, err))
return Value();
- if (!source->GetValue(cur.string_value(), true)) {
- *err = Err(cur, "Undefined identifier");
- return Value();
- }
+ // We don't need the return value, we invoke scope::GetValue only to mark
+ // the value as used. Note that we cannot use Scope::MarkUsed because we
+ // want to also search in the parent scope.
+ (void) source->GetValue(cur.string_value(), true);
}
return Value();
}
diff --git a/tools/gn/functions_target_unittest.cc b/tools/gn/functions_target_unittest.cc
index 40c6fde..af8b0e0 100644
--- a/tools/gn/functions_target_unittest.cc
+++ b/tools/gn/functions_target_unittest.cc
@@ -66,6 +66,16 @@
scoped_input.parsed()->Execute(setup.scope(), &err);
ASSERT_FALSE(err.has_error()) << err.message();
+ TestParseInput nonexistent_arg_input(
+ "source_set(\"foo\") {\n"
+ " a = {x = 1}\n"
+ " not_needed(a, [ \"x\", \"y\" ])\n"
+ "}\n");
+ ASSERT_FALSE(nonexistent_arg_input.has_error());
+ err = Err();
+ nonexistent_arg_input.parsed()->Execute(setup.scope(), &err);
+ ASSERT_FALSE(err.has_error()) << err.message();
+
TestParseInput exclusion_input(
"source_set(\"foo\") {\n"
" x = 1\n"
@@ -193,4 +203,4 @@
good_input.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error());
ASSERT_EQ(err.message(), "More than one language used in target sources.");
-}
\ No newline at end of file
+}