Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[staticcheck] Last few staticchecks! #13909

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/test/endtoend/throttler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func UpdateThrottlerTopoConfigRaw(vtctldProcess *cluster.VtctldClientProcess, ke
}
if appRule != nil {
args = append(args, "--throttle-app", appRule.Name)
args = append(args, "--throttle-app-duration", protoutil.TimeFromProto(appRule.ExpiresAt).UTC().Sub(time.Now()).String())
args = append(args, "--throttle-app-duration", time.Until(protoutil.TimeFromProto(appRule.ExpiresAt).UTC()).String())
args = append(args, "--throttle-app-ratio", fmt.Sprintf("%f", appRule.Ratio))
if appRule.Exempt {
args = append(args, "--throttle-app-exempt")
Expand Down
5 changes: 3 additions & 2 deletions go/vt/vtgate/planbuilder/operators/route_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ func unwrapDerivedTables(ctx *plancontext.PlanningContext, exp sqlparser.Expr) s
}

exp = semantics.RewriteDerivedTableExpression(exp, tbl)
exp = getColName(exp)
if exp == nil {
if col := getColName(exp); col != nil {
exp = col
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this more clear with the following logic vs. the switch?

if col := getColName(exp); col == nil {
   return nil
}
exp = col

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my concern with this one specifically is idk if this is taking advantage of a scoping thing that could get fixed along with the "loop variable scope" issue (what i am saying is that regardless of how go actually treats this, i think col shouldn't be in scope outside the if

so you'd need instead to do:

if col := getColName(exp); col != nil {
    exp = col
} else {
    return nil
}

which isn't really more concise (but i could see an argument for still being more clear) than the switch version

Copy link
Contributor

@dbussink dbussink Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, you're right. It would have to be something like this to avoid the else:

col := getColName(exp)
if col == nil {
   // return direct nil to avoid interface value with nil. 
   return nil
}
exp = col

Again, no super strong opinion here.

} else {
return nil
}
}
Expand Down
Loading