mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 13:41:47 +00:00
compiler: allow to use _
in constants
When `_` is unused it can be omitted from constant values mapping. Catched when compiling `netmap` contract from nspcc-dev/neofs-contract. Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
945b56e350
commit
970769e5b2
2 changed files with 17 additions and 3 deletions
|
@ -555,9 +555,11 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
vs := spec.(*ast.ValueSpec)
|
vs := spec.(*ast.ValueSpec)
|
||||||
for i := range vs.Names {
|
for i := range vs.Names {
|
||||||
obj := c.currPkg.Types.Scope().Lookup(vs.Names[i].Name)
|
obj := c.currPkg.Types.Scope().Lookup(vs.Names[i].Name)
|
||||||
c.constMap[c.getIdentName("", vs.Names[i].Name)] = types.TypeAndValue{
|
if obj != nil { // can be nil if unused
|
||||||
Type: obj.Type(),
|
c.constMap[c.getIdentName("", vs.Names[i].Name)] = types.TypeAndValue{
|
||||||
Value: obj.(*types.Const).Val(),
|
Type: obj.Type(),
|
||||||
|
Value: obj.(*types.Const).Val(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,18 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestUnusedGlobal(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
const (
|
||||||
|
_ int = iota
|
||||||
|
a
|
||||||
|
)
|
||||||
|
func Main() int {
|
||||||
|
return 1
|
||||||
|
}`
|
||||||
|
eval(t, src, big.NewInt(1))
|
||||||
|
}
|
||||||
|
|
||||||
func TestChangeGlobal(t *testing.T) {
|
func TestChangeGlobal(t *testing.T) {
|
||||||
src := `package foo
|
src := `package foo
|
||||||
var a int
|
var a int
|
||||||
|
|
Loading…
Reference in a new issue