about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/nixexpr.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-11-27T01·39-0800
committerkanepyork <rikingcoding@gmail.com>2020-11-27T18·34+0000
commit0c8c1227f1210a918737369c92d7e443d3d41c96 (patch)
treeb3bd55757bedc2fb3f9c7ac7be4cb5765580f1e0 /third_party/nix/src/libexpr/nixexpr.cc
parent5fb58e23deb28e2060500d347d402c2f48386691 (diff)
refactor(tvix): remove signedness conversions by using std::optional r/1931
The different signedness of level and withLevel was causing implicit conversions. Use a nullopt instead of a -1 sentinel value.

third_party/nix/src/libexpr/nixexpr.cc:242:21: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions]

Change-Id: I7c2cadb6fd6bbff6c5b84028651ad4ebba423297
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2157
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libexpr/nixexpr.cc')
-rw-r--r--third_party/nix/src/libexpr/nixexpr.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc
index 24ce6ec3fc91..391f0682059c 100644
--- a/third_party/nix/src/libexpr/nixexpr.cc
+++ b/third_party/nix/src/libexpr/nixexpr.cc
@@ -234,11 +234,11 @@ void ExprVar::bindVars(const StaticEnv& env) {
      set its level and displacement. */
   const StaticEnv* curEnv;
   unsigned int level;
-  int withLevel = -1;
+  std::optional<unsigned int> withLevel = std::nullopt;
   for (curEnv = &env, level = 0; curEnv != nullptr;
        curEnv = curEnv->up, level++) {
     if (curEnv->isWith) {
-      if (withLevel == -1) {
+      if (!withLevel.has_value()) {
         withLevel = level;
       }
     } else {
@@ -255,13 +255,13 @@ void ExprVar::bindVars(const StaticEnv& env) {
   /* Otherwise, the variable must be obtained from the nearest
      enclosing `with'.  If there is no `with', then we can issue an
      "undefined variable" error now. */
-  if (withLevel == -1) {
+  if (!withLevel.has_value()) {
     throw UndefinedVarError(format("undefined variable '%1%' at %2%") % name %
                             pos);
   }
 
   fromWith = true;
-  this->level = withLevel;
+  this->level = withLevel.value();
 }
 
 void ExprSelect::bindVars(const StaticEnv& env) {