From fa5444760e3a16de3380e856b1f620f506e007c7 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 14 Aug 2018 14:05:35 +0200 Subject: [PATCH] Forbid constructors with 0 arguments Constructors with 0 arguments make no sense. Thus, forbid creating such constructors, and also forbid installing zero argument methods for constructors. --- lib/oper.g | 7 ++- lib/oper1.g | 5 +- src/c_oper1.c | 95 ++++++++++++++++++--------------- src/hpc/c_oper1.c | 95 ++++++++++++++++++--------------- src/opers.c | 40 +++++++------- tst/testinstall/constructor.tst | 27 ++++++++++ tst/testinstall/varargs.tst | 2 +- tst/testspecial/trace.g | 6 +-- tst/testspecial/trace.g.out | 24 ++++----- 9 files changed, 173 insertions(+), 128 deletions(-) create mode 100644 tst/testinstall/constructor.tst diff --git a/lib/oper.g b/lib/oper.g index b642d809ce..0623169370 100644 --- a/lib/oper.g +++ b/lib/oper.g @@ -773,6 +773,9 @@ end ); BIND_GLOBAL( "NewConstructor", function ( name, filters ) local oper, filt, filter; + if LEN_LIST( filters ) = 0 then + Error( "constructors must have at least one argument" ); + fi; if GAPInfo.MaxNrArgsMethod < LEN_LIST( filters ) then Error( "methods can have at most ", GAPInfo.MaxNrArgsMethod, " arguments" ); @@ -944,7 +947,9 @@ BIND_GLOBAL( "DeclareConstructor", function ( name, filters ) local gvar, req, filt, filter; - if GAPInfo.MaxNrArgsMethod < LEN_LIST( filters ) then + if LEN_LIST( filters ) = 0 then + Error( "constructors must have at least one argument" ); + elif GAPInfo.MaxNrArgsMethod < LEN_LIST( filters ) then Error( "methods can have at most ", GAPInfo.MaxNrArgsMethod, " arguments" ); elif ISB_GVAR( name ) then diff --git a/lib/oper1.g b/lib/oper1.g index 5ae4ecd52f..71067774e0 100644 --- a/lib/oper1.g +++ b/lib/oper1.g @@ -153,9 +153,10 @@ BIND_GLOBAL( "INSTALL_METHOD_FLAGS", fi; # add the number of filters required for each argument if IS_CONSTRUCTOR(opr) then - if 0 < LEN_LIST(flags) then - rank := rank - RankFilter( flags[ 1 ] ); + if 0 = LEN_LIST(flags) then + Error(NAME_FUNC(opr),": constructors must have at least one argument"); fi; + rank := rank - RankFilter( flags[ 1 ] ); else for i in flags do rank := rank + RankFilter( i ); diff --git a/src/c_oper1.c b/src/c_oper1.c index 35886bdeb8..aeb413b27f 100644 --- a/src/c_oper1.c +++ b/src/c_oper1.c @@ -1,7 +1,7 @@ #ifndef AVOID_PRECOMPILED /* C file produced by GAC */ #include "compiled.h" -#define FILE_CRC "93694864" +#define FILE_CRC "32938550" /* global variables used in handlers */ static GVar G_REREADING; @@ -646,24 +646,32 @@ static Obj HdlrFunc3 ( t_1 = (Obj)(UInt)(t_2 != False); if ( t_1 ) { - /* if 0 < LEN_LIST( flags ) then */ + /* if 0 = LEN_LIST( flags ) then */ t_3 = GF_LEN__LIST; t_2 = CALL_1ARGS( t_3, a_flags ); CHECK_FUNC_RESULT( t_2 ) - t_1 = (Obj)(UInt)(LT( INTOBJ_INT(0), t_2 )); + t_1 = (Obj)(UInt)(EQ( INTOBJ_INT(0), t_2 )); if ( t_1 ) { - /* rank := rank - RankFilter( flags[1] ); */ - t_3 = GF_RankFilter; - C_ELM_LIST_FPL( t_4, a_flags, INTOBJ_INT(1) ) - t_2 = CALL_1ARGS( t_3, t_4 ); + /* Error( NAME_FUNC( opr ), ": constructors must have at least one argument" ); */ + t_1 = GF_Error; + t_3 = GF_NAME__FUNC; + t_2 = CALL_1ARGS( t_3, a_opr ); CHECK_FUNC_RESULT( t_2 ) - C_DIFF_FIA( t_1, a_rank, t_2 ) - a_rank = t_1; + t_3 = MakeString( ": constructors must have at least one argument" ); + CALL_2ARGS( t_1, t_2, t_3 ); } /* fi */ + /* rank := rank - RankFilter( flags[1] ); */ + t_3 = GF_RankFilter; + C_ELM_LIST_FPL( t_4, a_flags, INTOBJ_INT(1) ) + t_2 = CALL_1ARGS( t_3, t_4 ); + CHECK_FUNC_RESULT( t_2 ) + C_DIFF_FIA( t_1, a_rank, t_2 ) + a_rank = t_1; + } /* else */ @@ -2685,8 +2693,8 @@ static Obj HdlrFunc7 ( t_6 = NewFunction( NameFunc[8], 1, 0, HdlrFunc8 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 651); - SET_ENDLINE_BODY(t_7, 669); + SET_STARTLINE_BODY(t_7, 652); + SET_ENDLINE_BODY(t_7, 670); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3289,8 +3297,8 @@ static Obj HdlrFunc11 ( t_1 = NewFunction( NameFunc[12], 1, 0, HdlrFunc12 ); SET_ENVI_FUNC( t_1, STATE(CurrLVars) ); t_2 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_2, 848); - SET_ENDLINE_BODY(t_2, 852); + SET_STARTLINE_BODY(t_2, 849); + SET_ENDLINE_BODY(t_2, 853); SET_FILENAME_BODY(t_2, FileName); SET_BODY_FUNC(t_1, t_2); CHANGED_BAG( STATE(CurrLVars) ); @@ -3369,8 +3377,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[13], 1, 0, HdlrFunc13 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 869); - SET_ENDLINE_BODY(t_7, 869); + SET_STARTLINE_BODY(t_7, 870); + SET_ENDLINE_BODY(t_7, 870); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3432,8 +3440,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[14], 2, 0, HdlrFunc14 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 891); - SET_ENDLINE_BODY(t_7, 914); + SET_STARTLINE_BODY(t_7, 892); + SET_ENDLINE_BODY(t_7, 915); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3481,8 +3489,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[15], 2, 0, HdlrFunc15 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 924); - SET_ENDLINE_BODY(t_7, 932); + SET_STARTLINE_BODY(t_7, 925); + SET_ENDLINE_BODY(t_7, 933); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3543,8 +3551,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[16], 3, 0, HdlrFunc16 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 941); - SET_ENDLINE_BODY(t_7, 954); + SET_STARTLINE_BODY(t_7, 942); + SET_ENDLINE_BODY(t_7, 955); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3917,8 +3925,8 @@ static Obj HdlrFunc17 ( t_4 = NewFunction( NameFunc[18], -1, 0, HdlrFunc18 ); SET_ENVI_FUNC( t_4, STATE(CurrLVars) ); t_5 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_5, 1020); - SET_ENDLINE_BODY(t_5, 1036); + SET_STARTLINE_BODY(t_5, 1021); + SET_ENDLINE_BODY(t_5, 1037); SET_FILENAME_BODY(t_5, FileName); SET_BODY_FUNC(t_4, t_5); CHANGED_BAG( STATE(CurrLVars) ); @@ -4030,9 +4038,10 @@ static Obj HdlrFunc1 ( local methods, narg, i, k, tmp, replace, match, j, lk; ; if IS_CONSTRUCTOR( opr ) then - if 0 < LEN_LIST( flags ) then - rank := rank - RankFilter( flags[1] ); + if 0 = LEN_LIST( flags ) then + Error( NAME_FUNC( opr ), ": constructors must have at least one argument" ); fi; + rank := rank - RankFilter( flags[1] ); else for i in flags do rank := rank + RankFilter( i ); @@ -4122,7 +4131,7 @@ static Obj HdlrFunc1 ( SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); SET_STARTLINE_BODY(t_4, 146); - SET_ENDLINE_BODY(t_4, 273); + SET_ENDLINE_BODY(t_4, 274); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4137,8 +4146,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[4], -1, 0, HdlrFunc4 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 320); - SET_ENDLINE_BODY(t_4, 322); + SET_STARTLINE_BODY(t_4, 321); + SET_ENDLINE_BODY(t_4, 323); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4153,8 +4162,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[5], -1, 0, HdlrFunc5 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 347); - SET_ENDLINE_BODY(t_4, 349); + SET_STARTLINE_BODY(t_4, 348); + SET_ENDLINE_BODY(t_4, 350); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4323,8 +4332,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[6], 2, 0, HdlrFunc6 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 360); - SET_ENDLINE_BODY(t_4, 590); + SET_STARTLINE_BODY(t_4, 361); + SET_ENDLINE_BODY(t_4, 591); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4382,8 +4391,8 @@ static Obj HdlrFunc1 ( t_2 = NewFunction( NameFunc[7], 6, 0, HdlrFunc7 ); SET_ENVI_FUNC( t_2, STATE(CurrLVars) ); t_3 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_3, 609); - SET_ENDLINE_BODY(t_3, 673); + SET_STARTLINE_BODY(t_3, 610); + SET_ENDLINE_BODY(t_3, 674); SET_FILENAME_BODY(t_3, FileName); SET_BODY_FUNC(t_2, t_3); CHANGED_BAG( STATE(CurrLVars) ); @@ -4397,8 +4406,8 @@ static Obj HdlrFunc1 ( t_2 = NewFunction( NameFunc[9], 6, 0, HdlrFunc9 ); SET_ENVI_FUNC( t_2, STATE(CurrLVars) ); t_3 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_3, 676); - SET_ENDLINE_BODY(t_3, 682); + SET_STARTLINE_BODY(t_3, 677); + SET_ENDLINE_BODY(t_3, 683); SET_FILENAME_BODY(t_3, FileName); SET_BODY_FUNC(t_2, t_3); CHANGED_BAG( STATE(CurrLVars) ); @@ -4426,8 +4435,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[10], 2, 0, HdlrFunc10 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 695); - SET_ENDLINE_BODY(t_4, 719); + SET_STARTLINE_BODY(t_4, 696); + SET_ENDLINE_BODY(t_4, 720); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4511,8 +4520,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[11], 4, 0, HdlrFunc11 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 844); - SET_ENDLINE_BODY(t_4, 955); + SET_STARTLINE_BODY(t_4, 845); + SET_ENDLINE_BODY(t_4, 956); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4563,8 +4572,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[17], -1, 0, HdlrFunc17 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 990); - SET_ENDLINE_BODY(t_4, 1037); + SET_STARTLINE_BODY(t_4, 991); + SET_ENDLINE_BODY(t_4, 1038); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4871,7 +4880,7 @@ static Int InitLibrary ( StructInitInfo * module ) static StructInitInfo module = { .type = MODULE_STATIC, .name = "GAPROOT/lib/oper1.g", - .crc = 93694864, + .crc = 32938550, .initKernel = InitKernel, .initLibrary = InitLibrary, .postRestore = PostRestore, diff --git a/src/hpc/c_oper1.c b/src/hpc/c_oper1.c index d9962694e9..1c5ef2b2ab 100644 --- a/src/hpc/c_oper1.c +++ b/src/hpc/c_oper1.c @@ -1,7 +1,7 @@ #ifndef AVOID_PRECOMPILED /* C file produced by GAC */ #include "compiled.h" -#define FILE_CRC "93694864" +#define FILE_CRC "32938550" /* global variables used in handlers */ static GVar G_REREADING; @@ -670,24 +670,32 @@ static Obj HdlrFunc3 ( t_1 = (Obj)(UInt)(t_2 != False); if ( t_1 ) { - /* if 0 < LEN_LIST( flags ) then */ + /* if 0 = LEN_LIST( flags ) then */ t_3 = GF_LEN__LIST; t_2 = CALL_1ARGS( t_3, a_flags ); CHECK_FUNC_RESULT( t_2 ) - t_1 = (Obj)(UInt)(LT( INTOBJ_INT(0), t_2 )); + t_1 = (Obj)(UInt)(EQ( INTOBJ_INT(0), t_2 )); if ( t_1 ) { - /* rank := rank - RankFilter( flags[1] ); */ - t_3 = GF_RankFilter; - C_ELM_LIST_FPL( t_4, a_flags, INTOBJ_INT(1) ) - t_2 = CALL_1ARGS( t_3, t_4 ); + /* Error( NAME_FUNC( opr ), ": constructors must have at least one argument" ); */ + t_1 = GF_Error; + t_3 = GF_NAME__FUNC; + t_2 = CALL_1ARGS( t_3, a_opr ); CHECK_FUNC_RESULT( t_2 ) - C_DIFF_FIA( t_1, a_rank, t_2 ) - a_rank = t_1; + t_3 = MakeString( ": constructors must have at least one argument" ); + CALL_2ARGS( t_1, t_2, t_3 ); } /* fi */ + /* rank := rank - RankFilter( flags[1] ); */ + t_3 = GF_RankFilter; + C_ELM_LIST_FPL( t_4, a_flags, INTOBJ_INT(1) ) + t_2 = CALL_1ARGS( t_3, t_4 ); + CHECK_FUNC_RESULT( t_2 ) + C_DIFF_FIA( t_1, a_rank, t_2 ) + a_rank = t_1; + } /* else */ @@ -2748,8 +2756,8 @@ static Obj HdlrFunc7 ( t_6 = NewFunction( NameFunc[8], 1, 0, HdlrFunc8 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 651); - SET_ENDLINE_BODY(t_7, 669); + SET_STARTLINE_BODY(t_7, 652); + SET_ENDLINE_BODY(t_7, 670); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3352,8 +3360,8 @@ static Obj HdlrFunc11 ( t_1 = NewFunction( NameFunc[12], 1, 0, HdlrFunc12 ); SET_ENVI_FUNC( t_1, STATE(CurrLVars) ); t_2 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_2, 848); - SET_ENDLINE_BODY(t_2, 852); + SET_STARTLINE_BODY(t_2, 849); + SET_ENDLINE_BODY(t_2, 853); SET_FILENAME_BODY(t_2, FileName); SET_BODY_FUNC(t_1, t_2); CHANGED_BAG( STATE(CurrLVars) ); @@ -3432,8 +3440,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[13], 1, 0, HdlrFunc13 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 869); - SET_ENDLINE_BODY(t_7, 869); + SET_STARTLINE_BODY(t_7, 870); + SET_ENDLINE_BODY(t_7, 870); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3507,8 +3515,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[14], 2, 0, HdlrFunc14 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 891); - SET_ENDLINE_BODY(t_7, 914); + SET_STARTLINE_BODY(t_7, 892); + SET_ENDLINE_BODY(t_7, 915); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3556,8 +3564,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[15], 2, 0, HdlrFunc15 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 924); - SET_ENDLINE_BODY(t_7, 932); + SET_STARTLINE_BODY(t_7, 925); + SET_ENDLINE_BODY(t_7, 933); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3618,8 +3626,8 @@ static Obj HdlrFunc11 ( t_6 = NewFunction( NameFunc[16], 3, 0, HdlrFunc16 ); SET_ENVI_FUNC( t_6, STATE(CurrLVars) ); t_7 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_7, 941); - SET_ENDLINE_BODY(t_7, 954); + SET_STARTLINE_BODY(t_7, 942); + SET_ENDLINE_BODY(t_7, 955); SET_FILENAME_BODY(t_7, FileName); SET_BODY_FUNC(t_6, t_7); CHANGED_BAG( STATE(CurrLVars) ); @@ -3992,8 +4000,8 @@ static Obj HdlrFunc17 ( t_4 = NewFunction( NameFunc[18], -1, 0, HdlrFunc18 ); SET_ENVI_FUNC( t_4, STATE(CurrLVars) ); t_5 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_5, 1020); - SET_ENDLINE_BODY(t_5, 1036); + SET_STARTLINE_BODY(t_5, 1021); + SET_ENDLINE_BODY(t_5, 1037); SET_FILENAME_BODY(t_5, FileName); SET_BODY_FUNC(t_4, t_5); CHANGED_BAG( STATE(CurrLVars) ); @@ -4114,9 +4122,10 @@ static Obj HdlrFunc1 ( local methods, narg, i, k, tmp, replace, match, j, lk; lk := WRITE_LOCK( METHODS_OPERATION_REGION ); if IS_CONSTRUCTOR( opr ) then - if 0 < LEN_LIST( flags ) then - rank := rank - RankFilter( flags[1] ); + if 0 = LEN_LIST( flags ) then + Error( NAME_FUNC( opr ), ": constructors must have at least one argument" ); fi; + rank := rank - RankFilter( flags[1] ); else for i in flags do rank := rank + RankFilter( i ); @@ -4207,7 +4216,7 @@ static Obj HdlrFunc1 ( SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); SET_STARTLINE_BODY(t_4, 146); - SET_ENDLINE_BODY(t_4, 273); + SET_ENDLINE_BODY(t_4, 274); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4222,8 +4231,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[4], -1, 0, HdlrFunc4 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 320); - SET_ENDLINE_BODY(t_4, 322); + SET_STARTLINE_BODY(t_4, 321); + SET_ENDLINE_BODY(t_4, 323); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4238,8 +4247,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[5], -1, 0, HdlrFunc5 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 347); - SET_ENDLINE_BODY(t_4, 349); + SET_STARTLINE_BODY(t_4, 348); + SET_ENDLINE_BODY(t_4, 350); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4408,8 +4417,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[6], 2, 0, HdlrFunc6 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 360); - SET_ENDLINE_BODY(t_4, 590); + SET_STARTLINE_BODY(t_4, 361); + SET_ENDLINE_BODY(t_4, 591); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4467,8 +4476,8 @@ static Obj HdlrFunc1 ( t_2 = NewFunction( NameFunc[7], 6, 0, HdlrFunc7 ); SET_ENVI_FUNC( t_2, STATE(CurrLVars) ); t_3 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_3, 609); - SET_ENDLINE_BODY(t_3, 673); + SET_STARTLINE_BODY(t_3, 610); + SET_ENDLINE_BODY(t_3, 674); SET_FILENAME_BODY(t_3, FileName); SET_BODY_FUNC(t_2, t_3); CHANGED_BAG( STATE(CurrLVars) ); @@ -4482,8 +4491,8 @@ static Obj HdlrFunc1 ( t_2 = NewFunction( NameFunc[9], 6, 0, HdlrFunc9 ); SET_ENVI_FUNC( t_2, STATE(CurrLVars) ); t_3 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_3, 676); - SET_ENDLINE_BODY(t_3, 682); + SET_STARTLINE_BODY(t_3, 677); + SET_ENDLINE_BODY(t_3, 683); SET_FILENAME_BODY(t_3, FileName); SET_BODY_FUNC(t_2, t_3); CHANGED_BAG( STATE(CurrLVars) ); @@ -4511,8 +4520,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[10], 2, 0, HdlrFunc10 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 695); - SET_ENDLINE_BODY(t_4, 719); + SET_STARTLINE_BODY(t_4, 696); + SET_ENDLINE_BODY(t_4, 720); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4596,8 +4605,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[11], 4, 0, HdlrFunc11 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 844); - SET_ENDLINE_BODY(t_4, 955); + SET_STARTLINE_BODY(t_4, 845); + SET_ENDLINE_BODY(t_4, 956); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4648,8 +4657,8 @@ static Obj HdlrFunc1 ( t_3 = NewFunction( NameFunc[17], -1, 0, HdlrFunc17 ); SET_ENVI_FUNC( t_3, STATE(CurrLVars) ); t_4 = NewBag( T_BODY, sizeof(BodyHeader) ); - SET_STARTLINE_BODY(t_4, 990); - SET_ENDLINE_BODY(t_4, 1037); + SET_STARTLINE_BODY(t_4, 991); + SET_ENDLINE_BODY(t_4, 1038); SET_FILENAME_BODY(t_4, FileName); SET_BODY_FUNC(t_3, t_4); CHANGED_BAG( STATE(CurrLVars) ); @@ -4972,7 +4981,7 @@ static Int InitLibrary ( StructInitInfo * module ) static StructInitInfo module = { .type = MODULE_STATIC, .name = "GAPROOT/lib/oper1.g", - .crc = 93694864, + .crc = 32938550, .initKernel = InitKernel, .initLibrary = InitLibrary, .postRestore = PostRestore, diff --git a/src/opers.c b/src/opers.c index 2e42d27847..b585fbbd93 100644 --- a/src/opers.c +++ b/src/opers.c @@ -2341,16 +2341,20 @@ Obj NewOperation(Obj name, Int narg, Obj nams, ObjFunc hdlr) /**************************************************************************** ** -** DoConstructor0Args( ) -** -** I'm not sure if this makes any sense at all +*F DoConstructor0Args( ) +*F DoConstructor1Args( ) +*F DoConstructor2Args( ) +*F DoConstructor3Args( ) +*F DoConstructor4Args( ) +*F DoConstructor5Args( ) +*F DoConstructor6Args( ) +*F DoConstructorXArgs( ) */ - Obj DoConstructor0Args(Obj oper) { - return DoOperationNArgs(oper, 0, 0, 1, 0, 0, 0, 0, - 0, 0); + ErrorQuit("constructors must have at least one argument", 0L, 0L); + return 0; } Obj DoConstructor1Args(Obj oper, Obj arg1) @@ -2391,26 +2395,29 @@ Obj DoConstructor6Args( arg3, arg4, arg5, arg6); } - -/**************************************************************************** -** -** DoConstructorXArgs( , ... ) -*/ Obj DoConstructorXArgs(Obj self, Obj args) { ErrorQuit("sorry: cannot yet have X argument constructors", 0L, 0L); return 0; } + /**************************************************************************** ** -** DoVerboseConstructor0Args( ) +*F DoVerboseConstructor0Args( ) +*F DoVerboseConstructor1Args( ) +*F DoVerboseConstructor2Args( ) +*F DoVerboseConstructor3Args( ) +*F DoVerboseConstructor4Args( ) +*F DoVerboseConstructor5Args( ) +*F DoVerboseConstructor6Args( ) +*F DoVerboseConstructorXArgs( ) */ Obj DoVerboseConstructor0Args(Obj oper) { - return DoOperationNArgs(oper, 0, 1, 1, 0, 0, - 0, 0, 0, 0); + ErrorQuit("constructors must have at least one argument", 0L, 0L); + return 0; } Obj DoVerboseConstructor1Args(Obj oper, Obj arg1) @@ -2452,11 +2459,6 @@ Obj DoVerboseConstructor6Args( arg2, arg3, arg4, arg5, arg6); } - -/**************************************************************************** -** -** DoVerboseConstructorXArgs( , ... ) -*/ Obj DoVerboseConstructorXArgs(Obj self, Obj args) { ErrorQuit("sorry: cannot yet have X argument constructors", 0L, 0L); diff --git a/tst/testinstall/constructor.tst b/tst/testinstall/constructor.tst new file mode 100644 index 0000000000..e711616bc8 --- /dev/null +++ b/tst/testinstall/constructor.tst @@ -0,0 +1,27 @@ +# constructors with zero arguments cannot be created +gap> DeclareConstructor("foobar",[]); +Error, constructors must have at least one argument +gap> NewConstructor("foobar",[]); +Error, constructors must have at least one argument + +# +gap> c := NewConstructor("foobar",[IsObject]); + +gap> c(1); +Error, Constructor: the first argument must be a filter not a integer +gap> c(IsInt); +Error, no method found! For debugging hints type ?Recovery from NoMethodFound +Error, no 1st choice method found for `foobar' on 1 arguments +gap> InstallMethod(c,[IsInt],x->x); +gap> c(IsInt); + +gap> InstallOtherMethod(c,[IsInt,IsObject],{x,y}->[x,y]); +gap> c(IsInt, 0); +[ , 0 ] + +# constructors must not have methods with zero arguments, nor is it ever legal +# to invoke a constructor with zero arguments +gap> InstallOtherMethod(c,[],{}->[]); +Error, foobar: constructors must have at least one argument +gap> c(); +Error, constructors must have at least one argument diff --git a/tst/testinstall/varargs.tst b/tst/testinstall/varargs.tst index 1038e5db22..f31c64b2ac 100644 --- a/tst/testinstall/varargs.tst +++ b/tst/testinstall/varargs.tst @@ -87,7 +87,7 @@ function ( <>, <>, <>, <>, <>, <> ) end gap> Display(InstallMethod); function ( <>... ) - <> + <> end gap> [1..2]; [ 1, 2 ] diff --git a/tst/testspecial/trace.g b/tst/testspecial/trace.g index 39dcf5992e..62a47b251a 100644 --- a/tst/testspecial/trace.g +++ b/tst/testspecial/trace.g @@ -50,8 +50,7 @@ o(1,2,3,4,5,6,7); # not (yet?) supported # # create a dummy constructor -o:=NewConstructor("foobar",[]); -InstallOtherMethod(o,[],{}->[]); +o:=NewConstructor("foobar",[IsObject]); InstallOtherMethod(o,[IsInt],{arg...}->arg); InstallOtherMethod(o,[IsInt,IsInt],{arg...}->arg); InstallOtherMethod(o,[IsInt,IsInt],{arg...}->arg); @@ -61,7 +60,6 @@ InstallOtherMethod(o,[IsInt,IsInt,IsInt,IsInt,IsInt],{arg...}->arg); InstallOtherMethod(o,[IsInt,IsInt,IsInt,IsInt,IsInt,IsInt],{arg...}->arg); # without tracing -#o(); # ??? o(IsInt); o(IsInt,2); o(IsInt,2,3); @@ -72,7 +70,6 @@ o(IsInt,2,3,4,5,6,7); # not (yet?) supported # with tracing TraceMethods( o ); -#o(); # ??? o(IsInt); o(IsInt,2); o(IsInt,2,3); @@ -83,7 +80,6 @@ o(IsInt,2,3,4,5,6,7); # not (yet?) supported UntraceMethods( o ); # again without tracing -#o(); # ??? o(IsInt); o(IsInt,2); o(IsInt,2,3); diff --git a/tst/testspecial/trace.g.out b/tst/testspecial/trace.g.out index 06f37aeb4a..844962b4d0 100644 --- a/tst/testspecial/trace.g.out +++ b/tst/testspecial/trace.g.out @@ -85,9 +85,8 @@ gap> # tracing of constructors gap> # gap> gap> # create a dummy constructor -gap> o:=NewConstructor("foobar",[]); +gap> o:=NewConstructor("foobar",[IsObject]); -gap> InstallOtherMethod(o,[],{}->[]); gap> InstallOtherMethod(o,[IsInt],{arg...}->arg); gap> InstallOtherMethod(o,[IsInt,IsInt],{arg...}->arg); gap> InstallOtherMethod(o,[IsInt,IsInt],{arg...}->arg); @@ -97,7 +96,6 @@ gap> InstallOtherMethod(o,[IsInt,IsInt,IsInt,IsInt,IsInt],{arg...}->arg); gap> InstallOtherMethod(o,[IsInt,IsInt,IsInt,IsInt,IsInt,IsInt],{arg...}->arg); gap> gap> # without tracing -gap> #o(); # ??? gap> o(IsInt); [ ] gap> o(IsInt,2); @@ -112,36 +110,34 @@ gap> o(IsInt,2,3,4,5,6); [ , 2, 3, 4, 5, 6 ] gap> o(IsInt,2,3,4,5,6,7); # not (yet?) supported Error, sorry: cannot yet have X argument constructors -not in any function at *stdin*:72 +not in any function at *stdin*:70 gap> gap> # with tracing gap> TraceMethods( o ); -gap> #o(); # ??? gap> o(IsInt); -#I foobar at *stdin*:56 +#I foobar at *stdin*:55 [ ] gap> o(IsInt,2); -#I foobar at *stdin*:58 +#I foobar at *stdin*:57 [ , 2 ] gap> o(IsInt,2,3); -#I foobar at *stdin*:59 +#I foobar at *stdin*:58 [ , 2, 3 ] gap> o(IsInt,2,3,4); -#I foobar at *stdin*:60 +#I foobar at *stdin*:59 [ , 2, 3, 4 ] gap> o(IsInt,2,3,4,5); -#I foobar at *stdin*:61 +#I foobar at *stdin*:60 [ , 2, 3, 4, 5 ] gap> o(IsInt,2,3,4,5,6); -#I foobar at *stdin*:62 +#I foobar at *stdin*:61 [ , 2, 3, 4, 5, 6 ] gap> o(IsInt,2,3,4,5,6,7); # not (yet?) supported Error, sorry: cannot yet have X argument constructors -not in any function at *stdin*:83 +not in any function at *stdin*:80 gap> UntraceMethods( o ); gap> gap> # again without tracing -gap> #o(); # ??? gap> o(IsInt); [ ] gap> o(IsInt,2); @@ -156,5 +152,5 @@ gap> o(IsInt,2,3,4,5,6); [ , 2, 3, 4, 5, 6 ] gap> o(IsInt,2,3,4,5,6,7); # not (yet?) supported Error, sorry: cannot yet have X argument constructors -not in any function at *stdin*:94 +not in any function at *stdin*:90 gap> QUIT;