mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
compiler: support iota
This commit is contained in:
parent
d8badd9a8d
commit
05ef951055
2 changed files with 20 additions and 1 deletions
|
@ -408,7 +408,12 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
for _, spec := range n.Specs {
|
||||
vs := spec.(*ast.ValueSpec)
|
||||
for i := range vs.Names {
|
||||
c.constMap[c.getIdentName("", vs.Names[i].Name)] = c.typeAndValueOf(vs.Values[i])
|
||||
info := c.buildInfo.program.Package(c.currPkg.Path())
|
||||
obj := info.Defs[vs.Names[i]]
|
||||
c.constMap[c.getIdentName("", vs.Names[i].Name)] = types.TypeAndValue{
|
||||
Type: obj.Type(),
|
||||
Value: obj.(*types.Const).Val(),
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -72,3 +72,17 @@ func TestGlobalsWithFunctionParams(t *testing.T) {
|
|||
`
|
||||
eval(t, src, []byte("FOO"))
|
||||
}
|
||||
|
||||
func TestIota(t *testing.T) {
|
||||
src := `package foo
|
||||
const (
|
||||
a = 2 << iota
|
||||
b
|
||||
|
||||
c = 11
|
||||
)
|
||||
func Main() int {
|
||||
return a + b + c
|
||||
}`
|
||||
eval(t, src, big.NewInt(17))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue