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

builtin: print and println do not accept multiple-value expressions like fmt.Println and others #20656

Closed
go101 opened this issue Jun 13, 2017 · 4 comments

Comments

@go101
Copy link

go101 commented Jun 13, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.3 linux/amd64

What did you do?

package main

import "fmt"

func f1() ([]int, int, int) {
	return nil, 1, 2
}

func f2() (int, int) {
	return 1, 2
}

func main() {
	// function call nesting is ok.
	fmt.Println(f2())
	
	var s []int
	// function call nesting is ok.
	s = append(f1())
	_ = s

	// function call nestings are not ok.
	println(f2()) // multiple-value f2() in single-value context
	print(f2()) // multiple-value f2() in single-value context
}

What did you expect to see?

compile okay.

What did you see instead?

compile failed.

@mvdan mvdan changed the title inconsisten behavior for builtin functions print and println builtin: print and println do not accept multiple-value expressions like fmt.Println and others Jun 13, 2017
@mvdan
Copy link
Member

mvdan commented Jun 13, 2017

Smaller reproducer on play.golang.org: https://play.golang.org/p/0MMwjZ50XU

@ALTree
Copy link
Member

ALTree commented Jun 13, 2017

go/types accepts it.

Similar: #15992 (with copy instead of println)

@mvdan
Copy link
Member

mvdan commented Jun 13, 2017

In general it seems like you're right and this is an unexpected inconsistency - append takes ...Type just like print and println.

Then again, the print funcs are not guaranteed to stay in the language, so perhaps this was somehow done on purpose or not fixed on purpose.

@griesemer
Copy link
Contributor

This is an implementation restriction: https://golang.org/ref/spec#Bootstrapping:

print and println need not accept arbitrary argument types, but printing of boolean, numeric, and string types must be supported.

print and println are for bootstrapping - the language never guaranteed that they be first-class built-ins. Closing.

@golang golang locked and limited conversation to collaborators Jun 13, 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

5 participants