Skip to content
This repository was archived by the owner on Jul 7, 2020. It is now read-only.

Grind moves delcarations in between loop labels and their bodies #8

Open
dgryski opened this issue Mar 10, 2015 · 0 comments
Open

Grind moves delcarations in between loop labels and their bodies #8

dgryski opened this issue Mar 10, 2015 · 0 comments

Comments

@dgryski
Copy link

dgryski commented Mar 10, 2015

A minimal test case:

package main

import "time"

func f(ch chan int) {

}

func main() {

    var m int

    ch := make(chan int)

    for i := 0; i < 10; i++ {
        go f(ch)
    }

    t := time.After(1 * time.Second)

loop:
    for i := 0; i < 10; i++ {
        select {
        case j, ok := <-ch:
            if ok {
                m += j
            }

        case <-t:
            break loop
        }

    }
}

becomes

package main

import "time"

func f(ch chan int) {
}

func main() {
    ch := make(chan int)

    for i := 0; i < 10; i++ {
        go f(ch)
    }

    t := time.After(1 * time.Second)

loop:
    var m int
    for i := 0; i < 10; i++ {
        select {
        case j, ok := <-ch:
            if ok {
                m += j
            }

        case <-t:
            break loop
        }
    }
}

which fails to build because loop is no longer a valid break label because the declaration of m was moved after it, making it a regular label.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant