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

proposal: Go 2: make no result values expected when self has no return value too #36626

Closed
xbsura opened this issue Jan 17, 2020 · 5 comments
Closed
Labels
FrozenDueToAge LanguageChange Proposal v2 A language change or incompatible library change WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@xbsura
Copy link

xbsura commented Jan 17, 2020

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

$ go version
go version go1.13.1 linux/amd64

Does this issue reproduce with the latest release?

yes

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

Ubuntu 16.04

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="git.sysop.bigo.sg"
GONOSUMDB="git.sysop.bigo.sg"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE="git.sysop.bigo.sg"
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/dev_volumn/dis-grep/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build890909968=/tmp/go-build -gno-record-gcc-switches"

What did you do?

fake code is here:

func B() {
}

func A() {
return B()
}

What did you expect to see?

I want this works ok

What did you see instead?

It failed

In fact, A and B all have no return values, sometimes, for example in http handler, I need to cancel function with a 400 or something else:

func handler(ctx ...) {
...
// something went wrong
ctx.StatusCode(400)
return
}

But I can not just use return ctx.StatusCode(400) end this function, this make my code not clean, so, may golang make return with no value legal when function itself has no return value too?

thanks!!!

@gopherbot gopherbot added this to the Proposal milestone Jan 17, 2020
@xbsura
Copy link
Author

xbsura commented Jan 17, 2020

if A has a return int, and B has a return int, direct return B() is ok, so NO return params maybe should be same with NO return params I think, so such code can we same

@ALTree
Copy link
Member

ALTree commented Jan 17, 2020

How is

ctx.StatusCode(400)
return

less clean than

return ctx.StatusCode(400)

? They are roughly the same thing... except allowing the second one in a function that returns nothing would be misleading.

I think the confusion that allowing this syntax would cause would far exceed the small benefit of not having to write ctx.StatusCode(400) and return on two different lines.

@ianlancetaylor ianlancetaylor changed the title proposal: make no result values expected when self has no return value too proposal: Go 2: make no result values expected when self has no return value too Jan 17, 2020
@ianlancetaylor ianlancetaylor added v2 A language change or incompatible library change LanguageChange labels Jan 17, 2020
@xbsura
Copy link
Author

xbsura commented Jan 19, 2020

ok, thanks

@ianlancetaylor
Copy link
Contributor

For language change proposals, please fill out the template at https://go.googlesource.com/proposal/+/bd3ac287ccbebb2d12a386f1f1447876dd74b54d/go2-language-changes.md .

When you are done, please reply to the issue with @gopherbot please remove label WaitingForInfo.

Thanks!

@gopherbot gopherbot added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 21, 2020
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Feb 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge LanguageChange Proposal v2 A language change or incompatible library change WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants