Skip to content

Commit

Permalink
Fix shadowed variable in watchman/PDU.cpp
Browse files Browse the repository at this point in the history
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: palmje

Differential Revision: D64398726

fbshipit-source-id: a9985cd1f1b104cf878dd12b2a3ad51c14b30d26
  • Loading branch information
r-barnes authored and facebook-github-bot committed Oct 15, 2024
1 parent 4c48464 commit b7c4d13
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions watchman/PDU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,18 +581,18 @@ ResultErrno<folly::Unit> PduBuffer::jsonEncodeToStream(
}

ResultErrno<folly::Unit> PduBuffer::pduEncodeToStream(
PduFormat format,
PduFormat format_2,
const json_ref& json,
watchman_stream* stm) {
switch (format.type) {
switch (format_2.type) {
case is_json_compact:
return jsonEncodeToStream(json, stm, JSON_COMPACT);
case is_json_pretty:
return jsonEncodeToStream(json, stm, JSON_INDENT(4));
case is_bser:
return bserEncodeToStream(1, format.capabilities, json, stm);
return bserEncodeToStream(1, format_2.capabilities, json, stm);
case is_bser_v2:
return bserEncodeToStream(2, format.capabilities, json, stm);
return bserEncodeToStream(2, format_2.capabilities, json, stm);
case need_data:
default:
return EINVAL;
Expand Down

0 comments on commit b7c4d13

Please sign in to comment.