fix: panic when passing pointer to pointer as param

This commit is contained in:
kcln1687 2016-07-19 21:20:03 +08:00
parent be738c8546
commit 5f175bf3fc
2 changed files with 22 additions and 1 deletions

View File

@ -431,7 +431,7 @@ func strctVal(s interface{}) reflect.Value {
v := reflect.ValueOf(s) v := reflect.ValueOf(s)
// if pointer get the underlying element≤ // if pointer get the underlying element≤
if v.Kind() == reflect.Ptr { for v.Kind() == reflect.Ptr {
v = v.Elem() v = v.Elem()
} }

View File

@ -1376,3 +1376,24 @@ func TestMap_InterfaceValue(t *testing.T) {
t.Errorf("Value does not match expected: %q != %q", s["A"], expected) 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)
}