From fc5470009502d5469fe5dbb58a52f0f659636ca2 Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Sat, 24 Sep 2022 22:32:19 +0800 Subject: [PATCH] Set `intersection = 1` during `intersect_sub_datatype` (#46882) (cherry picked from commit e6d99792e6dd0cffe41e98b8d642cf07e64364c5) --- 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 76fcab4c0a3010..d79185d50f301b 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -2780,7 +2780,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 fd5e3156493f17..2ff887a435cc8e 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1885,3 +1885,10 @@ let A = Tuple{Array{Pair{T, JT} where JT<:Ref{T}, 1} where T, Vector}, @test_broken I <: A @test_broken !Base.has_free_typevars(I) end + +#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