From 418539c86d5117cdeb6461798fbe6949b5dd1e95 Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Sat, 24 Sep 2022 19:32:00 +0800 Subject: [PATCH] Set `intersection = 1` during `intersect_sub_datatype` At present, the `subtype_in_env` check is performed without this flag, thus `var_lt`/`var_gt` might set the wrong bounds. --- src/subtype.c | 2 +- test/subtype.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/subtype.c b/src/subtype.c index d6322503e9278..f30302ef6476b 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -2897,7 +2897,7 @@ static jl_value_t *intersect_sub_datatype(jl_datatype_t *xd, jl_datatype_t *yd, JL_GC_PUSHARGS(env, envsz); jl_stenv_t tempe; init_stenv(&tempe, env, envsz); - tempe.ignore_free = 1; + tempe.intersection = tempe.ignore_free = 1; if (subtype_in_env(isuper, super_pattern, &tempe)) { jl_value_t *wr = wrapper; int i; diff --git a/test/subtype.jl b/test/subtype.jl index 7fdf9ed1a38a0..373e41afe394e 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -2182,3 +2182,10 @@ S46735{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}},M,<:(Union{Abst A46735{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}},M,Union{AbstractMatrix{B}, AbstractMatrix{<:Vector{<:B}}}} @testintersect(A46735{B} where {B}, A46735, !Union{}) @testintersect(A46735{B, M} where {B, M}, A46735, !Union{}) + +#issue #46871 +struct A46871{T, N, M} <: AbstractArray{T, N} end +struct B46871{T, N} <: Ref{A46871{T, N, N}} end +for T in (B46871{Int, N} where {N}, B46871{Int}) # intentional duplication + @testintersect(T, Ref{<:AbstractArray{<:Real, 3}}, B46871{Int, 3}) +end