That seems like the strongest possibility.
Going back to the original code: note that TestScope does a scope search, which calls add_to_scope on everything in scope, and your add_to_scope routine does a scope search. So that’s a recursive call.
I don’t figure it’s an infinite recursion, because that would hang on any interpreter. But it might be going N^2 deep or something.
It’s better to avoid nesting scope searches like this. Even when it’s not crashing, it’s going to take N^2 time – this single routine could cause perceptible lag.