[m-rev.] diff: Avoid gcc warning about tautological comparison in test case.

Peter Wang novalazy at gmail.com
Fri Oct 19 16:54:03 AEDT 2018


We might need a general fix for this so that valid Mercury code doesn't
break at the C compiler, or just disable the gcc warning.

----

tests/typeclasses/typeclass_exist_method.m:
    Prevent gcc warning about a variable being compared to itself
    (self-comparison always evaluates to false).

diff --git a/tests/typeclasses/typeclass_exist_method.m b/tests/typeclasses/typeclass_exist_method.m
index 8f6100a04..44086e333 100644
--- a/tests/typeclasses/typeclass_exist_method.m
+++ b/tests/typeclasses/typeclass_exist_method.m
@@ -2,20 +2,22 @@
 % vim: ts=4 sw=4 et ft=mercury
 %---------------------------------------------------------------------------%
 
 :- module typeclass_exist_method.
 :- interface.
 :- import_module io.
 
 :- pred main(io::di, io::uo) is det.
 
 :- implementation.
+
+:- import_module int.
 :- import_module require.
 
 :- typeclass toto(T) where
   [
   ].
 
 :- instance toto(float) where [].
 :- instance toto(character) where [].
 
 :- some [V] (pred gen_toto_float(V) => toto(V)).
@@ -33,21 +35,21 @@ gen_toto_char('?').
 ].
 
 :- instance toto2(int) where [
     pred(gen_toto/2) is int_gen_toto
 ].
 
 :- some [V] (pred int_gen_toto(int, V) => toto(V)).
 :- mode int_gen_toto(in, out) is det.
 
 int_gen_toto(X, Y) :-
-    ( compare(=, X, X) ->
+    ( compare(=, X, X + 0) ->
         gen_toto_float(Y)
     ;
         error("oops")
     ).
 
 main -->
     { gen_toto(42, Y) },
     write(Y), nl.
 
 :- end_module typeclass_exist_method.
-- 
2.19.1



More information about the reviews mailing list