[m-rev.] Improved array error messages

Ralph Becket rafe at cs.mu.OZ.AU
Wed Jan 16 11:56:32 AEDT 2002


Peter Ross, Wednesday, 16 January 2002:
> Ralph wrote:
> > +
> > +    % out_of_bounds_error(OpName, Array, Index) = IndexOutOfBounds.
> > +    %
> > +:- func out_of_bounds_error(string, array(T), int) = index_out_of_bounds.
> > +
> > +out_of_bounds_error(Op, A, I) =
> > +    index_out_of_bounds(
> > +        string__format("%s: array bounds [%d, %d], index %d",
> > +        [s(Op), i(array__min(A)), i(array__max(A)), i(I)])
> >      ).
> >
> I suggest printing out the type of the array which is similar to what is
> done for map lookup failures.

Here's the relative diff:

--- array.m     16 Jan 2002 00:11:07 -0000
+++ array.m     16 Jan 2002 00:54:17 -0000
@@ -1616,8 +1616,11 @@
 
 out_of_bounds_error(Op, A, I) =
     index_out_of_bounds(
-        string__format("%s: array bounds [%d, %d], index %d",
-           [s(Op), i(array__min(A)), i(array__max(A)), i(I)])
+        string__format(
+            "%s: array type %s, bounds [%d, %d], index %d",
+            [s(Op), s(type_name(type_of(A))),
+             i(array__min(A)), i(array__max(A)), i(I)]
+       )
     ).
 
 %------------------------------------------------------------------------------%

--------------------------------------------------------------------------
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