Skip to content

Commit

Permalink
fix #28641, passing typevars to <: in typejoin and tuplemerge (#28655)
Browse files Browse the repository at this point in the history
(cherry picked from commit 290684d)
  • Loading branch information
JeffBezanson authored and KristofferC committed Sep 8, 2018
1 parent 6a1cc66 commit bbd310f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ function tuplemerge(a::DataType, b::DataType)
for loop_b = (false, true)
for i = (lt + 1):(loop_b ? lbr : lar)
ti = unwrapva(loop_b ? bp[i] : ap[i])
while ti isa TypeVar
ti = ti.ub
end
# compare (ti <-> tail), (wrapper ti <-> tail), (ti <-> wrapper tail), then (wrapper ti <-> wrapper tail)
# until we find the first element that contains the other in the pair
# TODO: this result would be more stable (and more associative and more commutative)
Expand Down
10 changes: 5 additions & 5 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ typejoin(@nospecialize(t)) = (@_pure_meta; t)
typejoin(@nospecialize(t), ts...) = (@_pure_meta; typejoin(t, typejoin(ts...)))
function typejoin(@nospecialize(a), @nospecialize(b))
@_pure_meta
if a <: b
if isa(a, TypeVar)
return typejoin(a.ub, b)
elseif isa(b, TypeVar)
return typejoin(a, b.ub)
elseif a <: b
return b
elseif b <: a
return a
elseif isa(a, UnionAll)
return UnionAll(a.var, typejoin(a.body, b))
elseif isa(b, UnionAll)
return UnionAll(b.var, typejoin(a, b.body))
elseif isa(a, TypeVar)
return typejoin(a.ub, b)
elseif isa(b, TypeVar)
return typejoin(a, b.ub)
elseif isa(a, Union)
return typejoin(typejoin(a.a, a.b), b)
elseif isa(b, Union)
Expand Down
13 changes: 13 additions & 0 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1977,3 +1977,16 @@ function bar28444()
e[1]
end
@test bar28444() == 1

# issue #28641
struct VoxelIndices{T <: Integer}
voxCrnrPos::NTuple{8,NTuple{3,T}}
voxEdgeCrnrs::NTuple{19, NTuple{2,T}}
voxEdgeDir::NTuple{19,T}
voxEdgeIx::NTuple{8,NTuple{8,T}}
subTets::NTuple{6,NTuple{4,T}}
tetEdgeCrnrs::NTuple{6,NTuple{2,T}}
tetTri::NTuple{16,NTuple{6,T}}
end
f28641(x::VoxelIndices, f) = getfield(x, f)
@test Base.return_types(f28641, (Any,Symbol)) == Any[Tuple]
2 changes: 2 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ end
@test typejoin(Tuple{Vararg{Int,2}}, Tuple{Int,Int,Int}) === Tuple{Int,Int,Vararg{Int}}
@test typejoin(Tuple{Vararg{Int,2}}, Tuple{Vararg{Int}}) === Tuple{Vararg{Int}}

@test typejoin(NTuple{3,Tuple}, NTuple{2,T} where T) == Tuple{Any,Any,Vararg{Tuple}}

# issue #26321
struct T26321{N,S<:NTuple{N}}
t::S
Expand Down

0 comments on commit bbd310f

Please sign in to comment.