From 814a0f6e77bbd0472619a588188c1858d5e4e6e3 Mon Sep 17 00:00:00 2001 From: James Williams Date: Wed, 29 Jun 2016 21:46:44 +0100 Subject: [PATCH] Fixed issue 820 and added tests Fixed List so that it complains if it has more than two arguments. Also changed the error type to 'ErrorNoReturn' when the arguments are 0 or greater than 2. Added some additional tests to test the error messages in these cases, and to test some of the other documented features of List, that is, it works for lists with holes, and it returns a mutable list. --- lib/coll.gi | 4 ++-- tst/testinstall/listgen.tst | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/coll.gi b/lib/coll.gi index 5ad14ee5eb..2bf23b5aec 100644 --- a/lib/coll.gi +++ b/lib/coll.gi @@ -727,8 +727,8 @@ InstallGlobalFunction( List, function( arg ) local tnum, C, func, res, i, elm, l; l := Length(arg); - if l = 0 then - Error( "usage: List( [, ] )" ); + if l = 0 or l > 2 then + ErrorNoReturn( "usage: List( [, ] )" ); fi; tnum:= TNUM_OBJ_INT( arg[1] ); if FIRST_LIST_TNUM <= tnum and tnum <= LAST_LIST_TNUM then diff --git a/tst/testinstall/listgen.tst b/tst/testinstall/listgen.tst index 278f262046..bb8eefdae0 100644 --- a/tst/testinstall/listgen.tst +++ b/tst/testinstall/listgen.tst @@ -12,6 +12,14 @@ gap> List( [ 1 .. 10 ], x -> x^2 ); [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ] gap> List( [ 2, 1, 2, 1 ], x -> x - 1 ); [ 1, 0, 1, 0 ] +gap> List(); +Error, usage: List( [, ] ) +gap> List([1..10], x->x^2, "extra argument"); +Error, usage: List( [, ] ) +gap> List([,1,,3,4], x->x>2); +[ , false,, true, true ] +gap> IsMutable(List([1,2,3],x->x^2)); +true gap> Flat( List( [ 1 .. 5 ], x -> [ 1 .. x ] ) ); [ 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5 ] gap> Reversed( [ 1, 2, 1, 2 ] );