Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Union{} <: T always return false (except when T is Union{}) #40301

Closed
davidanthoff opened this issue Apr 1, 2021 · 3 comments
Closed

Make Union{} <: T always return false (except when T is Union{}) #40301

davidanthoff opened this issue Apr 1, 2021 · 3 comments

Comments

@davidanthoff
Copy link
Contributor

I have to admit that I don't understand the formal properties of the type system well enough to tell whether this could cause trouble, and also not clear whether this could be done in a 1.x release at all. With those caveats:

The current behavior, that any subtype check with Union{} on the left hand side will return true (no matter what) was surprising to me and makes it kind of cumbersome to write code that really does what at least I want it to do when I'm checking for a subtype relationship. I've always assumed that if I write say T <: AbstractString, that I really only can get a true if T is some sort of string, but it turns out that if I want that behavior I need to write T <: AbstractString && T !== Union{}.

This came up in queryverse/TableTraits.jl#21.

@simeonschaub
Copy link
Member

This is the defining property of the bottom type, so changing this would pretty much break all the internals related to the type system. What has come up before though is being able to dispatch on Type{T} where {T <: S}, but excluding T == Union{}, which is often useful when hunting down invalidations.

@davidanthoff
Copy link
Contributor Author

This is the defining property of the bottom type, so changing this would pretty much break all the internals related to the type system.

See, I knew I was missing at least some minor aspect of this ;)

I think what is still true, though, is that in pretty much every instance where I have used the <: function in my code ever, I actually didn't really want to test for the subtype relationship as defined in Julia (and that I now understand), but instead had hoped to get something that is more narrow and excludes the bottom type, like what apparently has been discussed for dispatch as well.

Don't really know whether I have a real suggestion here, other than a) it would be nice if there was a name for the relationship I'm interested in and b) if there was some function or operator in Julia that I could use instead of <: out of the box. I guess for now I can just create a need_a_name_for_this_function(T1,T2) = T1===T2 || (T1 <: T2 && T1 !== Union{}).

@c42f
Copy link
Member

c42f commented Nov 6, 2021

Possible duplicate of #33780 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants