Skip to content

1.4.1中关于闭包的例子和本地测试结果不一致 #655

Description

@baiyeidk
func main() {
    for i := 0; i < 3; i++ {
        defer func(){ println(i) } ()
    }
}
// Output:
// 3
// 3
// 3

这个例子我在本地测试如下

Image

是因为高版本的go对循环的局部变量做了新的机制吗?

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