Skip to content

Commit

Permalink
Fixing a method sort order bug that caused this ordering:
Browse files Browse the repository at this point in the history
==(Rational{T<:Integer},Number) at rational.j:105
==(T<:Number,T<:Number) at promotion.j:75
==(Rational{T<:Integer},Integer) at rational.j:98

which in turn caused issue #354 together with the recent changes to
unsigned integer arithmetic.
This is tricky because while (Rational,Integer)<:(Rational,Number),
(Rational,Number) has overlap with (T,T) but (Rational,Integer) doesn't.

The new sort order is better, and exposed 2 new method ambiguities in
rational which are also fixed here.
  • Loading branch information
JeffBezanson committed Jan 28, 2012
1 parent f29d532 commit ad8be65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions j/rational.j
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ hash(x::Rational) = integer_valued(x) ? hash(x.num) :
==(x::Rational, y::Integer ) = x.den == 1 && x.num == y
==(x::Integer , y::Rational) = y == x
# needed to avoid ambiguity between ==(x::Real, z::Complex) and ==(x::Rational, y::Number)
==(z::Complex , x::Rational) = real_valued(z) && real(z) == x
==(x::Rational, z::Complex ) = real_valued(z) && real(z) == x
==(x::Rational, y::Number ) = x.num == x.den*y
==(x::Number , y::Rational) = y == x
==(x::Rational, y::Float ) = x.den==0 ? oftype(y,x)==y : x.num == x.den*y
Expand Down
5 changes: 4 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,10 @@ static int args_morespecific(jl_value_t *a, jl_value_t *b)
int msp = jl_type_morespecific(a,b,0);
if (jl_has_typevars(b)) {
if (jl_type_match_morespecific(a,b) == (jl_value_t*)jl_false) {
return 0;
if (jl_has_typevars(a)) {
return 0;
}
return msp;
}
if (jl_has_typevars(a)) {
if (jl_type_match_morespecific(b,a) == (jl_value_t*)jl_false) {
Expand Down
11 changes: 9 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,12 @@ static int type_eqv_(jl_value_t *a, jl_value_t *b, jl_value_pair_t *stack)
if (a == b) return 1;
if (jl_is_typector(a)) a = (jl_value_t*)((jl_typector_t*)a)->body;
if (jl_is_typector(b)) b = (jl_value_t*)((jl_typector_t*)b)->body;
if (jl_is_typevar(a)) return 0;
if (jl_is_typevar(a)) {
if (jl_is_typevar(b)) {
return type_eqv_(((jl_tvar_t*)a)->ub, ((jl_tvar_t*)b)->ub, stack) &&
type_eqv_(((jl_tvar_t*)a)->lb, ((jl_tvar_t*)b)->lb, stack);
}
}
if (jl_is_long(a)) {
if (jl_is_long(b))
return (jl_unbox_long(a) == jl_unbox_long(b));
Expand Down Expand Up @@ -1629,7 +1634,9 @@ static int jl_tuple_subtype_(jl_value_t **child, size_t cl,

if (morespecific) {
// stop as soon as one element is strictly more specific
if (!jl_types_equal(ce,pe)) {
if (!(jl_types_equal(ce,pe) ||
(jl_is_typevar(pe) &&
jl_types_equal(ce,((jl_tvar_t*)pe)->ub)))) {
mode = 1;
assert(!ta);
// here go into a different mode where we return 1
Expand Down

0 comments on commit ad8be65

Please sign in to comment.