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

Using parametrised type in a Union breaks subtype check #37772

Open
andreyz4k opened this issue Sep 27, 2020 · 2 comments
Open

Using parametrised type in a Union breaks subtype check #37772

andreyz4k opened this issue Sep 27, 2020 · 2 comments
Assignees
Labels
domain:types and dispatch Types, subtyping and method dispatch

Comments

@andreyz4k
Copy link

I want to allow my function to take two arguments. One is the usual of variable type T and the second one may be either of the same type T or it can be my custom container type Cont{T}. Unfortunately, it looks like in this case type checker decides to turn off the diagonal type checks. So here are refined examples:

julia> Tuple{Int64,Float64} <: Tuple{T,T} where T
false      # normal
julia> Tuple{Int64,Float64} <: Tuple{T,Union{Array{T}, T}} where T
true       # breaking
julia> Tuple{Int64,Array{Float64}} <: Tuple{T,Union{Array{T}, T}} where T
true       # breaking
julia> Tuple{Int64,Array{Float64}} <: Tuple{T,Union{Array{T}, T}} where T <: Number
false      # adding type constraint here helps for some reason
julia> Tuple{Int64,Float64} <: Tuple{T,Union{Array{T}, T}} where T<:Number
true       # but here it doesn't

Reproduces both on 1.5.1 and on the master branch versions.

@JeffBezanson JeffBezanson self-assigned this Sep 28, 2020
@JeffBezanson JeffBezanson added kind:regression Regression in behavior compared to a previous version domain:types and dispatch Types, subtyping and method dispatch and removed kind:regression Regression in behavior compared to a previous version labels Sep 28, 2020
@JeffBezanson
Copy link
Sponsor Member

This was an intentional change (#34272) needed to fix bugs. I agree it's inconvenient though. It might be possible to make this case work without totally reverting that change.

@julbinb
Copy link

julbinb commented Apr 10, 2023

Intuitively, Tuple{T,Union{Cont{T}, T}} where T should be the same as Union{Tuple{T,T} where T, Tuple{Cont{T}, T} where T}. One could probably get away by defining two methods, f(::T, ::T) where T and f(::T, ::Cont{T}) where T, and calling the former from the latter to avoid code duplication. Of course, the latter method allows abstract T in the container whereas the former does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants