gophernotes icon indicating copy to clipboard operation
gophernotes copied to clipboard

not a package: "n" in n.multiply <*ast.SelectorExpr>

Open chbk opened this issue 3 years ago • 1 comments

type Node struct {
  value int
  next *Node
}

func (n Node) multiply(x int) int {
  return n.value * x
}

n := Node{2, nil}
n.multiply(3)
repl.go:11:1: not a package: "n" in n.multiply <*ast.SelectorExpr>

However, this works:

type Node struct {
  value int
}

func (n Node) multiply(x int) int {
  return n.value * x
}

n := Node{2}
n.multiply(3)

Versions:

Related to #240

chbk avatar Oct 17 '22 16:10 chbk

Thanks for spotting this! It's a bug related to recursive types. Similar issues keep popping up, because reflect package cannot create recursive types so they need to be emulated - and the emulation is not yet perfect.

cosmos72 avatar Mar 28 '24 20:03 cosmos72