Skip to content

Commit dc0bf52

Browse files
authored
fix #32703, bad ambiguity error (#32731)
caused by 5283847
1 parent 30b3636 commit dc0bf52

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
@@ -3032,6 +3032,14 @@ static jl_value_t *intersect_types(jl_value_t *x, jl_value_t *y, int emptiness_o
30323032
jl_stenv_t e;
30333033
if (obviously_disjoint(x, y, 0))
30343034
return jl_bottom_type;
3035+
if (jl_is_dispatch_tupletype(x) || jl_is_dispatch_tupletype(y)) {
3036+
if (jl_subtype(x, y))
3037+
return x;
3038+
else if (jl_subtype(y, x))
3039+
return y;
3040+
else
3041+
return jl_bottom_type;
3042+
}
30353043
init_stenv(&e, NULL, 0);
30363044
e.intersection = e.ignore_free = 1;
30373045
e.emptiness_only = emptiness_only;

test/subtype.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,3 +1632,22 @@ end
16321632
@testintersect(Tuple{Type{T} where T<:(S32488{Tuple{_A}, Int64, 1, _A} where _A), Tuple{Vararg{Int64, D}} where D},
16331633
Tuple{Type{S32488{S, T, N, L}}, Tuple{Vararg{T, L}}} where L where N where T where S,
16341634
Tuple{Type{S32488{Tuple{L},Int64,1,L}},Tuple{Vararg{Int64,L}}} where L)
1635+
1636+
# issue #32703
1637+
struct Str{C} <: AbstractString
1638+
end
1639+
struct CSE{X}
1640+
end
1641+
const UTF16CSE = CSE{1}
1642+
const UTF16Str = Str{UTF16CSE}
1643+
const ASCIIStr = Str{CSE{2}}
1644+
c32703(::Type{<:Str{UTF16CSE}}, str::AbstractString) = 42
1645+
c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str
1646+
1647+
@testintersect(Tuple{Type{UTF16Str},ASCIIStr},
1648+
Tuple{Type{<:Str{C}}, Str{C}} where {C<:CSE},
1649+
Union{})
1650+
@test c32703(UTF16Str, ASCIIStr()) == 42
1651+
@test_broken typeintersect(Tuple{Vector{Vector{Float32}},Matrix,Matrix},
1652+
Tuple{Vector{V},Matrix{Int},Matrix{S}} where {S, V<:AbstractVector{S}}) ==
1653+
Tuple{Array{Array{Float32,1},1},Array{Int,2},Array{Float32,2}}

0 commit comments

Comments
 (0)