Skip to content

Commit

Permalink
Merge pull request #22343 from JuliaLang/jb/fix22338
Browse files Browse the repository at this point in the history
fix #22338 and #22339, specificity problems
  • Loading branch information
JeffBezanson authored Jun 13, 2017
2 parents 51ad96f + bd2dcf1 commit 01c6816
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2322,11 +2322,17 @@ static int tuple_morespecific(jl_datatype_t *cdt, jl_datatype_t *pdt, int invari
if (!cms && !eqv)
return 0;

// Tuple{..., T} not more specific than Tuple{..., Vararg{S}} if S is diagonal
if (eqv && i == clen-1 && clen == plen && !cva && pva && jl_is_typevar(ce) && jl_is_typevar(pe) && !cdiag && pdiag)
return 0;

if (cms) some_morespecific = 1;
i++;
}
if (cva && pva && clen > plen && (!pdiag || cdiag))
return 1;
if (cva && !pva && !some_morespecific)
return 0;
return some_morespecific || (cdiag && !pdiag);
}

Expand Down Expand Up @@ -2570,8 +2576,7 @@ static int type_morespecific_(jl_value_t *a, jl_value_t *b, int invariant, jl_ty
( type_morespecific_((jl_value_t*)((jl_tvar_t*)b)->lb,
(jl_value_t*)((jl_tvar_t*)a)->lb, 0, env) &&
!type_morespecific_((jl_value_t*)((jl_tvar_t*)b)->ub,
(jl_value_t*)((jl_tvar_t*)a)->ub, 0, env))) &&
num_occurs((jl_tvar_t*)a, env) >= num_occurs((jl_tvar_t*)b, env);
(jl_value_t*)((jl_tvar_t*)a)->ub, 0, env)));
}
if (!jl_is_type(b))
return 0;
Expand Down
19 changes: 19 additions & 0 deletions test/specificity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,22 @@ let A = Tuple{Type{D},D} where D<:Pair,
@test !args_morespecific(A, B)
@test !args_morespecific(C, B)
end

# issue #22338
let A = Tuple{Ref, Tuple{T}} where T,
B = Tuple{Ref{T}, Tuple{Vararg{T}}} where T,
C = Tuple{Ref{T}, Tuple{T}} where T
@test args_morespecific(C, A)
@test args_morespecific(C, B)
@test !args_morespecific(A, B)
@test !args_morespecific(B, A)
end

# issue #22339
let A = Tuple{T, Array{T, 1}} where T,
B = Tuple{T} where T,
C = Tuple{T} where T<:AbstractFloat
@test args_morespecific(B, A)
@test args_morespecific(C, B)
@test args_morespecific(C, A)
end

0 comments on commit 01c6816

Please sign in to comment.