Skip to content

Commit 689d138

Browse files
committed
subtyping: add tests for various Vararg bounds bugs
Refs #39088 Refs #39098
1 parent 25210a4 commit 689d138

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

test/subtype.jl

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,12 @@ function test_intersection()
10431043
Type{Tuple{Int,T}} where T<:Integer)
10441044
@testintersect(Type{<:Tuple{Any,Vararg{Any}}},
10451045
Type{Tuple{Vararg{Int,N}}} where N,
1046-
Type{Tuple{Int,Vararg{Int,N}}} where N)
1046+
!Union{})
1047+
1048+
@test typeintersect(Type{<:Tuple{Any,Vararg{Any}}}, Type{Tuple{Vararg{Int,N}}} where N) != Type{Tuple{Int,Vararg{Int}}}
1049+
@test_broken typeintersect(Type{<:Tuple{Any,Vararg{Any}}}, Type{Tuple{Vararg{Int,N}}} where N) == Type{Tuple{Int,Vararg{Int,N}}} where N
1050+
@test_broken typeintersect(Type{<:Tuple{Any,Vararg{Any}}}, Type{Tuple{Vararg{Int,N}}} where N) != Type{<:Tuple{Int,Vararg{Int}}}
1051+
10471052
@testintersect(Type{<:Array},
10481053
Type{AbstractArray{T}} where T,
10491054
Bottom)
@@ -2080,3 +2085,52 @@ let A = Tuple{NTuple{N,Any},Val{N}} where {N},
20802085
@testintersect(A, Tuple{Tuple{Any,Any,Any,Any,Any,Vararg{Any}},Val{4}}, Union{})
20812086
@testintersect(A, Tuple{Tuple{Any,Any,Any,Any,Any,Vararg{Any,N}} where {N},Val{4}}, Union{})
20822087
end
2088+
2089+
#issue #39088
2090+
let
2091+
a() = c((1,), (1,1,1,1))
2092+
c(d::NTuple{T}, ::NTuple{T}) where T = d
2093+
c(d::NTuple{f}, b) where f = c((d..., f), b)
2094+
j(h::NTuple{T}, ::NTuple{T} = a()) where T = nothing
2095+
@test j((1,1,1,1)) === nothing
2096+
end
2097+
2098+
let A = Tuple{NTuple{N, Int}, NTuple{N, Int}} where N,
2099+
C = Tuple{NTuple{4, Int}, NTuple{4, Int}}
2100+
@testintersect(A, Tuple{Tuple{Int, Vararg{Any}}, NTuple{4, Int}}, C)
2101+
@testintersect(A, Tuple{Tuple{Int, Vararg{Any, N}} where {N}, NTuple{4, Int}}, C)
2102+
@testintersect(A, Tuple{Tuple{Int, Vararg{Any, N}}, NTuple{4, Int}} where {N}, C)
2103+
2104+
Bs = (Tuple{Tuple{Int, Vararg{Any}}, Tuple{Int, Int, Vararg{Any}}},
2105+
Tuple{Tuple{Int, Vararg{Any,N1}}, Tuple{Int, Int, Vararg{Any,N2}}} where {N1,N2},
2106+
Tuple{Tuple{Int, Vararg{Any,N}} where {N}, Tuple{Int, Int, Vararg{Any,N}} where {N}})
2107+
Cerr = Tuple{Tuple{Int, Vararg{Int, N}}, Tuple{Int, Int, Vararg{Int, N}}} where {N}
2108+
for B in Bs
2109+
C = typeintersect(A, B)
2110+
@test C == typeintersect(B, A) != Union{}
2111+
@test C != Cerr
2112+
# TODO: The ideal result is Tuple{Tuple{Int, Int, Vararg{Int, N}}, Tuple{Int, Int, Vararg{Int, N}}} where {N}
2113+
@test_broken C != Tuple{Tuple{Int, Vararg{Int}}, Tuple{Int, Int, Vararg{Int}}}
2114+
end
2115+
end
2116+
2117+
let A = Pair{NTuple{N, Int}, NTuple{N, Int}} where N,
2118+
C = Pair{NTuple{4, Int}, NTuple{4, Int}}
2119+
@testintersect(A, Pair{<:Tuple{Int, Vararg{Any}}, NTuple{4, Int}}, C)
2120+
@testintersect(A, Pair{<:Tuple{Int, Vararg{Any, N}} where {N}, NTuple{4, Int}}, C)
2121+
@testintersect(A, Pair{<:Tuple{Int, Vararg{Any, N}}, NTuple{4, Int}} where {N}, C)
2122+
2123+
Bs = (Pair{<:Tuple{Int, Vararg{Int}}, <:Tuple{Int, Int, Vararg{Int}}},
2124+
Pair{Tuple{Int, Vararg{Int,N1}}, Tuple{Int, Int, Vararg{Int,N2}}} where {N1,N2},
2125+
Pair{<:Tuple{Int, Vararg{Int,N}} where {N}, <:Tuple{Int, Int, Vararg{Int,N}} where {N}})
2126+
Cerr = Pair{Tuple{Int, Vararg{Int, N}}, Tuple{Int, Int, Vararg{Int, N}}} where {N}
2127+
for B in Bs
2128+
C = typeintersect(A, B)
2129+
@test C == typeintersect(B, A) != Union{}
2130+
@test C != Cerr
2131+
@test_broken C != B
2132+
end
2133+
end
2134+
2135+
# Example from pr#39098
2136+
@testintersect(NTuple, Tuple{Any,Vararg}, Tuple{T, Vararg{T}} where {T})

0 commit comments

Comments
 (0)