[m-rev.] for review: fix dummy type bug in construct.construct
Ian MacLarty
maclarty at cs.mu.OZ.AU
Sat Nov 19 13:59:02 AEDT 2005
For review by Zoltan.
Estimated hours taken: 1
Branches: main
Fix a bug reported by Peter Ross, where dummy type terms could not be
constructed using construct.construct.
library/construct.m:
Change get_functor_ordinal to return 0 for the ordinal number if
the type is a dummy type.
Handle the case where the type_ctor_rep is MR_TYPECTOR_REP_DUMMY
in construct.construct by just setting the value of the new term to 0
(the value of the term should never be looked at).
tests/hard_coded/Mmakefile:
tests/hard_coded/dummy_type_construct.exp:
tests/hard_coded/dummy_type_construct.m:
Add a regression test. Previously this test failed with
"Mercury runtime: bad type_ctor_rep in construct:construct".
Index: library/construct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/construct.m,v
retrieving revision 1.22
diff -u -r1.22 construct.m
--- library/construct.m 19 Sep 2005 04:28:59 -0000 1.22
+++ library/construct.m 19 Nov 2005 02:08:53 -0000
@@ -339,6 +339,7 @@
case MR_TYPECTOR_REP_NOTAG_GROUND:
case MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
case MR_TYPECTOR_REP_TUPLE:
+ case MR_TYPECTOR_REP_DUMMY:
Ordinal = 0;
break;
@@ -590,6 +591,16 @@
}
break;
+ case MR_TYPECTOR_REP_DUMMY:
+ {
+ /*
+ ** The value of the dummy type will never be looked at,
+ ** so just set it to zero.
+ */
+ new_data = (MR_Word) 0;
+ break;
+ }
+
default:
new_data = (MR_Word) 0; /* avoid a warning */
MR_fatal_error(""bad type_ctor_rep in construct:construct"");
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.274
diff -u -r1.274 Mmakefile
--- tests/hard_coded/Mmakefile 3 Nov 2005 07:03:16 -0000 1.274
+++ tests/hard_coded/Mmakefile 19 Nov 2005 02:37:46 -0000
@@ -47,6 +47,7 @@
dos \
dot_separator \
dst_test \
+ dummy_type_construct \
dupcall_impurity \
dupcall_types_bug \
elim_special_pred \
Index: tests/hard_coded/dummy_type_construct.exp
===================================================================
RCS file: tests/hard_coded/dummy_type_construct.exp
diff -N tests/hard_coded/dummy_type_construct.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/dummy_type_construct.exp 19 Nov 2005 02:54:38 -0000
@@ -0,0 +1,5 @@
+univ_cons(dummy)
+Unable to construct type.
+0
+get_functor_ordinal failed.
+Functor = dummy, Arity = 0, Args = []
Index: tests/hard_coded/dummy_type_construct.m
===================================================================
RCS file: tests/hard_coded/dummy_type_construct.m
diff -N tests/hard_coded/dummy_type_construct.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/dummy_type_construct.m 19 Nov 2005 02:54:15 -0000
@@ -0,0 +1,38 @@
+:- module dummy_type_construct.
+:- interface.
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+:- implementation.
+
+:- import_module construct, type_desc, list, string, deconstruct.
+
+:- type dummy ---> dummy.
+
+main(!IO) :-
+ ( DummyVal1 = construct.construct(type_of(_:dummy), 0, []) ->
+ io.write(DummyVal1, !IO)
+ ;
+ io.write_string("Unable to construct type.", !IO)
+ ),
+ io.nl(!IO),
+ ( DummyVal2 = construct.construct(type_of(_:dummy), 1, []) ->
+ io.write(DummyVal2, !IO)
+ ;
+ io.write_string("Unable to construct type.", !IO)
+ ),
+ io.nl(!IO),
+ ( get_functor_ordinal(type_of(_:dummy), 0, Ordinal1) ->
+ io.write_int(Ordinal1, !IO)
+ ;
+ io.write_string("get_functor_ordinal failed.", !IO)
+ ),
+ io.nl(!IO),
+ ( get_functor_ordinal(type_of(_:dummy), 1, Ordinal2) ->
+ io.write_int(Ordinal2, !IO)
+ ;
+ io.write_string("get_functor_ordinal failed.", !IO)
+ ),
+ io.nl(!IO),
+ deconstruct.deconstruct(dummy, canonicalize, Functor, Arity, Args),
+ io.format("Functor = %s, Arity = %i, Args = %s\n", [
+ s(Functor), i(Arity), s(string.string(Args))], !IO).
--------------------------------------------------------------------------
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