Skip to content

Commit

Permalink
interp: handle getting address of interpreter interface value
Browse files Browse the repository at this point in the history
Fixes #963.
  • Loading branch information
mvertes authored Nov 30, 2020
1 parent 81d8339 commit 81e1e5f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
29 changes: 29 additions & 0 deletions _test/addr2.go
Original file line number Diff line number Diff line change
@@ -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}
21 changes: 16 additions & 5 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 81e1e5f

Please sign in to comment.