fix: fix builtin shadowing

This commit is contained in:
HAOYUatHZ 2019-07-02 08:27:02 +08:00
parent 0b26a826e9
commit 65d315d0a7
10 changed files with 33 additions and 33 deletions

View file

@ -27,8 +27,8 @@ import (
// packBytesSlice packs the given bytes as [L, V] as the canonical representation // packBytesSlice packs the given bytes as [L, V] as the canonical representation
// bytes slice // bytes slice
func packBytesSlice(bytes []byte, l int) []byte { func packBytesSlice(bytes []byte, l int) []byte {
len := packNum(reflect.ValueOf(l)) length := packNum(reflect.ValueOf(l))
return append(len, common.RightPadBytes(bytes, (l+31)/32*32)...) return append(length, common.RightPadBytes(bytes, (l+31)/32*32)...)
} }
// packElement packs the given reflect value according to the abi specification in // packElement packs the given reflect value according to the abi specification in

View file

@ -42,11 +42,11 @@ type HexOrDecimal64 uint64
// UnmarshalText implements encoding.TextUnmarshaler. // UnmarshalText implements encoding.TextUnmarshaler.
func (i *HexOrDecimal64) UnmarshalText(input []byte) error { func (i *HexOrDecimal64) UnmarshalText(input []byte) error {
int, ok := ParseUint64(string(input)) integer, ok := ParseUint64(string(input))
if !ok { if !ok {
return fmt.Errorf("invalid hex or decimal integer %q", input) return fmt.Errorf("invalid hex or decimal integer %q", input)
} }
*i = HexOrDecimal64(int) *i = HexOrDecimal64(integer)
return nil return nil
} }

View file

@ -116,14 +116,14 @@ func Lex(source []byte, debug bool) <-chan token {
} }
// next returns the next rune in the program's source. // next returns the next rune in the program's source.
func (l *lexer) next() (rune rune) { func (l *lexer) next() (r rune) {
if l.pos >= len(l.input) { if l.pos >= len(l.input) {
l.width = 0 l.width = 0
return 0 return 0
} }
rune, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) r, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
l.pos += l.width l.pos += l.width
return rune return r
} }
// backup backsup the last parsed element (multi-character) // backup backsup the last parsed element (multi-character)

View file

