-
Notifications
You must be signed in to change notification settings - Fork 161
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
Error in autocompletion when trying to access a component object via record access by accident #5241
Comments
Thank you for reporting this. That's indeed a regression from the "nicer" record tab completion introduced in 4.12, and should be fixed. |
Actually even in older versions something weird happens, but unrelated to tab completion: If I press "return" instead of tab, I see this:
If I now enter |
Out of curiosity: Why is there a distinction between |
|
The question was not meant in the concrete context of this issue, sorry. New try: Why does GAP not allow to access components of component objects via |
My belief is this is a safety / organisation issue. In general the names of components of component objects aren't fixed between versions of GAP, and also you can create some horrible bugs (and possibly even crashes) if you started editing components of component objects in ways you are not supposed to. There isn't (I believe) any reason we couldn't just use "." for accessing all "record-like" objects, and get rid of "!.", except as you point out the documentation discourages uses "!." as you are digging inside objects. |
I see, this matches what I expected, thanks for the thorough explanation! :-) |
@ChrisJefferson no, that's not right! Objects can overload In particular, it is possible for In contrast, |
Oh, I didn't realise you overload them both separately. I've also been surprised that g!.foo works for records, but I also agree that I bet some code is using it -- it doesn't feel worth breaking that code. |
Actually, you can only overload InstallMethod(\.,"group generators",true,
[IsGroup and HasGeneratorsOfGroup,IsPosInt],
function(g,n)
g:=GeneratorsOfGroup(g);
n:=NameRNam(n);
n:=Int(n);
if n=fail or Length(g)<n then
TryNextMethod();
fi;
return g[n];
end); and # methods to catch error cases
InstallMethod( \.,
"catch error",
true,
[IsObject,IsObject],
0,
function(obj,nr)
local msg;
msg:=Concatenation("illegal access to record component `obj.",
NameRNam(nr),"'\n",
"of the object <obj>. (Objects by default do not have record components.\n",
"The error might be a relic from translated GAP3 code.)");
Error(msg);
end); Note that this can only be overloaded for "external" objects (so positional, component or data objects, and types provided by packages), but not for internal ones like integers, strings, booleans, plist, ... |
Thanks for the detailed answers! I have recently started a prototype of a system automatically converting GAP code to Julia code, so all this information is valuable :-) |
Steps to reproduce:
and now press Tab to autocomplete.
Observed behaviour
Expected behaviour
Of course the real problem is the user typing a wrong expression, but I think it would be nice to fail in a more graceful way here. If you don't think so, or if fixing this is not easy (there might actually be a method for
\.
installed and I'm not sure if one can easily detect this), feel free to close this issue.Copy and paste GAP banner (to tell us about your setup)
The text was updated successfully, but these errors were encountered: