From 9d7dee4a8f279ffd220d41d05a651761ed10d3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Lafuente?= Date: Sat, 20 Apr 2024 14:15:05 +0200 Subject: [PATCH] nix::Value: Use more descriptive names --- src/libexpr/value.hh | 15 ++++++++++----- tests/unit/libexpr/value/value.cc | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh index a1003e16b..5795f04cf 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/value.hh @@ -23,7 +23,7 @@ class BindingsBuilder; typedef enum { - tUnset, + tUninitialized = 0, tInt = 1, tBool, tString, @@ -167,7 +167,7 @@ public: struct Value { private: - InternalType internalType = tUnset; + InternalType internalType = tUninitialized; friend std::string showType(const Value & v); @@ -271,7 +271,7 @@ public: inline ValueType type(bool invalidIsThunk = false) const { switch (internalType) { - case tUnset: break; + case tUninitialized: break; case tInt: return nInt; case tBool: return nBool; case tString: return nString; @@ -296,9 +296,14 @@ public: internalType = newType; } - inline bool isInitialized() + /** + * A value becomes valid when it is initialized. We don't use this + * in the evaluator; only in the bindings, where the slight extra + * cost is warranted because of inexperienced callers. + */ + inline bool isValid() const { - return internalType != tUnset; + return internalType != tUninitialized; } inline void mkInt(NixInt n) diff --git a/tests/unit/libexpr/value/value.cc b/tests/unit/libexpr/value/value.cc index 49a896c87..5762d5891 100644 --- a/tests/unit/libexpr/value/value.cc +++ b/tests/unit/libexpr/value/value.cc @@ -10,7 +10,7 @@ class ValueTest : public LibStoreTest TEST_F(ValueTest, unsetValue) { Value unsetValue; - ASSERT_EQ(false, unsetValue.isInitialized()); + ASSERT_EQ(false, unsetValue.isValid()); ASSERT_EQ(nThunk, unsetValue.type(true)); ASSERT_DEATH(unsetValue.type(), ""); } @@ -19,7 +19,7 @@ TEST_F(ValueTest, vInt) { Value vInt; vInt.mkInt(42); - ASSERT_EQ(true, vInt.isInitialized()); + ASSERT_EQ(true, vInt.isValid()); } } // namespace nix