diff --git a/src/cmd/internal/gc/export.go b/src/cmd/internal/gc/export.go index 1efc8150c51f5e..614de4e2ce1563 100644 --- a/src/cmd/internal/gc/export.go +++ b/src/cmd/internal/gc/export.go @@ -64,7 +64,7 @@ func autoexport(n *Node, ctxt uint8) { if (ctxt != PEXTERN && ctxt != PFUNC) || dclcontext != PEXTERN { return } - if n.Ntype != nil && n.Ntype.Op == OTFUNC && n.Ntype.Left != nil { // method + if n.Param != nil && n.Ntype != nil && n.Ntype.Op == OTFUNC && n.Ntype.Left != nil { // method return } diff --git a/src/cmd/internal/gc/subr.go b/src/cmd/internal/gc/subr.go index 33741c3baf514e..b10a6b3d3d0d6d 100644 --- a/src/cmd/internal/gc/subr.go +++ b/src/cmd/internal/gc/subr.go @@ -371,8 +371,12 @@ func Nod(op int, nleft *Node, nright *Node) *Node { switch op { case OCLOSURE, ODCLFUNC: n.Func = new(Func) + n.Param = new(Param) case ONAME: n.Name = new(Name) + n.Param = new(Param) + case ODCLFIELD: + n.Param = new(Param) } return n } diff --git a/src/cmd/internal/gc/syntax.go b/src/cmd/internal/gc/syntax.go index d4ede60c900ad3..d52a3d4fe77e60 100644 --- a/src/cmd/internal/gc/syntax.go +++ b/src/cmd/internal/gc/syntax.go @@ -65,21 +65,12 @@ type Node struct { // ONAME Name *Name - Ntype *Node Defn *Node // ONAME: initializing assignment; OLABEL: labeled statement Pack *Node // real package for import . names Curfn *Node // function for local variables Paramfld *Type // TFIELD for this PPARAM; also for ODOT, curfn - - // ONAME func param with PHEAP - Outerexpr *Node // expression copied into closure for variable - Stackparam *Node // OPARAM node referring to stack copy of param - Alloc *Node // allocation call - - // ONAME closure param with PPARAMREF - Outer *Node // outer PPARAMREF in nested closure - Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF - Top int // top context (Ecall, Eproc, etc) + Alloc *Node // allocation call + *Param // OPACK Pkg *Pkg @@ -115,6 +106,19 @@ type Name struct { Needzero bool // if it contains pointers, needs to be zeroed on function entry } +type Param struct { + Ntype *Node + + // ONAME func param with PHEAP + Outerexpr *Node // expression copied into closure for variable + Stackparam *Node // OPARAM node referring to stack copy of param + + // ONAME closure param with PPARAMREF + Outer *Node // outer PPARAMREF in nested closure + Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF + Top int // top context (Ecall, Eproc, etc) +} + // Func holds Node fields used only with function-like nodes. type Func struct { Shortname *Node diff --git a/src/cmd/internal/gc/typecheck.go b/src/cmd/internal/gc/typecheck.go index 06f8b34305e0c7..8af9f084e2368f 100644 --- a/src/cmd/internal/gc/typecheck.go +++ b/src/cmd/internal/gc/typecheck.go @@ -813,7 +813,7 @@ OpSwitch: var l *Node for l = n.Left; l != r; l = l.Left { l.Addrtaken = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Addrtaken = true } } @@ -822,7 +822,7 @@ OpSwitch: Fatal("found non-orig name node %v", l) } l.Addrtaken = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Addrtaken = true } defaultlit(&n.Left, nil) @@ -3273,13 +3273,13 @@ func checkassign(stmt *Node, n *Node) { var l *Node for l = n; l != r; l = l.Left { l.Assigned = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Assigned = true } } l.Assigned = true - if l.Closure != nil { + if l.Param != nil && l.Closure != nil { l.Closure.Assigned = true } }