]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: accept trailing empty stmts in terminating stmt lists
authorRobert Griesemer <gri@golang.org>
Tue, 19 Apr 2016 18:27:52 +0000 (11:27 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 19 Apr 2016 20:36:35 +0000 (20:36 +0000)
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>

src/go/types/return.go
src/go/types/testdata/stmt1.src

index 662898521474cb000b77958b02dd814bbfa37719..0c1447f89b3d9d66e18083af9cc668c0cc4c268e 100644 (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 {
index a2955e6fd059d259c7b14ff912110ce42b65c171..24ad6ebdf18633e6f819fa1bbd6eb1544eef78d2 100644 (file)
@@ -20,17 +20,41 @@ 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
 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 }
+       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" */