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

cmd/compile: function compiles OK with no return statement #49003

Closed
rogpeppe opened this issue Oct 15, 2021 · 4 comments
Closed

cmd/compile: function compiles OK with no return statement #49003

rogpeppe opened this issue Oct 15, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@rogpeppe
Copy link
Contributor

commit 1cbec68

The following program compiles and runs, but it should complain that there's no return statement in f:

package main

func main() {
	_ = f("")
}

func f(s string) string {
	for range s {
	}
}
@ALTree ALTree added this to the Go1.18 milestone Oct 15, 2021
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 15, 2021
@randall77
Copy link
Contributor

This is kind of a corner case in the definition of terminating statements.

A "for" statement in which:
there are no "break" statements referring to the "for" statement, and
the loop condition is absent.

Technically that for statement qualifies, so no return after it is needed. There should maybe be an exception for a for range statement?

go1.17 gets this correct (it gives an error).

@gopherbot
Copy link

Change https://golang.org/cl/356189 mentions this issue: cmd/compile: make for loops with range statements terminating

@griesemer
Copy link
Contributor

Nice find!

@gopherbot
Copy link

Change https://golang.org/cl/356411 mentions this issue: go/types, types2: add test case for missing return

gopherbot pushed a commit that referenced this issue Oct 17, 2021
The respective issue was fixed in types2 with CL 356189;
and the problem didn't exist in go/types. This CL simply
adds the test case to the type checkers as well.

For #49003.

Change-Id: Ib50ee8bb0ad21f2916f2b79d4f77593302899a3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/356411
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
@golang golang locked and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants