diff --git a/lib/function.g b/lib/function.g
index 72021bb40f..0973db6d09 100644
--- a/lib/function.g
+++ b/lib/function.g
@@ -313,8 +313,8 @@ BIND_GLOBAL( "EndlineFunc", ENDLINE_FUNC );
##
##
## Let func be a function.
-## Returns a string describing the location of func, or an empty
-## string if the information cannot be found. This uses the information
+## Returns a string describing the location of func, or fail
+## if the information cannot be found. This uses the information
## provided by and
##
## LocationFunc( String );
-## ""
+## fail
## ]]>
##
##
## <#/GAPDoc>
##
-BIND_GLOBAL( "LocationFunc", function(x)
+BIND_GLOBAL( "LocationFunc", function(func)
local nam, line, ret;
# If someone passes something which isn't a true function,
# like a method or attribute, just return.
- if not(IS_FUNCTION(x)) then
- return "";
+ if not IS_FUNCTION(func) then
+ Error(" must be a function");
fi;
ret := "";
- nam := FILENAME_FUNC(x);
+ nam := FILENAME_FUNC(func);
if nam = fail then
- return ret;
+ return fail;
fi;
- line := STARTLINE_FUNC(x);
+ line := STARTLINE_FUNC(func);
if line <> fail then
APPEND_LIST(ret, nam);
APPEND_LIST(ret, ":");
APPEND_LIST(ret, STRING_INT(line));
return ret;
fi;
- line := LOCATION_FUNC(x);
+ line := LOCATION_FUNC(func);
if line <> fail then
APPEND_LIST(ret, nam);
APPEND_LIST(ret, ":");
APPEND_LIST(ret, line);
+ return ret;
fi;
- return ret;
+ return fail;
end);
diff --git a/lib/methwhy.g b/lib/methwhy.g
index c8deac2adc..d41cff22f5 100644
--- a/lib/methwhy.g
+++ b/lib/methwhy.g
@@ -182,7 +182,7 @@ local oper,narg,args,skip,verbos,fams,flags,i,j,methods,flag,flag2,
Print("#I Method ",i,": ``",nam,"''");
if IsBound(m.location) then
Print(" at ", m.location[1], ":", m.location[2]);
- elif LocationFunc(oper) <> "" then
+ elif LocationFunc(oper) <> fail then
Print(" at ",LocationFunc(oper));
fi;
Print(", value: ");
@@ -217,7 +217,7 @@ local oper,narg,args,skip,verbos,fams,flags,i,j,methods,flag,flag2,
Print("#I Method ",i,": ``",nam,"''");
if IsBound(m.location) then
Print(" at ", m.location[1], ":", m.location[2]);
- elif LocationFunc(oper) <> "" then
+ elif LocationFunc(oper) <> fail then
Print(" at ",LocationFunc(oper));
fi;
Print(" , value: ");
diff --git a/src/code.c b/src/code.c
index 00a5d75a14..28d16ea9d4 100644
--- a/src/code.c
+++ b/src/code.c
@@ -211,7 +211,7 @@ void SET_GAPNAMEID_BODY(Obj body, UInt val)
Obj GET_LOCATION_BODY(Obj body)
{
Obj location = BODY_HEADER(body)->startline_or_location;
- return IS_STRING_REP(location) ? location : 0;
+ return (location && IS_STRING_REP(location)) ? location : 0;
}
void SET_LOCATION_BODY(Obj body, Obj val)
diff --git a/tst/testinstall/opers/LocationFunc.tst b/tst/testinstall/opers/LocationFunc.tst
index fc4a1a0394..146d5b7c0c 100644
--- a/tst/testinstall/opers/LocationFunc.tst
+++ b/tst/testinstall/opers/LocationFunc.tst
@@ -1,5 +1,9 @@
gap> START_TEST("LocationFunc.tst");
+#
+gap> LocationFunc(fail);
+Error, must be a function
+
# regular GAP function
gap> f:=x->x;;
gap> LocationFunc(f);
@@ -24,5 +28,13 @@ true
gap> LocationFunc(APPEND_LIST_INTR);
"src/listfunc.c:APPEND_LIST_INTR"
+# String is an attribute, so no information is stored
+gap> LocationFunc( String );
+fail
+
+# functions created from a syntax tree have no location
+gap> LocationFunc(SYNTAX_TREE_CODE(SYNTAX_TREE(x->x)));
+fail
+
#
gap> STOP_TEST("LocationFunc.tst", 1);