yaegi
yaegi copied to clipboard
String access by index, got constant definition loop
The following program sample.go
triggers an unexpected result
package main
func main() {
m := "asdf"
j := m[0]
println(j)
}
Expected result
$ go run j.go
97
Got
$ yaegi ./j.go
97
Yaegi Version
devel
Additional Notes
However it break if you try to run it on REPL.
$ yaegi
> s := "abc"
: abc
> p := s[0]
1:28: constant definition loop
>
$ yaegi
> var k = "asdf"
: 0xc0004840f0
> var m = k[0]
1:18: constant definition loop
>
I've seen this error in seemingly unrelated issues. I'd love to know more about the root cause of this message for my own edification.
I was testing a piece of function, I had to declare (literally copied from Go file):
var (
l = "asdf"
m = l[0]
)
Expecting that yaegi REPL will declare these variables, but it looks like they treated as a constant declaration.