Skip to content

encoding/gob: fails with nested interface values #1416

@robpike

Description

@robpike
reported by taru karttunen. this program fails.

i know the bug, the fix will take some thinking.  putting it here to track.

package main

import "gob"
import "bytes"

type F struct {
    Contents
}

type Contents interface {}

type T struct {}

func main() {
    var buf bytes.Buffer
    e := gob.NewEncoder(&buf)
    d := gob.NewDecoder(&buf)
    gob.Register(new(F))
    gob.Register(new(T))
    f := &F{&T{}}
    var v interface{} = f
    err := e.Encode(&v)
    if err!=nil { panic("Encode: "+err.String()) }
    err  = d.Decode(&v)
    if err!=nil { panic("Decode: "+err.String()) }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions