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
don't let users accidentally create a function with the name of a builtin #3000
Comments
I vote for the first option. Having to preface all uses with |
Does "banning a test function" mean |
If we implemented that proposal then, yes,
Do we want to let people hurt themselves this way? Is there a legitimate use case for doing |
It is not bad if
There are many moments you can shoot yourself if you think |
I'm not sure about reserving just that particular keyword. What about other generic-sounding builtin like |
And what about 3rd-party and user defined functions? I'm not convinced we should reserve |
I propose adding a |
@krader1961: That's reasonable, and I'd be okay with it. |
I'm going to modify these functions as part of dealing with issue #3000 and don't want those changes to be masked by running the files through `make style`.
This change will in the future have the effect that any scripts which do override a builtin and work fine on 2.3.0/2.3.1 will need this new |
That's the whole idea. It's not supposed to be convenient to shoot yourself in the foot. |
The part where that broke forwards and backwards compatibility to take advantage of this is the inconvenient part. I don't think we want to punish people for having used our software. The error output from master |
This has been removed with cfefaaf. Removing from the milestone. |
@zanchey, Why reopen this? It's pretty clear that no one wants to break both forward and backward compatibility to keep people from shooting themselves in the foot. The only thing I think we can do that wouldn't be controversial is to give a warning if, and only if, the function that shadowed a builtin was defined interactively. And even then we shouldn't keep the function from being defined. |
I don't think we've come up with the right answer yet, but that doesn't mean there isn't one; let's keep it open and keep thinking. |
Why not go back around and just do the simple thing that'll make |
it's totally safe to shadow these builtins... right up until you start autoloading, and then things to to hell quickly. We could make I think if we say that |
No because it doesn't address all the other failure modes; e.g., creating a |
It's safer because a user is less likely to accidentally define |
Which misses the point that someone defining a function that shadows any builtin can break fish. The Regardless, the use of the |
A new fish use shot themselves in the foot by doing There is no way to disallow defining a function with the same name as a builtin without breaking backward and forward compatibility. As I said earlier when that became clear and my change was reverted the best we can do is issue a warning if someone does so interactively. Which is likely to deal with the majority of these situations since such problems typically involve someone defining a function interactively. So I propose we do so then consider this issue resolved. Note that we need to be careful not to issue a warning if the function is autoloaded in an interactive session. There is one other possible, but problematic, solution. Examine the parse tree of the function to see if it contains |
From the duplicate #4742, with emphasis added:
A simpler alternative has just occurred to me, however. If a user defines a function whose name conflicts with a builtin (or perhaps just |
Would we then have to store what functions we've warned about? I believe the major issue here is Two already have functions overriding them ( Honestly, I believe that most of the benefit can be had by just forbidding functions named By not requiring an additional flag for those builtins that are allowed to be overridden (at the very least |
See #4732, where |
I would be onboard with that. There's not much to be gained by refusing to expand the reversed keywords list, imho. |
So, here's a list of builtins that currently aren't reserved: [ Of these, we currently override At the very least Of the rest, I don't see any great reason to override any of them - one might be tempted to e.g. add logging to For So the minimal list is: argparse And the maximal list is [ (i.e. no Does anyone have any objections to any in the maximal list? Maybe an idea for how one could override it in a useful manner? |
I'd stick with the minimal list, plus I'm not even sure about |
In my tests, it doesn't - function argparse --no-scope-shadowing
builtin argparse $argv
end already causes
I'd add |
Okay, done with |
Thanks, @faho. Do we use |
Having syntax rather than commands is not a good idea generally. Giving the user the possibility to alter the meaning of syntax is just too confusing and it also goes against everything bash or sh users would expect to happen. Implementing such details (or rather leaving them unguarded) will obfuscate code using such a 'syntax redefinition' for most fish users |
Yes, we do. About 80 occurences in share/**.fish.
Even if it didn't cause internal problems in fish, it'd cause problems with other people's scripts. And even if it didn't do that, it would cause issues with other people reading your scripts. We really don't want to support that. Like we don't want to support people repurposing "if" or "for". The minor advantage of subjective aesthetics is dwarfed by the disadvantage of compatibility with other people's stuff and us having to remove If you want to add something syntax-like (which doesn't really behave like syntax because all of the expansions and such still happen), you can just use a different name - you can even add a function called |
Just a note for the benefit of future searchers (or myself in a day or two), while |
Fairly regularly, somebody writes a function called
test
, and then their entire environment spews garbage and often becomes unresponsive, as many shipped functions and prompts expecttest
to be the builtin (or at least behave the same way).Options include:
test
functionbuiltin test
or[
.The text was updated successfully, but these errors were encountered: