yaegi icon indicating copy to clipboard operation
yaegi copied to clipboard

String access by index, got constant definition loop

Open ii64 opened this issue 1 year ago • 5 comments

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
> 

ii64 avatar Aug 07 '22 14:08 ii64

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.

clarkmcc avatar Aug 08 '22 00:08 clarkmcc

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.

ii64 avatar Aug 08 '22 03:08 ii64