Skip to content

Commit

Permalink
fix #32703, bad ambiguity error (#32731)
Browse files Browse the repository at this point in the history
caused by 5283847
(cherry picked from commit dc0bf52)
  • Loading branch information
JeffBezanson committed Aug 2, 2019
1 parent de3ea08 commit 2d8f4db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2803,6 +2803,14 @@ static jl_value_t *intersect_types(jl_value_t *x, jl_value_t *y, int emptiness_o
jl_stenv_t e;
if (obviously_disjoint(x, y, 0))
return jl_bottom_type;
if (jl_is_dispatch_tupletype(x) || jl_is_dispatch_tupletype(y)) {
if (jl_subtype(x, y))
return x;
else if (jl_subtype(y, x))
return y;
else
return jl_bottom_type;
}
init_stenv(&e, NULL, 0);
e.intersection = e.ignore_free = 1;
e.emptiness_only = emptiness_only;
Expand Down
19 changes: 19 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1615,3 +1615,22 @@ end
Tuple{Array{Tuple{Vararg{Int64,N}},N},Tuple{Vararg{Array{Int64,1},N}}} where N,
Tuple{Array{Tuple{Int64},1}, Tuple},
Tuple{Array{Tuple{Int64},1},Tuple{Array{Int64,1}}})

# issue #32703
struct Str{C} <: AbstractString
end
struct CSE{X}
end
const UTF16CSE = CSE{1}
const UTF16Str = Str{UTF16CSE}
const ASCIIStr = Str{CSE{2}}
c32703(::Type{<:Str{UTF16CSE}}, str::AbstractString) = 42
c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str

@testintersect(Tuple{Type{UTF16Str},ASCIIStr},
Tuple{Type{<:Str{C}}, Str{C}} where {C<:CSE},
Union{})
@test c32703(UTF16Str, ASCIIStr()) == 42
@test_broken typeintersect(Tuple{Vector{Vector{Float32}},Matrix,Matrix},
Tuple{Vector{V},Matrix{Int},Matrix{S}} where {S, V<:AbstractVector{S}}) ==
Tuple{Array{Array{Float32,1},1},Array{Int,2},Array{Float32,2}}

0 comments on commit 2d8f4db

Please sign in to comment.