From 626952c46b7a6a172b6527da74bc2881d3ec7b8f Mon Sep 17 00:00:00 2001 From: xia Date: Mon, 7 Sep 2015 11:00:18 +0800 Subject: [PATCH] *: pass go vet check for shadowed variables --- ddl/ddl.go | 8 ++++++-- driver.go | 6 +++--- plan/plans/distinct.go | 3 ++- plan/plans/from.go | 10 ++++++---- plan/plans/groupby.go | 3 ++- plan/plans/union.go | 7 +++---- stmt/stmts/insert.go | 6 +++--- stmt/stmts/union.go | 11 ++++------- table/tables/tables.go | 3 ++- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ddl/ddl.go b/ddl/ddl.go index e4bc7ae3ee618..d5cf04bc80ebf 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -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) } diff --git a/driver.go b/driver.go index 9ccd9f3f95c7b..2a325764b9ee4 100644 --- a/driver.go +++ b/driver.go @@ -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: diff --git a/plan/plans/distinct.go b/plan/plans/distinct.go index 6fa790cd0bc87..13d0ed29e9fad 100644 --- a/plan/plans/distinct.go +++ b/plan/plans/distinct.go @@ -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 } diff --git a/plan/plans/from.go b/plan/plans/from.go index 152a6231fb4b8..c777b615fd8cc 100644 --- a/plan/plans/from.go +++ b/plan/plans/from.go @@ -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 } @@ -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 } diff --git a/plan/plans/groupby.go b/plan/plans/groupby.go index 4db419eb2df3b..03d0da3775bc5 100644 --- a/plan/plans/groupby.go +++ b/plan/plans/groupby.go @@ -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 } diff --git a/plan/plans/union.go b/plan/plans/union.go index 88fcba66ed2c6..73d3531641d11 100644 --- a/plan/plans/union.go +++ b/plan/plans/union.go @@ -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) { @@ -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 diff --git a/stmt/stmts/insert.go b/stmt/stmts/insert.go index 8808930284b22..e9056cc559033 100644 --- a/stmt/stmts/insert.go +++ b/stmt/stmts/insert.go @@ -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{}{} diff --git a/stmt/stmts/union.go b/stmt/stmts/union.go index 4ff05b5cf2ed8..3dd8a237d25a8 100644 --- a/stmt/stmts/union.go +++ b/stmt/stmts/union.go @@ -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) @@ -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. diff --git a/table/tables/tables.go b/table/tables/tables.go index 8a423e9cd9010..e8a3fc10df860 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -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 }