-
Notifications
You must be signed in to change notification settings - Fork 98
Description
The doc for Unmarshal() says:
To decode property list values into an interface value, Unmarshal decodes the property list into the concrete value contained in the interface value.
Here's a test that models a scenario described in this doc (if my understanding is correct):
type Person struct {
Name string
}
func TestUnmarshalInterface(t *testing.T) {
myPlist := []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Name</key>
<string>Deka Dahir</string>
</dict>
</plist>`)
var person interface{}
person = Person{}
t.Logf("(%v, %T)\n", person, person)
_, err := Unmarshal(myPlist, &person)
if err != nil {
t.Error(err)
}
t.Logf("(%v, %T)\n", person, person)
}I expected this to print the following:
({}, plist.Person)
(map[Name:Deka Dahir], plist.Person)
but it prints:
({}, plist.Person)
(map[Name:Deka Dahir], map[string]interface {})
I went back and read this go.dev doc page on "Interface Values" to remind myself what they are 🤓 . It describes interface values as having a "value" and a "concrete type". Note, the logs for printing the value and concrete type in this test are based on the example program in the go.dev doc.
I'm not sure whether the "concrete value" described in the go-plist doc was intended to refer to the "value" or the "concrete type" described in the go.dev doc. But, it seems surprising to me that the documented expected behavior of "decoding into the concrete value contained in the interface value" would result in the concrete type changing from plist.Person to map[string]interface{}.