Skip to content

Commit

Permalink
Merge pull request #16183 from JuliaLang/jb/fix16153
Browse files Browse the repository at this point in the history
fix #16153
  • Loading branch information
JeffBezanson committed May 4, 2016
2 parents 81bc6e7 + e349de6 commit 26d2f2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,14 @@ int jl_subtype_invariant(jl_value_t *a, jl_value_t *b, int ta)

// specificity comparison

static int type_eqv_with_ANY(jl_value_t *a, jl_value_t *b)
{
// equate ANY and Any for specificity purposes, #16153
return ((a == (jl_value_t*)jl_any_type && b == jl_ANY_flag) ||
(b == (jl_value_t*)jl_any_type && a == jl_ANY_flag) ||
type_eqv_(a, b));
}

static int jl_type_morespecific_(jl_value_t *a, jl_value_t *b, int invariant);

static int jl_tuple_morespecific_(jl_datatype_t *cdt, jl_datatype_t *pdt, int invariant)
Expand All @@ -2614,7 +2622,7 @@ static int jl_tuple_morespecific_(jl_datatype_t *cdt, jl_datatype_t *pdt, int in
if (pseq) pe = jl_tparam0(pe);

if (!jl_type_morespecific_(ce, pe, invariant)) {
if (type_eqv_(ce,pe)) {
if (type_eqv_with_ANY(ce,pe)) {
if (ci==cl-1 && pi==pl-1) {
if (!cseq && pseq)
return 1;
Expand All @@ -2631,7 +2639,7 @@ static int jl_tuple_morespecific_(jl_datatype_t *cdt, jl_datatype_t *pdt, int in
return 1;

// at this point we know one element is strictly more specific
if (!(jl_types_equal(ce,pe) ||
if (!(type_eqv_with_ANY(ce,pe) ||
(jl_is_typevar(pe) &&
jl_types_equal(ce,((jl_tvar_t*)pe)->ub)))) {
some_morespecific = 1;
Expand Down
14 changes: 14 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3887,3 +3887,17 @@ function f16158(x)
bar(x)
end
@test f16158("abc") == "abcaba"

# issue #16153
f16153(x) = 1
f16153(x::ANY, y...) = 2
@test f16153("") == 1
ff16153(x::ANY, y...) = 2
ff16153(x) = 1
@test ff16153("") == 1
g16153(x::ANY, y...) = 1
g16153(x::ANY, y::ANY) = 2
@test g16153(1, 1) == 2
gg16153(x::ANY, y::ANY) = 2
gg16153(x::ANY, y...) = 1
@test gg16153(1, 1) == 2

0 comments on commit 26d2f2c

Please sign in to comment.