Simplify unions when erasing last known values (#12064)
When we erase last known values in an union with multiple
Instance types, make sure that the resulting union doesn't have
duplicate erased types. The duplicate items weren't incorrect as such,
but they could cause overly complex error messages and potentially
slow type checking performance.
This is one of the fixes extracted from #12054. Since some of the
changes may cause regressions, it's better to split the PR.
Work on #12051.
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>