Skip to content

Commit

Permalink
fix JuliaLang#39218, bug in subtyping fast path for tuples with repea…
Browse files Browse the repository at this point in the history
…ted elements (JuliaLang#39237)
  • Loading branch information
JeffBezanson committed Jan 14, 2021
1 parent 0102a3b commit 4e6a3a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ static int subtype_tuple_tail(jl_datatype_t *xd, jl_datatype_t *yd, int8_t R, jl
// an identical type on the left doesn't need to be compared to a Vararg
// element type on the right more than twice.
}
else if (x_same &&
else if (x_same && e->Runions.depth == 0 &&
((yi == lasty && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) ||
(yi == lastx && !vx && vy && jl_is_concrete_type(xi)))) {
// fast path for repeated elements
Expand Down
14 changes: 14 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1854,3 +1854,17 @@ let A = Tuple{Type{T} where T<:Ref, Ref, Union{T, Union{Ref{T}, T}} where T<:Ref
@test I == typeintersect(A,B)
@test I == Tuple{Type{T}, Ref{T}, Union{Ref{T}, T}} where T<:Ref
end

# issue #39218
let A = Int, B = String, U = Union{A, B}
@test issub_strict(Union{Tuple{A, A}, Tuple{B, B}}, Tuple{U, U})
@test issub_strict(Union{Tuple{A, A}, Tuple{B, B}}, Tuple{Union{A, B}, Union{A, B}})
end

struct A39218 end
struct B39218 end
const AB39218 = Union{A39218,B39218}
f39218(::T, ::T) where {T<:AB39218} = false
g39218(a, b) = (@nospecialize; if a isa AB39218 && b isa AB39218; f39218(a, b); end;)
@test g39218(A39218(), A39218()) === false
@test_throws MethodError g39218(A39218(), B39218())

0 comments on commit 4e6a3a4

Please sign in to comment.