[Lldb-commits] [lldb] [lldb] Return index of element in ValueObject path instead of the element's value (PR #74413)

Pete Lawrence via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 5 11:51:10 PST 2023


================
@@ -398,13 +398,16 @@ ValueObject::GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs,
   if (idxs.size() == 0)
     return GetSP();
   ValueObjectSP root(GetSP());
+
+  size_t current_index = 0;
   for (size_t idx : idxs) {
     root = root->GetChildAtIndex(idx);
     if (!root) {
       if (index_of_error)
-        *index_of_error = idx;
+        *index_of_error = current_index;
       return root;
     }
+    current_index += 1;
----------------
PortalPete wrote:

Sure!
I had a hunch someone would point this one out, but I thought it'd be fun to see who, if anyone, would.
You passed the test! 😂 

Personally, I prefer `+= 1` because:
- Swift doesn't have the `++` operator.
- In my mind `+= 1` more explicitly communicates my intent.
- I've seen people get burned by the "post" part of a post-increment operator too many times. 🙃


https://github.com/llvm/llvm-project/pull/74413


More information about the lldb-commits mailing list