Skip to content

Commit

Permalink
Objectify: warn if Is{Component,Positional}ObjectRep absent
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Dec 19, 2022
1 parent 999f835 commit 2d07ffc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
29 changes: 18 additions & 11 deletions lib/type1.g
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,6 @@ BIND_GLOBAL( "FlagsObj", obj -> FlagsType( TypeObj( obj ) ) );
BIND_GLOBAL( "DataObj", obj -> DataType( TypeObj( obj ) ) );


BIND_GLOBAL( "IsNonAtomicComponentObjectRepFlags",
FLAGS_FILTER(IsNonAtomicComponentObjectRep));
BIND_GLOBAL( "IsAtomicPositionalObjectRepFlags",
FLAGS_FILTER(IsAtomicPositionalObjectRep));
BIND_GLOBAL( "IsReadOnlyPositionalObjectRepFlags",
FLAGS_FILTER(IsReadOnlyPositionalObjectRep));

#############################################################################
##
#F Objectify( <type>, <obj> )
Expand All @@ -592,26 +585,40 @@ BIND_GLOBAL( "Objectify", function ( type, obj )
if not IsType( type ) then
Error("<type> must be a type");
fi;
flags := FlagsType(type);
if IsHPCGAP then
flags := FlagsType(type);
if IS_LIST( obj ) then
if IS_SUBSET_FLAGS(flags, IsAtomicPositionalObjectRepFlags) then
if IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsAtomicPositionalObjectRep)) then
FORCE_SWITCH_OBJ( obj, FixedAtomicList(obj) );
fi;
elif IS_REC( obj ) then
if IS_ATOMIC_RECORD(obj) then
if IS_SUBSET_FLAGS(flags, IsNonAtomicComponentObjectRepFlags) then
if IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsNonAtomicComponentObjectRep)) then
FORCE_SWITCH_OBJ( obj, FromAtomicRecord(obj) );
fi;
elif not IS_SUBSET_FLAGS(flags, IsNonAtomicComponentObjectRepFlags) then
elif not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsNonAtomicComponentObjectRep)) then
FORCE_SWITCH_OBJ( obj, AtomicRecord(obj) );
fi;
fi;
fi;
if IS_LIST( obj ) then
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
if not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)) then
INFO_DEBUG(1, "Objectify: type does not imply IsPositionalObjectRep ",
INPUT_FILENAME(), ":", STRING_INT(INPUT_LINENUMBER()));
fi;
SET_TYPE_POSOBJ( obj, type );
elif IS_REC( obj ) then
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
if not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)) then
INFO_DEBUG(1, "Objectify: type does not imply IsComponentObjectRep ",
INPUT_FILENAME(), ":", STRING_INT(INPUT_LINENUMBER()));
fi;
SET_TYPE_COMOBJ( obj, type );
else
Error("<obj> must be a list or a record");
fi;
if not ( IGNORE_IMMEDIATE_METHODS
or IsNoImmediateMethodsObject(obj) ) then
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/kernel/gap.tst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gap> START_TEST("kernel/gap.tst");
# in ViewObj; afterwards everything should still work as before
gap> l := [ ~ ];; r := rec(a:=~);;
gap> cat := NewCategory("IsMockObject", IsObject);;
gap> type := NewType(NewFamily("MockFamily"), cat);;
gap> type := NewType(NewFamily("MockFamily"), cat and IsPositionalObjectRep);;
gap> InstallMethod(ViewObj, [cat], function(s) Error("oops"); end);
gap> InstallMethod(PrintObj, [cat], function(s) Error("uups"); end);
gap> x:=Objectify(type,[]); r; Print(l, "\n");
Expand Down
4 changes: 2 additions & 2 deletions tst/testinstall/kernel/opers.tst
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ gap> CLEAR_CACHE_INFO();
gap> opcheck := OPERS_CACHE_INFO();;
#@if GAPInfo.KernelInfo.KernelDebug and IsHPCGAP
gap> opcheck{[1..11]};
[ 2, 0, 0, 6, 0, 0, 6, 0, 0, 2, 0 ]
[ 2, 0, 0, 6, 0, 0, 10, 0, 0, 2, 0 ]
#@fi

# FIXME: the following code skips entry 4 (OperationHit, which is normally
Expand Down Expand Up @@ -338,7 +338,7 @@ gap> opcheck{[1..11]};
#
#@if GAPInfo.KernelInfo.KernelDebug and not IsHPCGAP
gap> opcheck{Difference([1..11], [4])};
[ 2, 0, 0, 0, 0, 4, 0, 0, 2, 0 ]
[ 2, 0, 0, 0, 0, 8, 0, 0, 2, 0 ]
#@fi
#@if not GAPInfo.KernelInfo.KernelDebug
gap> opcheck{[1..11]};
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/object.tst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gap> START_TEST("object.tst");

# test some standard object types
gap> r := Objectify(TYPE_KERNEL_OBJECT, rec());
gap> r := [];; SET_TYPE_DATOBJ(r,TYPE_KERNEL_OBJECT);
<kernel object>
gap> KnownAttributesOfObject(r);
[ ]
Expand Down

0 comments on commit 2d07ffc

Please sign in to comment.