Skip to content

Commit 2d8f4db

Browse files
committed
fix #32703, bad ambiguity error (#32731)
caused by 5283847 (cherry picked from commit dc0bf52)
1 parent de3ea08 commit 2d8f4db

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/subtype.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,14 @@ static jl_value_t *intersect_types(jl_value_t *x, jl_value_t *y, int emptiness_o
28032803
jl_stenv_t e;
28042804
if (obviously_disjoint(x, y, 0))
28052805
return jl_bottom_type;
2806+
if (jl_is_dispatch_tupletype(x) || jl_is_dispatch_tupletype(y)) {
2807+
if (jl_subtype(x, y))
2808+
return x;
2809+
else if (jl_subtype(y, x))
2810+
return y;
2811+
else
2812+
return jl_bottom_type;
2813+
}
28062814
init_stenv(&e, NULL, 0);
28072815
e.intersection = e.ignore_free = 1;
28082816
e.emptiness_only = emptiness_only;

test/subtype.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,3 +1615,22 @@ end
16151615
Tuple{Array{Tuple{Vararg{Int64,N}},N},Tuple{Vararg{Array{Int64,1},N}}} where N,
16161616
Tuple{Array{Tuple{Int64},1}, Tuple},
16171617
Tuple{Array{Tuple{Int64},1},Tuple{Array{Int64,1}}})
1618+
1619+
# issue #32703
1620+
struct Str{C} <: AbstractString
1621+
end
1622+
struct CSE{X}
1623+
end
1624+
const UTF16CSE = CSE{1}
1625+
const UTF16Str = Str{UTF16CSE}
1626+
const ASCIIStr = Str{CSE{2}}
1627+
c32703(::Type{<:Str{UTF16CSE}}, str::AbstractString) = 42
1628+
c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str
1629+
1630+
@testintersect(Tuple{Type{UTF16Str},ASCIIStr},
1631+
Tuple{Type{<:Str{C}}, Str{C}} where {C<:CSE},
1632+
Union{})
1633+
@test c32703(UTF16Str, ASCIIStr()) == 42
1634+
@test_broken typeintersect(Tuple{Vector{Vector{Float32}},Matrix,Matrix},
1635+
Tuple{Vector{V},Matrix{Int},Matrix{S}} where {S, V<:AbstractVector{S}}) ==
1636+
Tuple{Array{Array{Float32,1},1},Array{Int,2},Array{Float32,2}}

0 commit comments

Comments
 (0)