Skip to content

Commit

Permalink
Merge pull request fatih#69 from kuangchanglang/master
Browse files Browse the repository at this point in the history
fix: panic when passing pointer to pointer as param
  • Loading branch information
fatih authored Jul 19, 2016
2 parents be738c8 + 5f175bf commit 14f4623
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func strctVal(s interface{}) reflect.Value {
v := reflect.ValueOf(s)

// if pointer get the underlying element≤
if v.Kind() == reflect.Ptr {
for v.Kind() == reflect.Ptr {
v = v.Elem()
}

Expand Down
21 changes: 21 additions & 0 deletions structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,3 +1376,24 @@ func TestMap_InterfaceValue(t *testing.T) {
t.Errorf("Value does not match expected: %q != %q", s["A"], expected)
}
}

func TestPointer2Pointer(t *testing.T) {
defer func() {
err := recover()
if err != nil {
fmt.Printf("err %+v\n", err)
t.Error("Internal nil pointer should not panic")
}
}()
a := &Animal{
Name: "Fluff",
Age: 4,
}
_ = Map(&a)

b := &a
_ = Map(&b)

c := &b
_ = Map(&c)
}

0 comments on commit 14f4623

Please sign in to comment.