Julia: typejoin bug with Tuple

Created on 18 Feb 2018  路  8Comments  路  Source: JuliaLang/julia

typejoin is known to be incorrect in the presence of triangular dispatch. Here's a simple repro to show how to trigger that. I think we can just be more conservative and move the isa(T, TypeVar) logic to the top of this function (e.g., always replace a Tuple{::TypeVar} with a Tuple{.ub::Type})

EDIT: this example was incorrect, see https://github.com/JuliaLang/julia/issues/26106#issuecomment-366566392 below for correction.

julia> T = Tuple{Tuple{T, T, Any}, Tuple{T, T, Vector{T}}} where T
Tuple{Tuple{T, T, Any}, Tuple{T, T, Array{T, 1}}} where T

julia> Base.typejoin(fieldtype(T, 1), fieldtype(T, 2))
Tuple{T, T, Any} where T

julia> ans <: fieldtype(T, 2)
false
bug

Most helpful comment

@martinholters I could add a test for this and submit it as a PR.

All 8 comments

Wouldn't we want fieldtype(T, 2) <: ans?

Sorry, yes, I did test that in the wrong direction and got confused by a subtyping bug. Here's the corrected version:

julia> T, S = Tuple{T, T, T} where T, Tuple{T, T, Vector{T}} where T
(Tuple{T, T, T} where T, Tuple{T, T, Array{T, 1}} where T)

julia> typejoin(S, T)
Tuple{T, T, T} where T

julia> T <: typejoin(S, T)
true

julia> S <: typejoin(S, T)
false

Looks like this problem has been resolved in Julia 1.1.0 version.

Indeed:

julia> T, S = Tuple{T, T, T} where T, Tuple{T, T, Vector{T}} where T
(Tuple{T,T,T} where T, Tuple{T,T,Array{T,1}} where T)

julia> typejoin(S, T)
Tuple{Any,Any,Any}

At a quick glance, I couldn't find a test for this, though.

@martinholters I could add a test for this and submit it as a PR.

Where exactly do I need to add these tests as there is no promotion.jl in test?Should I create one?

There is a bunch of typejoin tests in test/core.jl. That would be the obvious place to add this. (And also to check whether it exists and I missed it.)

fixed by 290684d3180, I believe

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yurivish picture yurivish  路  3Comments

tkoolen picture tkoolen  路  3Comments

omus picture omus  路  3Comments

musm picture musm  路  3Comments

dpsanders picture dpsanders  路  3Comments