Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chbk opened this issue Oct 17, 2022 · 1 comment
Open

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

chbk opened this issue Oct 17, 2022 · 1 comment
Assignees
Labels

Comments

@chbk
Copy link

chbk commented Oct 17, 2022

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:

  • go version go1.19.2 linux/amd64
  • gophernotes@v0.7.5

Related to #240

@cosmos72 cosmos72 self-assigned this Mar 28, 2024
@cosmos72 cosmos72 added the bug label Mar 28, 2024
@cosmos72
Copy link
Member

cosmos72 commented Mar 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants