Merge pull request #69 from kuangchanglang/master

fix: panic when passing pointer to pointer as param
This commit is contained in:
Fatih Arslan 2016-07-19 16:45:16 -04:00 committed by GitHub
commit 14f46232cd
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)
}