From 08a093b5644293c13dd89dbb1234aaf59b5393ad Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 15 Aug 2018 18:04:07 -0400 Subject: [PATCH] fix #28641, passing typevars to `<:` in typejoin and tuplemerge (#28655) (cherry picked from commit 290684d3180bb3b38259343d74479f90dccd9b04) --- base/compiler/typelimits.jl | 3 +++ base/promotion.jl | 10 +++++----- test/compiler/compiler.jl | 13 +++++++++++++ test/core.jl | 2 ++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index 83ca2a386b119..f8220375e4518 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -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) diff --git a/base/promotion.jl b/base/promotion.jl index 78a1954da55eb..319284beaaaf9 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -14,7 +14,11 @@ 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 @@ -22,10 +26,6 @@ function typejoin(@nospecialize(a), @nospecialize(b)) 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) diff --git a/test/compiler/compiler.jl b/test/compiler/compiler.jl index 904695982e030..7ddca137ed2c4 100644 --- a/test/compiler/compiler.jl +++ b/test/compiler/compiler.jl @@ -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] diff --git a/test/core.jl b/test/core.jl index 7dd27fefe03fc..d8981f352ffb1 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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