Fixed evaluation of overloaded == and != operators

Partially fixes bug #19570