Skip to content

Commit 659d91f

Browse files
committed
Restrict generic ==(x::NCRingElem, y::NCRingElem) fallback
So far this method default to returning `false` if it failed to promote the arguments into a common ring. That lead to situations were comparisons between unrelated rings seemed "possible" but returned surprising results.
1 parent 995a497 commit 659d91f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/NCRings.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ end
8383

8484
*(x::NCRingElement, y::NCRingElem) = parent(y)(x)*y
8585

86+
# general fallback for comparison of elements via promotion.
87+
# This is different from Julia's existing promotion logic because
88+
# it takes parents into account
8689
function ==(x::NCRingElem, y::NCRingElem)
87-
fl, u, v = try_promote(x, y)
88-
if fl
89-
return u == v
90-
else
91-
return false
92-
end
90+
if typeof(x) === typeof(y)
91+
# avoid infinite recursion: we only get here
92+
# if a ring type "forgot" to implement ==
93+
end
94+
fl, u, v = try_promote(x, y)
95+
fl && return u == v
96+
throw(NotImplementedError(:(==), x, y))
9397
end
9498

9599
==(x::NCRingElem, y::NCRingElement) = x == parent(x)(y)

0 commit comments

Comments
 (0)