Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when methods for mutable attribute do not return a value #4579

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/opers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,9 @@ static Obj DoMutableAttribute(Obj self, Obj obj)

/* call the operation to compute the value */
val = DoOperation1Args( self, obj );

if (val == 0) {
ErrorMayQuit("Method for an attribute must return a value", 0, 0);
}
/* set the value (but not for internal objects) */
if ( ENABLED_ATTR( self ) == 1 && !IS_MUTABLE_OBJ( obj ) ) {
switch ( TNUM_OBJ( obj ) ) {
Expand Down Expand Up @@ -2473,7 +2475,9 @@ static Obj DoVerboseMutableAttribute(Obj self, Obj obj)

/* call the operation to compute the value */
val = DoVerboseOperation1Args( self, obj );

if (val == 0) {
ErrorMayQuit("Method for an attribute must return a value", 0, 0);
}
/* set the value (but not for internal objects) */
if ( ENABLED_ATTR( self ) == 1 && !IS_MUTABLE_OBJ( obj ) ) {
switch ( TNUM_OBJ( obj ) ) {
Expand Down
12 changes: 12 additions & 0 deletions tst/testinstall/oper1.tst
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ gap> List(MethodsOperation(IsMyProperty, 1), x->x.info);
#
gap> RedispatchOnCondition();
Error, Usage: RedispatchOnCondition(oper[,info],fampred,reqs,cond,val)

# Check install methods for operations which do not return a value
gap> MyMutAttribute := NewAttribute( "MyMutAttribute", IsObject, "mutable" );
<Attribute "MyMutAttribute">
gap> MyAttribute := NewAttribute( "MyAttribute", IsObject);
<Attribute "MyAttribute">
gap> InstallMethod(MyAttribute, "for a perm group", [IsPermGroup], function(x) end);
gap> InstallMethod(MyMutAttribute, "for a perm group", [IsPermGroup], function(x) end);
gap> MyAttribute(Group((1,2,3)));
Error, Method for an attribute must return a value
gap> MyMutAttribute(Group((1,2,3)));
Error, Method for an attribute must return a value