Fix control flow graph for unary expressions

This commit is contained in:
Marc Vertes
2018-09-03 16:44:45 +02:00
parent fef99903de
commit 285f8ae818
2 changed files with 19 additions and 0 deletions

15
_test/struct7.go Normal file
View File

@@ -0,0 +1,15 @@
package main
type Opt struct {
b bool
}
type T struct {
i int
opt Opt
}
func main() {
a := T{}
println(a.i, a.opt.b)
}

View File

@@ -930,6 +930,7 @@ func (interp *Interpreter) Cfg(root *Node) []*Node {
log.Println(n.index, "selector unresolved:", n.child[0].ident+"."+n.child[1].ident)
}
} else if fi := n.typ.fieldIndex(n.child[1].ident); fi >= 0 {
//log.Println(n.index, "selector field", fi)
// Resolve struct field index
if n.typ.cat == PtrT {
n.run = getPtrIndex
@@ -986,6 +987,9 @@ func (interp *Interpreter) Cfg(root *Node) []*Node {
}
n.typ = n.child[1].typ
case UnaryExpr:
wireChild(n)
case ValueSpec:
l := len(n.child) - 1
if n.typ = n.child[l].typ; n.typ == nil {