Avoid `StackOverflowError` in generic recursive `dot` (#53030)
A quick check to throw an error early if `first(x) == x && first(y) ==
y`, in which case the recursive `dot` will lead to a stack overflow.
Close https://github.com/JuliaLang/julia/issues/35654