Skip to content

Commit

Permalink
*: pass go vet
Browse files Browse the repository at this point in the history
check for shadowed variables
  • Loading branch information
zimulala committed Sep 7, 2015
1 parent a919e8c commit 626952c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 26 deletions.
8 changes: 6 additions & 2 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,17 @@ func (d *ddl) buildIndex(ctx context.Context, t table.Table, idxInfo *model.Inde
cols := t.Cols()
var vals []interface{}
for _, v := range idxInfo.Columns {
var (
data []byte
val interface{}
)
col := cols[v.Offset]
k := t.RecordKey(h, col)
data, err := txn.Get([]byte(k))
data, err = txn.Get([]byte(k))
if err != nil {
return errors.Trace(err)
}
val, err := t.DecodeValue(data, col)
val, err = t.DecodeValue(data, col)
if err != nil {
return errors.Trace(err)
}
Expand Down
6 changes: 3 additions & 3 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ func newdriverRows(rs rset.Recordset) *driverRows {
go func() {
err := io.EOF
if e := r.rs.Do(func(data []interface{}) (bool, error) {
vv, err := types.Clone(data)
if err != nil {
return false, errors.Trace(err)
vv, cloneErr := types.Clone(data)
if cloneErr != nil {
return false, errors.Trace(cloneErr)
}
select {
case r.rows <- vv:
Expand Down
3 changes: 2 additions & 1 deletion plan/plans/distinct.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ func (r *DistinctDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err e

var rows [][]interface{}
if err = r.Src.Do(ctx, func(id interface{}, in []interface{}) (bool, error) {
var v []interface{}
// get distinct key
key := in[0:r.HiddenFieldOffset]
v, err := t.Get(key)
v, err = t.Get(key)
if err != nil {
return false, err
}
Expand Down
10 changes: 6 additions & 4 deletions plan/plans/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ func (r *TableNilPlan) Do(ctx context.Context, f plan.RowIterFunc) error {
}
defer it.Close()
for it.Valid() && strings.HasPrefix(it.Key(), prefix) {
var err error
id, err := util.DecodeHandleFromRowKey(it.Key())
var id int64
id, err = util.DecodeHandleFromRowKey(it.Key())
if err != nil {
return err
}

// do nothing
if m, err := f(id, nil); !m || err != nil {
var m bool
if m, err = f(id, nil); !m || err != nil {
return err
}

Expand Down Expand Up @@ -291,7 +292,8 @@ func (r *TableDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error {
}
rks.appendKeys(rke)
rec = append(rec, rks)
if m, err := f(int64(0), rec); !m || err != nil {
m, err := f(int64(0), rec)
if !m || err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion plan/plans/groupby.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func (r *GroupByDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err er

if len(outRows) == 0 {
// empty table
out, err := r.evalEmptyTable(ctx)
var out []interface{}
out, err = r.evalEmptyTable(ctx)
if err != nil || out == nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions plan/plans/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (p *UnionPlan) Do(ctx context.Context, f plan.RowIterFunc) error {

// Eval the following select statements
for i, distinct := range p.Distincts {
var err error
src = p.Srcs[i+1]
// Eval src
if len(src.GetFields()) != len(rfs) {
Expand Down Expand Up @@ -100,9 +99,9 @@ func (p *UnionPlan) Do(ctx context.Context, f plan.RowIterFunc) error {
}
if distinct {
// distinct union, check duplicate
v, err := t.Get(in)
if err != nil {
return false, err
v, getErr := t.Get(in)
if getErr != nil {
return false, getErr
}
if len(v) > 0 {
// Find duplicate, ignore it
Expand Down
6 changes: 3 additions & 3 deletions stmt/stmts/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ func (s *InsertIntoStmt) Exec(ctx context.Context) (_ rset.Recordset, err error)
// For "insert into t values (default)" Default Eval.
m[expressions.ExprEvalDefaultName] = cols[i].Name.O

val, err := expr.Eval(ctx, m)
if err != nil {
return nil, errors.Trace(err)
val, evalErr := expr.Eval(ctx, m)
if evalErr != nil {
return nil, errors.Trace(evalErr)
}
r[cols[i].Offset] = val
marked[cols[i].Offset] = struct{}{}
Expand Down
11 changes: 4 additions & 7 deletions stmt/stmts/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ func (s *UnionStmt) SetText(text string) {

// Plan implements the plan.Planner interface.
func (s *UnionStmt) Plan(ctx context.Context) (plan.Plan, error) {
var r plan.Plan
var err error
srcs := make([]plan.Plan, 0, len(s.Selects))
for _, s := range s.Selects {
p, err := s.Plan(ctx)
Expand All @@ -65,13 +63,12 @@ func (s *UnionStmt) Plan(ctx context.Context) (plan.Plan, error) {
}
srcs = append(srcs, p)
}
if r, err = (&rsets.UnionRset{

r, err := (&rsets.UnionRset{
Srcs: srcs,
Distincts: s.Distincts,
}).Plan(ctx); err != nil {
return nil, err
}
return r, nil
}).Plan(ctx)
return r, err
}

// Exec implements the stmt.Statement Exec interface.
Expand Down
3 changes: 2 additions & 1 deletion table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ func (t *Table) IterRecords(ctx context.Context, startKey string, cols []*column
if err != nil {
return err
}
if more, err := fn(h, data, cols); !more || err != nil {
more, err := fn(h, data, cols)
if !more || err != nil {
return err
}

Expand Down

0 comments on commit 626952c

Please sign in to comment.