Odin
Odin copied to clipboard
Printing element of self-containing map causes infinite recursion
- Operating System & Odin Version: Odin: dev-2023-09:aaaff9b6 OS: Manjaro Linux, Linux 5.10.187-1-MANJARO CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz RAM: 15950 MiB
Running the following code:
package main
import "core:fmt"
T :: map[string]T
main :: proc() {
t := T{"m" = T{}}
fmt.println(t["m"])
}
results in an infinite recursion between fmt.fmt_value and fmt.fmt_named until the stack overflows.
It looks like this is caused by a bug in type info generation, where T's base type is indicated as being itself.
Note that this behavior is rather volatile, and seemingly insignificant changes cause this not to happen, for example:
main :: proc() {
t := T{"m" = T{}}
fmt.println(t)
fmt.println(t["m"])
}
works as expected.
This bug is caused by the frontend and should result in a cycle, but for some reason it is not being checked. For that to work, it would need to be T :: distinct map[string]T IF that even makes any sense to begin with.