interp: handle getting address of interpreter interface value

Fixes #963.
This commit is contained in:
Marc Vertes
2020-11-30 11:48:04 +01:00
committed by GitHub
parent 81d8339132
commit 81e1e5f206
2 changed files with 45 additions and 5 deletions

29
_test/addr2.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import (
"encoding/xml"
"fmt"
)
type Email struct {
Where string `xml:"where,attr"`
Addr string
}
func f(s string, r interface{}) error {
return xml.Unmarshal([]byte(s), &r)
}
func main() {
data := `
<Email where='work'>
<Addr>bob@work.com</Addr>
</Email>
`
v := Email{}
err := f(data, &v)
fmt.Println(err, v)
}
// Ouput:
// <nil> {work bob@work.com}

View File

@@ -588,12 +588,23 @@ func not(n *node) {
func addr(n *node) {
dest := genValue(n)
value := genValue(n.child[0])
next := getExec(n.tnext)
n.exec = func(f *frame) bltn {
dest(f).Set(value(f).Addr())
return next
c0 := n.child[0]
value := genValue(c0)
switch c0.typ.cat {
case interfaceT:
i := n.findex
l := n.level
n.exec = func(f *frame) bltn {
v := value(f).Interface().(valueInterface).value
getFrame(f, l).data[i] = reflect.ValueOf(v.Interface())
return next
}
default:
n.exec = func(f *frame) bltn {
dest(f).Set(value(f).Addr())
return next
}
}
}