On Tue, 26 Mar 2019, at 12:37 PM, XiaoBing Jiang wrote: > Hi, all: > > in src/cmd/compile/internal/syntax/nodes.go, why need the aNode() function in > the interface? > > type Node interface { > // Pos() returns the position associated with the node as follows: > // 1) The position of a node representing a terminal syntax production > // (Name, BasicLit, etc.) is the position of the respective production > // in the source. > // 2) The position of a node representing a non-terminal production > // (IndexExpr, IfStmt, etc.) is the position of a token uniquely > // associated with that production; usually the left-most one > // ('[' for IndexExpr, 'if' for IfStmt, etc.) > Pos() Pos > aNode() > } > > type node struct { > // commented out for now since not yet used > // doc *Comment // nil means no comment(s) attached > pos Pos > } > > func (n *node) Pos() Pos { return n.pos } > func (*node) aNode() {} >
It prevents implementations of the interface outside of that package. The code can then assume it knows all the possible implementations of Node. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.