New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 650880 link

Starred by 0 users

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

"spurious" assignment had no effect warning in GN

Project Member Reported by dpranke@chromium.org, Sep 27 2016

Issue description

% git diff
diff --git a/base/BUILD.gn b/base/BUILD.gn
index f764c0a..aace847 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -36,6 +36,12 @@ declare_args() {
   override_build_date = "N/A"
 }
 
+foo = false
+bar = true
+if (foo && bar) {
+  print("foo and bar")
+}
+
 if (is_android) {
   import("//build/config/android/rules.gni")
 }
src $ gn gen out/Release
ERROR at //base/BUILD.gn:40:7: Assignment had no effect.
bar = true
      ^---
You set the variable "bar" here and it was unused before it went
out of scope.
See //BUILD.gn:190:5: which caused the file to be included.
    "//base:base_unittests",
    ^----------------------


In this case, strictly speaking, the message is correct because foo can never be true and hence bar never needs to be read. However, if you change foo to be a declare_arg(), but don't set it, you get the same error, which is somewhere between confusing and wrong.

Interestingly, if you make the same change to //BUILD.gn you don't get the same error. I don't know why not.

 
This behavior also spawns "mark as used" workarounds, see https://cs.chromium.org/search/?q=assert.*true+file:.*.gni$&sq=package:chromium&type=cs or  //build/config/android/internal_rules.gni, which I think are a not great.

Sign in to add a comment