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

Allow const func of named type #26351

Closed
earthboundkid opened this issue Jul 12, 2018 · 3 comments
Closed

Allow const func of named type #26351

earthboundkid opened this issue Jul 12, 2018 · 3 comments

Comments

@earthboundkid
Copy link
Contributor

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

Go 1.10

Does this issue reproduce with the latest release?

Yes

What did you do?

Play link:

package main

type funky func()

const g funky = func() {}

func main() {
}

What did you expect to see?

Succesful compilation.

What did you see instead?

prog.go:5:7: const initializer func literal is not a constant

Comment

Being able to make constant functions with a named type would be useful for http.HandlerFunc.

@earthboundkid
Copy link
Contributor Author

This is also not allowed:

package main

type funky func()

func f() {}

const g funky = f

func main() {
}

@jimmyfrasche
Copy link
Member

This isn't a bug: this is a proposal to change the language. As such, it needs to follow https://github.com/golang/proposal/blob/master/README.md I would recommend reading some existing issues with the Proposal label to get an idea of what sort of information you should include.

There needs to be a lot more information here. Are there differences in use between a const func and a var func? If you have a const func what can't you do with it. Is the only benefit http.Handlers or are there others? What are the downsides? Is const f = decorator(anotherFunc) legal?

I'm going to close this issue. Please create a new issue when you have a more fleshed out proposal or comment on one of the current issues for extending what can be const, such as #21130, and make an argument for including func as well.

@ianlancetaylor
Copy link
Contributor

Related to #6386.

@golang golang locked and limited conversation to collaborators Jul 12, 2019
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

4 participants