interp: handle getting address of interpreter interface value
Fixes #963.
This commit is contained in:
29
_test/addr2.go
Normal file
29
_test/addr2.go
Normal 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}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user