risor-io / risor

Fast and flexible scripting for Go developers and DevOps.
https://risor.io
Apache License 2.0
581 stars 24 forks source link

Bug: too many nested for loops start stepping on each other #171

Closed applejag closed 6 months ago

applejag commented 6 months ago

I've a hard time getting this down to as small of an example as possible. Here's what I got:

my_list := ['a', 'banana', 'c', 'd']

func get_match(c) {
    for _, s := range my_list {
        if strings.has_prefix(s, c) {
            return s
        }
    }
}

func do_thing_with_string(s) {
    for _, c := range s {
        print('char: "{c}"')

        _ = get_match(c)
    }
}

for _, s := range my_list {
    print('for my_list start: {s}')
    do_thing_with_string(s)
    print('for my_list end: {s}')
}
$ risor bug.risor
for my_list start: a
char: "a"
char: "banana"
char: "c"
char: "d"
for my_list end: a

The behavior here is just super weird. Don't know what's really going on.

myzie commented 6 months ago

Thanks @applejag I’ll debug this.