-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
go/types: incorrect error about missing return #11698
Comments
I think the Go spec unambiguously supports the gotype error. Functions with result parameters need to end in a terminating statement, and empty statements are not terminating statements. |
Interestingly if we change the body of that function from package main
import "fmt"
func f() int {
for {
}
}
func f1() int {
for true {
}
}
func main() {
fmt.Printf("hello world")
} $ tmp/sandbox109964380/main.go:13: missing return at end of function |
Per https://golang.org/ref/spec#Terminating_statements these programs contain a for loop without a loop condition or break statement, therefore the for loop is a terminating statement. These programs are thus valid and gotype is failing to detect the terminating statement? |
Isn't that this is working as intended for cmd/gc, and a bug The for loop doesn't terminate, so the function won't ever |
This is now a go/types error. The relevant lines from the spec are: "If the function's signature declares result parameters, the function body's statement list must end in a terminating statement." (https://tip.golang.org/ref/spec#Function_declarations) "A statement list ends in a terminating statement if the list is not empty and its final non-empty statement is terminating." (https://golang.org/ref/spec#Terminating_statements, end of paragraph). Thus:
@mdempsky was correct, too, because in 2015 this was still a gc bug :-) The relevant sentence in the spec changed in 2016 (b5ddbb9). |
With the spec change, this became a duplicate of #14537 which has been fixed. Not-reproducible anymore. Closing. |
gc successfully compiles the following program:
while gotype says:
go version devel +9b04852 Sat Jul 11 00:08:50 2015 +0000 linux/amd64
The text was updated successfully, but these errors were encountered: