diff --git a/_test/const26.go b/_test/const26.go new file mode 100644 index 000000000..16d854d0b --- /dev/null +++ b/_test/const26.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" +) + +func init() { + fmt.Println(constString) + fmt.Println(const2) + fmt.Println(varString) +} + +const constString string = "hello" + +const ( + const1 = iota + 10 + const2 + const3 +) + +var varString string = "test" + +func main() {} + +// Output: +// hello +// 11 +// test diff --git a/interp/gta.go b/interp/gta.go index 694954978..6518166b0 100644 --- a/interp/gta.go +++ b/interp/gta.go @@ -3,7 +3,6 @@ package interp import ( "path" "path/filepath" - "reflect" ) // gta performs a global types analysis on the AST, registering types, @@ -53,7 +52,7 @@ func (interp *Interpreter) gta(root *node, rpath, importPath, pkgName string) ([ for i := 0; i < n.nleft; i++ { dest, src := n.child[i], n.child[sbase+i] - val := reflect.ValueOf(sc.iota) + val := src.rval if n.anc.kind == constDecl { if _, err2 := interp.cfg(n, importPath, pkgName); err2 != nil { // Constant value can not be computed yet.