]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/closure2.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / closure2.go
index 4d61b45d3f42fa3461290645e48c35fc3a8f3c5f..081d2e2d3d178595cc60028722a6aec07c11ef46 100644 (file)
@@ -9,6 +9,8 @@
 
 package main
 
+var never bool
+
 func main() {
        {
                type X struct {
@@ -71,10 +73,11 @@ func main() {
 
        {
                var g func() int
-               for i := range [2]int{} {
+               var i int
+               for i = range [2]int{} {
                        if i == 0 {
                                g = func() int {
-                                       return i // test that we capture by ref here, i is mutated on every interation
+                                       return i // test that we capture by ref here, i is mutated on every interaction
                                }
                        }
                }
@@ -90,7 +93,7 @@ func main() {
                        q++
                        g = func() int {
                                return q // test that we capture by ref here
-                                        // q++ must on a different decldepth than q declaration
+                               // q++ must on a different decldepth than q declaration
                        }
                }
                if g() != 2 {
@@ -108,11 +111,23 @@ func main() {
                }()] = range [2]int{} {
                        g = func() int {
                                return q // test that we capture by ref here
-                                        // q++ must on a different decldepth than q declaration
+                               // q++ must on a different decldepth than q declaration
                        }
                }
                if g() != 2 {
                        panic("g() != 2")
                }
        }
+
+       {
+               var g func() int
+               q := 0
+               q, g = 1, func() int { return q }
+               if never {
+                       g = func() int { return 2 }
+               }
+               if g() != 1 {
+                       panic("g() != 1")
+               }
+       }
 }