Fix crash when sources is set to a non-list value
Given this code:
executable("test_exe") { sources = "test.cc" }
gn crashes without an error message. With this change, the error is:
ERROR at //BUILD.gn:31:36: This is not a list.
executable("test_exe") { sources = "test.cc" }
^--------
Instead I see a string = "test.cc"
See //BUILD.gn:31:1: whence it was called.
executable("test_exe") { sources = "test.cc" }
^---------------------------------------------
BUG=None
R=brettw
Change-Id: I98665a6b9580b61f8165ce2705ad15be324c7f8b
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/5701
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/tools/gn/operators.cc b/tools/gn/operators.cc
index ad25159..40ea900 100644
--- a/tools/gn/operators.cc
+++ b/tools/gn/operators.cc
@@ -350,7 +350,7 @@
// Optionally apply the assignment filter in-place.
const PatternList* filter = dest->GetAssignmentFilter(exec_scope);
- if (filter) {
+ if (filter && written_value->type() == Value::LIST) {
std::vector<Value>& list_value = written_value->list_value();
auto first_deleted = std::remove_if(
list_value.begin(), list_value.end(),