While this patch helps fixing the test that it includes, I just realized that the solution is not enough to avoid the infinite loop in the much more complex Factorio shader. So I probably have to find a stronger solution for a even more obscure edge case.
I will keep looking at that.