Skip to content

Commit d394a93

Browse files
authored
Merge pull request #21761 from JuliaLang/jb/specificity21750
fix method specificity issue causing problems for pr #21750
2 parents 9f69d24 + 37f20f1 commit d394a93

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/subtype.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,8 @@ static int tuple_morespecific(jl_datatype_t *cdt, jl_datatype_t *pdt, int invari
23202320

23212321
if (ci >= clenf && !cseq) {
23222322
if (pseq && plenr <= clenr+1) return 1;
2323+
// shorter tuples are more specific, to ensure transitivity with varargs
2324+
if (!pseq && clenr < plenr) return 1;
23232325
break;
23242326
}
23252327
if (pi >= plenf && !pseq) {

test/core.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ _z_z_z_(::Int, c...) = 3
7878
@test args_morespecific(Tuple{Type{Pair{A,B} where B}} where A, Tuple{DataType})
7979
@test args_morespecific(Tuple{Union{Int,String},Type{Pair{A,B} where B}} where A, Tuple{Integer,UnionAll})
8080

81+
# PR #21750
82+
let A = Tuple{Any, Tuple{Vararg{Integer,N} where N}},
83+
B = Tuple{Any, Tuple{Any}},
84+
C = Tuple{Any, Tuple{}}
85+
@test args_morespecific(A, B)
86+
@test args_morespecific(C, A)
87+
@test args_morespecific(C, B)
88+
end
89+
8190
# with bound varargs
8291

8392
_bound_vararg_specificity_1{T,N}(::Type{Array{T,N}}, d::Vararg{Int, N}) = 0

0 commit comments

Comments
 (0)