Skip to content

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

Description

@chbk
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

Activity

  1. self-assigned this
    on Mar 28, 2024
  2. cosmos72 commented on Mar 28, 2024

    @cosmos72
    Member

    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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions