[m-rev.] diff: warnings/trace_goal_dupl_defn.m
Zoltan Somogyi
zs at csse.unimelb.edu.au
Wed Jun 4 13:55:33 AEST 2008
tests/valid/trace_goal_dupl_defn.m:
Add a test case for the error message we get when a trace goal tries to
define something it shouldn't.
tests/valid/Mmakefile:
Note but don't enable the test case yet.
Zoltan.
cvs diff: Diffing .
Index: Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/warnings/Mmakefile,v
retrieving revision 1.44
diff -u -b -r1.44 Mmakefile
--- Mmakefile 20 Jul 2006 01:50:46 -0000 1.44
+++ Mmakefile 4 Jun 2008 03:53:42 -0000
@@ -36,6 +36,9 @@
unused_import \
warn_stubs
+# We don't yet pass (or even have a .exp file for) this test.
+# trace_goal_dupl_defn
+
ifeq ($(MMAKE_USE_MMC_MAKE),yes)
ERRORCHECK_PROGS += unused_args_analysis
endif
Index: trace_goal_dupl_defn.m
===================================================================
RCS file: trace_goal_dupl_defn.m
diff -N trace_goal_dupl_defn.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ trace_goal_dupl_defn.m 29 May 2008 04:22:37 -0000
@@ -0,0 +1,54 @@
+% vim: ts=4 sw=4 et ft=mercury
+%
+% This is a test case for what error message the compiler generates
+% when a trace goal attempts to bind a nonlocal variable.
+
+:- module trace_goal_dupl_defn.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module int.
+:- import_module string.
+
+main(!IO) :-
+ p(42, _, X),
+ io.write_string(X, !IO),
+ io.nl(!IO).
+
+:- pred p(int::in, int::out, string::out) is det.
+
+p(!N, S) :-
+ trace [compiletime(flag("abc")), io(!IO)] (
+ ( is_even(!.N) ->
+ % M is the nonlocal we attempt to bind. It is nonlocal here
+ % because it also appears in the second trace goal.
+ M = !.N,
+ io.write_string("<abc>", !IO),
+ io.write_int(M, !IO),
+ io.write_string("<abc>\n", !IO)
+ ;
+ true
+ )
+ ),
+ S = "xx",
+ trace [compiletime(flag("abc")), io(!IO)] (
+ ( is_even(!.N) ->
+ M = !.N,
+ io.write_string("<abc>", !IO),
+ io.write_int(M, !IO),
+ io.write_string("<abc>\n", !IO)
+ ;
+ true
+ )
+ ).
+
+:- pred is_even(int::in) is semidet.
+
+is_even(N) :-
+ N mod 2 = 0.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list