[m-rev.] for review: Fix reverse implication goals.

Peter Wang novalazy at gmail.com
Thu Oct 28 10:52:10 AEDT 2021


compiler/parse_goal.m:
    Fix typo: A <= B was parsed as B => B.

tests/hard_coded/Mmakefile:
tests/hard_coded/implication.exp:
tests/hard_coded/implication.m:
    Add test case.

NEWS:
    Announce change.

diff --git a/NEWS b/NEWS
index 3a07b8fd8..eab098551 100644
--- a/NEWS
+++ b/NEWS
@@ -542,6 +542,8 @@ Changes to the Mercury compiler
   warning about modules that are imported in the interface section but are
   not used in the interface section.
 
+* We have fixed parsing of reverse implication goals (A <= B).
+
 Portability improvements
 ------------------------
 
diff --git a/compiler/parse_goal.m b/compiler/parse_goal.m
index d01c4f435..e5d68d11b 100644
--- a/compiler/parse_goal.m
+++ b/compiler/parse_goal.m
@@ -935,7 +935,7 @@ parse_goal_implication(Functor, ArgTerms, Context, ContextPieces,
         then
             (
                 Functor = "<=",
-                Goal = implies_expr(Context, GoalB, GoalB)
+                Goal = implies_expr(Context, GoalB, GoalA)
             ;
                 Functor = "=>",
                 Goal = implies_expr(Context, GoalA, GoalB)
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 4b105e23a..af4ab31ca 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -198,6 +198,7 @@ ORDINARY_PROGS = \
 	if_then_else_expr_state_var \
 	impl_def_lex \
 	impl_def_lex_string \
+	implication \
 	impossible_unify \
 	impure_foreign \
 	impure_init_and_final \
diff --git a/tests/hard_coded/implication.exp b/tests/hard_coded/implication.exp
new file mode 100644
index 000000000..2d069a314
--- /dev/null
+++ b/tests/hard_coded/implication.exp
@@ -0,0 +1,16 @@
+implication:
+ok
+ok
+ok
+ok
+reverse implication:
+ok
+ok
+ok
+ok
+logical equivalence:
+ok
+ok
+ok
+ok
+done.
diff --git a/tests/hard_coded/implication.m b/tests/hard_coded/implication.m
new file mode 100644
index 000000000..518161d90
--- /dev/null
+++ b/tests/hard_coded/implication.m
@@ -0,0 +1,101 @@
+%---------------------------------------------------------------------------%
+% vim: ts=4 sw=4 et ft=mercury
+%---------------------------------------------------------------------------%
+
+:- module implication.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+main(!IO) :-
+    io.write_string("implication:\n", !IO),
+    ( if t => t then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+    ( if t => f then
+        bad(!IO)
+    else
+        ok(!IO)
+    ),
+    ( if f => t then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+    ( if f => f then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+
+    io.write_string("reverse implication:\n", !IO),
+    ( if t <= t then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+    ( if f <= t then
+        bad(!IO)
+    else
+        ok(!IO)
+    ),
+    ( if t <= f then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+    ( if f <= f then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+
+    io.write_string("logical equivalence:\n", !IO),
+    ( if t <=> t then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+    ( if t <=> f then
+        bad(!IO)
+    else
+        ok(!IO)
+    ),
+    ( if f <=> t then
+        bad(!IO)
+    else
+        ok(!IO)
+    ),
+    ( if f <=> f then
+        ok(!IO)
+    else
+        bad(!IO)
+    ),
+
+    io.write_string("done.\n", !IO).
+
+:- pred t is semidet.
+
+t :- semidet_true.
+
+:- pred f is semidet.
+
+f :- semidet_false.
+
+:- pred ok(io::di, io::uo) is det.
+
+ok(!IO) :-
+    io.write_string("ok\n", !IO).
+
+:- pred bad(io::di, io::uo) is det.
+
+bad(!IO) :-
+    io.write_string("fail\n", !IO).
-- 
2.33.1



More information about the reviews mailing list