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

Can't declare method in function #42007

d2jvkpn opened this issue Oct 16, 2020 · 1 comment

Can't declare method in function #42007

d2jvkpn opened this issue Oct 16, 2020 · 1 comment


Copy link

@d2jvkpn d2jvkpn commented Oct 16, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

go build demo.go


package main

import (

func main() {
	type D struct {
		A int64

	func (d *D) Print() {
		fmt.Println("~~~", d.A)

	d := &D{A: 64}

What did you expect to see?

compiled without error

What did you see instead?

./demo.go:12:22: syntax error: unexpected { at end of statement
./demo.go:16:2: syntax error: non-declaration statement outside function body

@d2jvkpn d2jvkpn changed the title Can't declare method in functiion Can't declare method in function Oct 16, 2020
Copy link

@davecheney davecheney commented Oct 16, 2020

Nope, you can't do that.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@davecheney davecheney closed this Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.