[m-rev.] diff: purity warnings test case

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 23 00:44:31 AEDT 2003


On 22-Jan-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> tests/warnings/Mmakefile:
> tests/warnings/purity_warnings.m:
> tests/warnings/purity_warnings.exp:
> 	Add a test case to test purity warnings.

The reason that I wrote this test case was that, based on inspection of
the compiler source code, I though there were some cases that we would
fail to warn about.  Unfortunately the test code that I originally posted
didn't cover those cases.  But it turns out that there are some such
cases.

Hence I have changed the test to cover those cases, and added some XXX
comments mentioning that we ought to issue a warning in those cases.

diff -u tests/warnings/purity_warnings.m tests/warnings/purity_warnings.m
--- tests/warnings/purity_warnings.m	22 Jan 2003 12:42:46 -0000
+++ tests/warnings/purity_warnings.m	22 Jan 2003 13:36:05 -0000
@@ -1,5 +1,5 @@
 % Various checks that impurity declarations are treated properly.
-
+% XXX We miss a couple of things that we should warn about: see the XXXs below.
 :- module purity_warnings.
 :- interface.
 :- import_module io.
@@ -18,22 +18,22 @@
 	impure impure_method1b,
 	impure impure_method2b,
 	semipure semipure_method_b,
-	semipure io__write_string("main 1\n"),
-	impure io__print("main 2\n").
+	semipure io__write_string("main 1\n"),	% warn
+	impure io__print("main 2\n").		% warn
 
-:- impure pred impure_pred1(io__state::di, io__state::uo) is det.
+:- impure pred impure_pred1(io__state::di, io__state::uo) is det. % warn
 impure_pred1 -->
 	io__write_string("impure_pred1\n").
 
-:- impure pred impure_pred2(io__state::di, io__state::uo) is det.
+:- impure pred impure_pred2(io__state::di, io__state::uo) is det. % warn
 impure_pred2 -->
 	io__write_string("impure_pred2\n"),
 	{ semipure get_x(X) },
 	print("X = "), print(X), nl.
 
-:- semipure pred semipure_pred(io__state::di, io__state::uo) is det.
+:- semipure pred semipure_pred(io__state::di, io__state::uo) is det. % warn
 semipure_pred -->
-	semipure io__write_string("semipure_pred1\n").
+	semipure io__write_string("semipure_pred1\n").		% warn
 
 :- typeclass foo(IO) where [
 	(impure pred impure_method1a(IO::di, IO::uo) is det),
@@ -47,26 +47,28 @@
 	pred(impure_method1a/2) is impure_method1a_impl,
 	pred(impure_method2a/2 )is impure_method2a_impl,
 	pred(semipure_method_a/2 )is semipure_method_a_impl,
-	(impure_method1b --> print("impure_method1b\n")),
+	(impure_method1b -->
+		impure print("impure_method1b\n")),	% XXX should warn
 	(impure_method2b -->
 		io__write_string("impure_method2b\n"),
 		{ semipure get_x(X) },
 		print("X = "), print(X), nl),
-	(semipure_method_b --> print("semipure_method_b\n"))
+	(semipure_method_b -->
+		semipure print("semipure_method_b\n"))	% XXX should warn
 ].
 
-:- impure pred impure_method1a_impl(io::di, io::uo) is det.
-:- impure pred impure_method2a_impl(io::di, io::uo) is det.
-:- semipure pred semipure_method_a_impl(io::di, io::uo) is det.
+:- pred impure_method1a_impl(io::di, io::uo) is det.
+:- semipure pred impure_method2a_impl(io::di, io::uo) is det.
+:- pred semipure_method_a_impl(io::di, io::uo) is det.
 
 impure_method1a_impl -->
-	impure print("impure_method1a_impl\n").
+	impure print("impure_method1a_impl\n").		% warn
 impure_method2a_impl -->
 	io__write_string("impure_method2a_impl\n"),
 	{ semipure get_x(X) },
 	print("X = "), print(X), nl.
 semipure_method_a_impl -->
-	semipure print("semipure_method_a_impl\n").
+	semipure print("semipure_method_a_impl\n").	% warn
 
 :- pragma c_header_code("extern int x;").
 :- pragma c_code("int x = 0;").
diff -u tests/warnings/purity_warnings.exp tests/warnings/purity_warnings.exp
--- tests/warnings/purity_warnings.exp	22 Jan 2003 12:44:10 -0000
+++ tests/warnings/purity_warnings.exp	22 Jan 2003 13:29:50 -0000
@@ -16,12 +16,6 @@
-purity_warnings.m:063: In call to predicate `io.print/3':
-purity_warnings.m:063:   warning: unnecessary `impure' indicator.
-purity_warnings.m:063:   No purity indicator is necessary.
-purity_warnings.m:058: In predicate `purity_warnings.impure_method1a_impl/2':
-purity_warnings.m:058:   warning: declared `impure' but actually pure.
-purity_warnings.m:059: In predicate `purity_warnings.impure_method2a_impl/2':
-purity_warnings.m:059:   warning: declared `impure' but actually semipure.
-purity_warnings.m:069: In call to predicate `io.print/3':
-purity_warnings.m:069:   warning: unnecessary `semipure' indicator.
-purity_warnings.m:069:   No purity indicator is necessary.
-purity_warnings.m:060: In predicate `purity_warnings.semipure_method_a_impl/2':
-purity_warnings.m:060:   warning: declared `semipure' but actually pure.
+purity_warnings.m:065: In call to predicate `io.print/3':
+purity_warnings.m:065:   warning: unnecessary `impure' indicator.
+purity_warnings.m:065:   No purity indicator is necessary.
+purity_warnings.m:071: In call to predicate `io.print/3':
+purity_warnings.m:071:   warning: unnecessary `semipure' indicator.
+purity_warnings.m:071:   No purity indicator is necessary.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list