[ty] Fix panic where we would incorrectly consider overloads in another file as belonging to a function in the file being checked
Summary
Fixes https://github.com/astral-sh/ty/issues/1867. In certain cases where a function definition has not yet been completed, we can end up associating overloads from a totally different function (in a totally different file) with the unfinished function in the file being checked. That then leads us to panic in other places that assume (reasonably) that a function's overloads will all always be defined in a single file.
This PR fixes the panic by adding more sanity checks to OverloadLiteral::previous_overload().
Test Plan
Added a regression test that causes us to panic on main.
Diagnostic diff on typing conformance tests
No changes detected when running ty on typing conformance tests ✅
mypy_primer results
No ecosystem changes detected ✅
No memory usage changes detected ✅