Skip to content

Commit 21eb1b6

Browse files
authored
add some assorted subtyping tests (#20627)
1 parent 2f0156a commit 21eb1b6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/ambiguous.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,21 @@ let ambig = Int32[0]
369369
@test ambig[1] == 1
370370
end
371371

372+
# issue #11407
373+
f11407(::Dict{K,V}, ::Dict{Any,V}) where {K,V} = 1
374+
f11407(::Dict{K,V}, ::Dict{K,Any}) where {K,V} = 2
375+
@test_throws MethodError f11407(Dict{Any,Any}(), Dict{Any,Any}()) # ambiguous
376+
@test f11407(Dict{Any,Int}(), Dict{Any,Int}()) == 1
377+
f11407(::Dict{Any,Any}, ::Dict{Any,Any}) where {K,V} = 3
378+
@test f11407(Dict{Any,Any}(), Dict{Any,Any}()) == 3
379+
380+
# issue #12814
381+
abstract type A12814{N, T} end
382+
struct B12814{N, T} <: A12814{N, T}
383+
x::NTuple{N, T}
384+
end
385+
(::Type{T})(x::X) where {T <: A12814, X <: Array} = 1
386+
@test_throws MethodError B12814{3, Float64}([1, 2, 3]) # ambiguous
387+
@test B12814{3,Float64}((1, 2, 3)).x === (1.0, 2.0, 3.0)
388+
372389
nothing

test/subtype.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,3 +1901,16 @@ let A = Tuple{Array{Pair{T, JT} where JT<:Ref{T}, 1} where T, Vector},
19011901
@test_broken I <: A
19021902
@test_broken !Base.has_free_typevars(I)
19031903
end
1904+
1905+
# issue #8915
1906+
struct D8915{T<:Union{Float32,Float64}}
1907+
D8915{T}(a) where {T} = 1
1908+
D8915{T}(a::Int) where {T} = 2
1909+
end
1910+
@test D8915{Float64}(1) == 2
1911+
@test D8915{Float64}(1.0) == 1
1912+
1913+
# issue #18985
1914+
f18985(x::T, y...) where {T<:Union{Int32,Int64}} = (length(y), f18985(y[1], y[2:end]...)...)
1915+
f18985(x::T) where {T<:Union{Int32,Int64}} = 100
1916+
@test f18985(1, 2, 3) == (2, 1, 100)

0 commit comments

Comments
 (0)