From 96f3c7a3a8cf695477f08866bd47620e69b1b64c Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Wed, 16 Oct 2024 12:16:11 -0700 Subject: [PATCH] Fix shadowed variable in watchman/bser.cpp Summary: Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so. This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug. **What's a shadowed variable?** Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs. This diff fixes such an issue by renaming the variable. - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: meyering Differential Revision: D64398679 fbshipit-source-id: a36466237ef4cac69ad261d0b9c60a92a95db758 --- watchman/bser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/watchman/bser.cpp b/watchman/bser.cpp index dbfc260dfae3..e85655f29b46 100644 --- a/watchman/bser.cpp +++ b/watchman/bser.cpp @@ -492,13 +492,13 @@ class BserParser { } std::string expected = "{"; bool comma = false; - for (char type : types) { + for (char type_2 : types) { if (comma) { expected += ","; } else { comma = true; } - expected += std::to_string(static_cast(type)); + expected += std::to_string(static_cast(type_2)); } expected += "}"; throw BserParseError(