1
0
mirror of https://github.com/golang/go synced 2024-11-27 05:31:31 -07:00
go/test/fixedbugs/issue30709.go
LE Manh Cuong 644543dd64 cmd/compile: fix const declaration group broken with closure
In typecheckclosure, a xfunc node will be put to xtop. But that node can
be shared between multiple closures, like in a const declaration group:

const (
	x = unsafe.Sizeof(func() {})
	y
)

It makes a xfunc node appears multiple times in xtop, causing duplicate
initLSym run.

To fix this issue, we only do typecheck for xfunc one time, and setup
closure node earlier in typecheckclosure process.

Fixes #30709

Change-Id: Ic924a157ee9f3e5d776214bef5390849ddc8aab9
Reviewed-on: https://go-review.googlesource.com/c/go/+/172298
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-16 19:07:42 +00:00

34 lines
550 B
Go

// run
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Check closure in const declaration group can be compiled
// and set correct value
package main
import "unsafe"
const (
x = unsafe.Sizeof(func() {})
y
)
func main() {
const (
z = unsafe.Sizeof(func() {})
t
)
// x and y must be equal
println(x == y)
// size must be greater than zero
println(y > 0)
// Same logic as x, y above
println(z == t)
println(t > 0)
}