types: Move where we reject UnionAlls that cross TypeEgal #63770
This does sound much clearer semantics. Though I'm not sure an error is necessary -- if the object doesn't participate in TypeVar placeholders, it can just disallow walking through it and TypeEgal{T} where T simply returns TypeEgal{T} without the UnionAll binder remaining when it has nothing to bind.
No, I would like to stop doing that particular construction normalization in the first place, so it would be confusing. Not to mention that Tuple{TypeEgal{T}, Type{T}} where T would be very confusing.
Right now that is probably supposed to print as something like Tuple{TypeEgal{T<:Any}, Type{T}} where T (or in the future perhaps Tuple{TypeEgal{TypeIndex(0)}, Type{T}} where T), since an unbound variable doesn't have a where clause to refer to. So I think that's mostly a defect in the printer, not necessary a reason to do or not keep it as an error after this PR.
Ok, but what's the reason to allow it?
Just seemed like it might fall out of seemingly innocent code that just wants to unwrap_unionall / rewrap_unionall -- so every error that UnionAll throws (not specific to UnionAll, just that being the case here) is something that might end up having to be modeled in other places. E.g. it sounds awkward that rewrap_unionall(Tuple{TypeEgal{Vector.body}, S}, S) fails only if S == Vector
Yeah, I can see that argument, but I do really think that TypeEgal{T} where T ought to error. I think anything else is just very misleading, since it feels like the kind of thing that could maybe work (and who knows, maybe we want to make it work in the future). Let's revisit this after the UnionAll refactor, since the internal APIs will look different.
vtjnash
Keno
The type system does not allow UnionAlls quantified over
TypeEgal, e.g.TypeEgal{T} where T. I had originally implemented this by disallowing free typevars inside TypeEgal entirely, but we've since given those well-defined egality semantics. Disallowing free typevars there is a bit annoying, particularly after the UnionAll refactor, so instead move this restriction to the UnionAll constructor, which already does various validity checks. I think that's a better design.