Skip to content

Commit

Permalink
fix the bug reflect on zero Value
Browse files Browse the repository at this point in the history
fix the bug :reflect: call of reflect.Value.Type on zero Value

if the slice is nil, or len==0, will be panic.
the case:

type Foo struct{
	Bar[]int
}

func TestGoFunk(t *testing.T) {
	Log.InitLog()
	foo := []Foo{}
	bars := funk.Get(foo, "Bar") //panic !!
	fmt.Print(bars)
}
  • Loading branch information
ninghejun authored Nov 21, 2019
1 parent 35b4b47 commit 1aa708f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func get(value reflect.Value, path string) reflect.Value {
var resultSlice reflect.Value

length := value.Len()


if length == 0 {
return resultSlice
}

for i := 0; i < length; i++ {
item := value.Index(i)

Expand Down

0 comments on commit 1aa708f

Please sign in to comment.