1
0
mirror of https://github.com/golang/go synced 2024-11-20 02:34:42 -07:00

go/types: accept trailing empty stmts in terminating stmt lists

Per the latest spec refinement (https://golang.org/cl/19981).

Fixes #14537.

Change-Id: I2dedee942c4da21dc94bdeda466f133827ab5bb9
Reviewed-on: https://go-review.googlesource.com/22241
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2016-04-19 11:27:52 -07:00
parent 9b6bf20a35
commit 562d398aef
2 changed files with 83 additions and 2 deletions

View File

@ -83,8 +83,13 @@ func (check *Checker) isTerminating(s ast.Stmt, label string) bool {
}
func (check *Checker) isTerminatingList(list []ast.Stmt, label string) bool {
n := len(list)
return n > 0 && check.isTerminating(list[n-1], label)
// trailing empty statements are permitted - skip them
for i := len(list) - 1; i >= 0; i-- {
if _, ok := list[i].(*ast.EmptyStmt); !ok {
return check.isTerminating(list[i], label)
}
}
return false // all statements are empty
}
func (check *Checker) isTerminatingSwitch(body *ast.BlockStmt, label string) bool {

View File

@ -22,7 +22,21 @@ func _(x, y int) (z int) {
func _(x, y int) (z int) {
{
return; ; ; // trailing empty statements are ok
}
; ; ;
}
func _(x, y int) (z int) {
{
}
} /* ERROR "missing return" */
func _(x, y int) (z int) {
{
; ; ;
}
; ; ;
} /* ERROR "missing return" */
// if statements
@ -31,6 +45,16 @@ func _(x, y int) (z int) {
return 1
}
func _(x, y int) (z int) {
if x < y { return; ; ; ; }
return 1
}
func _(x, y int) (z int) {
if x < y { return }
return 1; ;
}
func _(x, y int) (z int) {
if x < y { return }
} /* ERROR "missing return" */
@ -60,11 +84,18 @@ func _(x, y int) (z int) {
}
}
func _(x, y int) (z int) {
for {
return; ; ; ;
}
}
func _(x, y int) (z int) {
for {
return
break
}
; ; ;
} /* ERROR "missing return" */
func _(x, y int) (z int) {
@ -74,6 +105,14 @@ func _(x, y int) (z int) {
}
}
func _(x, y int) (z int) {
for {
for { break }
return ; ;
}
;
}
func _(x, y int) (z int) {
L: for {
for { break L }
@ -89,6 +128,13 @@ func _(x, y int) (z int) {
}
}
func _(x, y int) (z int) {
switch x {
case 0: return;
default: return; ; ;
}
}
func _(x, y int) (z int) {
switch x {
case 0: return
@ -113,6 +159,18 @@ func _(x, y int) (z int) {
}
}
func _(x, y int) (z int) {
switch x {
case 0: return
default:
switch y {
case 0: break
}
panic(0); ; ;
}
;
}
func _(x, y int) (z int) {
L: switch x {
case 0: return
@ -129,6 +187,11 @@ func _(ch chan int) (z int) {
select {}
} // nice!
func _(ch chan int) (z int) {
select {}
; ;
}
func _(ch chan int) (z int) {
select {
default: break
@ -153,6 +216,18 @@ func _(ch chan int) (z int) {
}
}
func _(ch chan int) (z int) {
select {
case <-ch: return; ; ;
default:
for i := 0; i < 10; i++ {
break
}
return; ; ;
}
; ; ;
}
func _(ch chan int) (z int) {
L: select {
case <-ch: return
@ -162,4 +237,5 @@ L: select {
}
return
}
; ; ;
} /* ERROR "missing return" */