for review: prevent compiler aborts for uu types
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Aug 26 15:08:19 AEST 1998
Prevent compiler aborts by preventing uu types from reaching any pass after
the front end. You can get such types when you unintentionally use the
syntax reserved for undiscriminated union types, by writing
:- type type1 = type2.
instead of
:- type type1 == type2.
This fixes a problem reported by Bart.
compiler/make_hlds.m:
Handle references to uu types as errors, not warnings. Change the
message accordingly.
tests/warnings/uu_type.{m,exp}:
A test case for the new handling of uu types, contributed by Bart.
tests/warnings/Mmakefile:
Enable the test case.
tests/invalid/bigtest.err_exp:
Update expected error message.
Zoltan.
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.271
diff -u -u -r1.271 make_hlds.m
--- make_hlds.m 1998/08/07 00:49:03 1.271
+++ make_hlds.m 1998/08/19 05:22:35
@@ -1006,8 +1006,9 @@
io__stderr_stream(StdErr),
io__set_output_stream(StdErr, OldStream),
prog_out__write_context(Context),
- report_warning(StdErr,
- "Warning: undiscriminated union types (`+') not implemented.\n"),
+ io__write_string(
+ "Sorry, not implemented: undiscriminated union type.\n"),
+ io__set_exit_status(1),
io__set_output_stream(OldStream, _)
;
% XXX we can't handle abstract exported
Index: tests/invalid/bigtest.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/bigtest.err_exp,v
retrieving revision 1.1
diff -u -u -r1.1 bigtest.err_exp
--- bigtest.err_exp 1996/11/04 07:14:34 1.1
+++ bigtest.err_exp 1998/08/20 06:50:16
@@ -4,7 +4,7 @@
bigtest.m:001: Warning: declaration not yet implemented.
bigtest.m:002: Warning: declaration not yet implemented.
bigtest.m:003: Warning: declaration not yet implemented.
-bigtest.m:016: Warning: undiscriminated union types (`+') not implemented.
+bigtest.m:016: Sorry, not implemented: undiscriminated union type.
bigtest.m:005: Error: clause for predicate `bigtest:fact/0'
bigtest.m:005: without preceding `pred' declaration.
bigtest.m:005: Inferred :- pred fact.
Index: tests/warnings/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/warnings/Mmakefile,v
retrieving revision 1.2
diff -u -u -r1.2 Mmakefile
--- Mmakefile 1998/08/07 04:42:10 1.2
+++ Mmakefile 1998/08/21 06:42:19
@@ -14,7 +14,8 @@
simple_code \
singleton_test \
unused_args_test \
- unused_import
+ unused_import \
+ uu_type
#-----------------------------------------------------------------------------#
@@ -25,6 +26,10 @@
MCFLAGS-unused_import = --warn-interface-imports
#-----------------------------------------------------------------------------#
+
+# the compilation of uu_type is expected to yield a non-zero exit status
+uu_type.err: uu_type.m
+ -mmc --errorcheck-only uu_type.m > uu_type.err 2>&1
%.res: %.exp %.err
-rm -f $@
Index: tests/warnings/uu_type.exp
===================================================================
RCS file: uu_type.exp
diff -N uu_type.exp
--- /dev/null Wed May 28 10:49:58 1997
+++ uu_type.exp Wed Aug 19 15:28:34 1998
@@ -0,0 +1,2 @@
+uu_type.m:022: Sorry, not implemented: undiscriminated union type.
+For more information, try recompiling with `-E'.
Index: tests/warnings/uu_type.m
===================================================================
RCS file: uu_type.m
diff -N uu_type.m
--- /dev/null Wed May 28 10:49:58 1997
+++ uu_type.m Wed Aug 19 15:17:23 1998
@@ -0,0 +1,24 @@
+% This test case checks the handling of a situation in which a user uses
+% = instead of == in a type equivalence, and thus unwittingly triggers code
+% inside the compiler that considers this to be the introduction of an
+% undiscriminated union type.
+%
+% This test case was contributed by Bart Demoen.
+
+:- module uu_type.
+
+:- interface.
+
+:- type hiddenrenamedtype.
+
+:- pred gen(hiddentype::out) is det.
+
+:- implementation.
+
+:- import_module int.
+
+:- type hiddentype ---> (f(int) ; g(int)).
+
+:- type hiddenrenamedtype = hiddentype.
+
+gen(f(4)).
More information about the developers
mailing list