Hirevo / som-rs

An alternative implementation of the Simple Object Machine, written in Rust

Home Page:https://hirevo.github.io/som-rs/som_interpreter_bc/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Object>>#hashcode` recurses infinitely on objects with cyclic references

Hirevo opened this issue · comments

While working with graphs to test various pathfinding algorithms in SOM, I discovered that the current implementation of the Object>>#hashcode primitive infinitely recurses, if the object contains a reference cycle anywhere in itself and/or in its locals.

Minimal example code:

CyclicDataTest = (
    run: args = (
        | first second |

        first := Array new: 1.
        second := Array new: 1.

        first at: 1 put: second.
        second at: 1 put: first.

        " this call to `Object>>#hashcode` recurses infinitely until the stack overflows "
        first hashcode println.
    )
)

Running this code results in:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted