Commit 3cb973ff authored by Rob Pike's avatar Rob Pike

gob: fix trivial bug in map marshaling.

Forgot to send key/value types.

R=rsc
CC=golang-dev, hmc2you
https://golang.org/cl/4434058
parent 4877c8a7
......@@ -116,6 +116,9 @@ func (enc *Encoder) sendActualType(w io.Writer, state *encoderState, ut *userTyp
}
case reflect.Array, reflect.Slice:
enc.sendType(w, state, st.Elem())
case reflect.Map:
enc.sendType(w, state, st.Key())
enc.sendType(w, state, st.Elem())
}
return true
}
......
......@@ -514,3 +514,38 @@ func TestNestedInterfaces(t *testing.T) {
t.Fatalf("final value %d; expected %d", inner.A, 7)
}
}
// The bugs keep coming. We forgot to send map subtypes before the map.
type Bug1Elem struct {
Name string
Id int
}
type Bug1StructMap map[string]Bug1Elem
func bug1EncDec(in Bug1StructMap, out *Bug1StructMap) os.Error {
return nil
}
func TestMapBug1(t *testing.T) {
in := make(Bug1StructMap)
in["val1"] = Bug1Elem{"elem1", 1}
in["val2"] = Bug1Elem{"elem2", 2}
b := new(bytes.Buffer)
enc := NewEncoder(b)
err := enc.Encode(in)
if err != nil {
t.Fatal("encode:", err)
}
dec := NewDecoder(b)
out := make(Bug1StructMap)
err = dec.Decode(&out)
if err != nil {
t.Fatal("decode:", err)
}
if !reflect.DeepEqual(in, out) {
t.Errorf("mismatch: %v %v", in, out)
}
}
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