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

Closed
d2jvkpn opened this issue Oct 16, 2020 · 1 comment
Closed

Can't declare method in function #42007

d2jvkpn opened this issue Oct 16, 2020 · 1 comment

Comments

@d2jvkpn
Copy link

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?

yes

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

go env Output
$ go env

What did you do?

go build demo.go

demo.go

package main

import (
	"fmt"
)

func main() {
	type D struct {
		A int64
	}

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

	d := &D{A: 64}
	d.Print()
}

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
@davecheney
Copy link
Contributor

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:

@golang golang locked and limited conversation to collaborators Oct 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants