Skip to content

cmd/gc: confusing error message for a bad receiver type #3783

@gopherbot

Description

@gopherbot

by dmitrymaluka:

package main

var i int
//var i *int

func (p *i) f() {
}

func main() {
}


./indir.go:6: invalid indirect of i (type int)


I expect the error message to be "is not a type".

After replacing i declaration by the commented one, where i is a pointer variable (var i
*int), the error message is correct:


./indir.go:6: *i is not a type


Quoting myself
(https://groups.google.com/forum/#!msg/golang-nuts/oRTdZYmkpqg/xKtazXH44N0J):

"Ok, as far as I understand now, the compiler was dealing with the AST
node *i treating it as a pointer indirection. But why it
did that in the first place? According to
http://golang.org/ref/spec#Method_declarations there is no place for a
pointer indirection, syntactically. This behavior looks strange to me,
and the resulting error message is a bit confusing."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions