Commit 30775f67 authored by Rob Pike's avatar Rob Pike

encoding/gob: don't send type info for unexported fields

Fixes #2517.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5440079
parent 8bc64108
......@@ -119,7 +119,9 @@ func (enc *Encoder) sendActualType(w io.Writer, state *encoderState, ut *userTyp
switch st := actual; st.Kind() {
case reflect.Struct:
for i := 0; i < st.NumField(); i++ {
enc.sendType(w, state, st.Field(i).Type)
if isExported(st.Field(i).Name) {
enc.sendType(w, state, st.Field(i).Type)
}
}
case reflect.Array, reflect.Slice:
enc.sendType(w, state, st.Elem())
......
......@@ -662,3 +662,19 @@ func TestSequentialDecoder(t *testing.T) {
}
}
}
// Should be able to have unrepresentable fields (chan, func) as long as they
// are unexported.
type Bug2 struct {
A int
b chan int
}
func TestUnexportedChan(t *testing.T) {
b := Bug2{23, make(chan int)}
var stream bytes.Buffer
enc := NewEncoder(&stream)
if err := enc.Encode(b); err != nil {
t.Fatalf("error encoding unexported channel: %s", err)
}
}
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