Commit 6f88288a authored by Russ Cox's avatar Russ Cox

xml: fix reflect error

Fixes #1749.

R=bradfitz
CC=golang-dev
https://golang.org/cl/4431075
parent df2c5d54
......@@ -220,13 +220,10 @@ func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
}
if pv := val; pv.Kind() == reflect.Ptr {
if pv.Pointer() == 0 {
zv := reflect.Zero(pv.Type().Elem())
pv.Set(zv.Addr())
val = zv
} else {
val = pv.Elem()
if pv.IsNil() {
pv.Set(reflect.New(pv.Type().Elem()))
}
val = pv.Elem()
}
var (
......
......@@ -347,6 +347,7 @@ type allScalars struct {
Float32 float32
Float64 float64
String string
PtrString *string
}
var all = allScalars{
......@@ -368,8 +369,11 @@ var all = allScalars{
Float32: 13.0,
Float64: 14.0,
String: "15",
PtrString: &sixteen,
}
var sixteen = "16"
const testScalarsInput = `<allscalars>
<true1>true</true1>
<true2>1</true2>
......@@ -390,6 +394,7 @@ const testScalarsInput = `<allscalars>
<float32>13.0</float32>
<float64>14.0</float64>
<string>15</string>
<ptrstring>16</ptrstring>
</allscalars>`
func TestAllScalars(t *testing.T) {
......@@ -401,7 +406,7 @@ func TestAllScalars(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(a, all) {
t.Errorf("expected %+v got %+v", all, a)
t.Errorf("have %+v want %+v", a, all)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment