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

Combining explicit arguments with slice expansion doesn't work #22035

Closed
funny-falcon opened this issue Sep 26, 2017 · 2 comments
Closed

Combining explicit arguments with slice expansion doesn't work #22035

funny-falcon opened this issue Sep 26, 2017 · 2 comments

Comments

@funny-falcon
Copy link
Contributor

Probably it is already discussed. But I didn't see description in Language Specification.

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

go version go1.8 linux/amd64
play.golang.org

Does this issue reproduce with the latest release?

I think, yes.

What did you do?

https://play.golang.org/p/2Qm34TE-gn

func main() {
	a := []interface{}{ 1, 2, 3 }
	fmt.Println(1, 2, 3)
	fmt.Println(a...)
	fmt.Println(-1, 0, a...)
}

What did you expect to see?

1 2 3
1 2 3
-1 0 1 2 3

What did you see instead?

tmp/sandbox223672132/main.go:11:13: too many arguments in call to fmt.Println
	have (number, number, []interface {}...)
	want (...interface {})
@robpike
Copy link
Contributor

robpike commented Sep 26, 2017

This is working as defined in the spec. The arguments to match a variadic argument may be a list of singletons or a slice followed by ..., not a combination. The main reason is to avoid ambiguity that can lead to errors.

Working as intended.

@robpike robpike closed this as completed Sep 26, 2017
@mvdan
Copy link
Member

mvdan commented Sep 26, 2017

The previous Go2 proposals are #18605 and #19218.

@robpike you might want to raise your point in the proposals, or when the time comes for Go2.

@golang golang locked and limited conversation to collaborators Sep 26, 2018
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