@ -66,11 +66,11 @@ func TestFeedPanics(t *testing.T) {
func checkPanic(want error, fn func()) (err error) { func checkPanic(want error, fn func()) (err error) {
defer func() { defer func() {
panic := recover() pnc := recover()
if panic == nil { if pnc == nil {
err = fmt.Errorf("didn't panic") err = fmt.Errorf("didn't panic")
} else if !reflect.DeepEqual(panic, want) { } else if !reflect.DeepEqual(pnc, want) {
err = fmt.Errorf("panicked with wrong error: got %q, want %q", panic, want) err = fmt.Errorf("panicked with wrong error: got %q, want %q", pnc, want)
} }
}() }()
fn() fn()

View file

@ -110,8 +110,8 @@ func (ctx ppctx) printObject(obj *otto.Object, level int, inArray bool) {
switch obj.Class() { switch obj.Class() {
case "Array", "GoArray": case "Array", "GoArray":
lv, _ := obj.Get("length") lv, _ := obj.Get("length")
len, _ := lv.ToInteger() length, _ := lv.ToInteger()
if len == 0 { if length == 0 {
fmt.Fprintf(ctx.w, "[]") fmt.Fprintf(ctx.w, "[]")
return return
} }
@ -120,12 +120,12 @@ func (ctx ppctx) printObject(obj *otto.Object, level int, inArray bool) {
return return
} }
fmt.Fprint(ctx.w, "[") fmt.Fprint(ctx.w, "[")
for i := int64(0); i < len; i++ { for i := int64(0); i < length; i++ {
el, err := obj.Get(strconv.FormatInt(i, 10)) el, err := obj.Get(strconv.FormatInt(i, 10))
if err == nil { if err == nil {
ctx.printValue(el, level+1, true) ctx.printValue(el, level+1, true)
} }
if i < len-1 { if i < length-1 {
fmt.Fprintf(ctx.w, ", ") fmt.Fprintf(ctx.w, ", ")
} }
} }

View file

@ -28,8 +28,8 @@ var locationTrims = []string{
// PrintOrigins sets or unsets log location (file:line) printing for terminal // PrintOrigins sets or unsets log location (file:line) printing for terminal
// format output. // format output.
func PrintOrigins(print bool) { func PrintOrigins(setPrint bool) {
if print { if setPrint {
atomic.StoreUint32(&locationEnabled, 1) atomic.StoreUint32(&locationEnabled, 1)
} else { } else {
atomic.StoreUint32(&locationEnabled, 0) atomic.StoreUint32(&locationEnabled, 0)

View file

@ -648,11 +648,11 @@ func NewStream(r io.Reader, inputLimit uint64) *Stream {
// NewListStream creates a new stream that pretends to be positioned // NewListStream creates a new stream that pretends to be positioned
// at an encoded list of the given length. // at an encoded list of the given length.
func NewListStream(r io.Reader, len uint64) *Stream { func NewListStream(r io.Reader, length uint64) *Stream {
s := new(Stream) s := new(Stream)
s.Reset(r, len) s.Reset(r, length)
s.kind = List s.kind = List
s.size = len s.size = length
return s return s
} }

View file

@ -51,16 +51,16 @@ func TestStreamKind(t *testing.T) {
for i, test := range tests { for i, test := range tests {
// using plainReader to inhibit input limit errors. // using plainReader to inhibit input limit errors.
s := NewStream(newPlainReader(unhex(test.input)), 0) s := NewStream(newPlainReader(unhex(test.input)), 0)
kind, len, err := s.Kind() gotKind, gotLen, err := s.Kind()
if err != nil { if err != nil {
t.Errorf("test %d: Kind returned error: %v", i, err) t.Errorf("test %d: Kind returned error: %v", i, err)
continue continue
} }
if kind != test.wantKind { if gotKind != test.wantKind {
t.Errorf("test %d: kind mismatch: got %d, want %d", i, kind, test.wantKind) t.Errorf("test %d: kind mismatch: got %d, want %d", i, gotKind, test.wantKind)
} }
if len != test.wantLen { if gotLen != test.wantLen {
t.Errorf("test %d: len mismatch: got %d, want %d", i, len, test.wantLen) t.Errorf("test %d: len mismatch: got %d, want %d", i, gotLen, test.wantLen)
} }
} }
} }
@ -229,12 +229,12 @@ testfor:
func TestStreamList(t *testing.T) { func TestStreamList(t *testing.T) {
s := NewStream(bytes.NewReader(unhex("C80102030405060708")), 0) s := NewStream(bytes.NewReader(unhex("C80102030405060708")), 0)
len, err := s.List() gotLen, err := s.List()
if err != nil { if err != nil {
t.Fatalf("List error: %v", err) t.Fatalf("List error: %v", err)
} }
if len != 8 { if gotLen != 8 {
t.Fatalf("List returned invalid length, got %d, want 8", len) t.Fatalf("List returned invalid length, got %d, want 8", gotLen)
} }
for i := uint64(1); i <= 8; i++ { for i := uint64(1); i <= 8; i++ {

View file

@ -448,9 +448,9 @@ func writeByteArray(val reflect.Value, w *encbuf) error {
if !val.CanAddr() { if !val.CanAddr() {
// Slice requires the value to be addressable. // Slice requires the value to be addressable.
// Make it addressable by copying. // Make it addressable by copying.
copy := reflect.New(val.Type()).Elem() cp := reflect.New(val.Type()).Elem()
copy.Set(val) cp.Set(val)
val = copy val = cp
} }
size := val.Len() size := val.Len()
slice := val.Slice(0, size).Bytes() slice := val.Slice(0, size).Bytes()

View file

@ -220,8 +220,8 @@ func (c *callback) call(ctx context.Context, method string, args []reflect.Value
// Is this an exported - upper case - name? // Is this an exported - upper case - name?
func isExported(name string) bool { func isExported(name string) bool {
rune, _ := utf8.DecodeRuneInString(name) r, _ := utf8.DecodeRuneInString(name)
return unicode.IsUpper(rune) return unicode.IsUpper(r)
} }
// Are all those types exported or built-in? // Are all those types exported or built-in?