Skip to content
This repository was archived by the owner on Jul 7, 2020. It is now read-only.
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

@dgryski

Description

@dgryski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions