-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Vim9: body of broken function not cleared when using ":silent!" #8093
Comments
Sorry, the error is not raised; it's suppressed by |
Something else looks a bit weird. When we ask for the definition of a broken And when we invoke a broken function (because of All of this suggests that a broken function is redefined as a legacy one. But that's not the case: vim9script
def Func()
echo (() => 123)()
var x = 0 + {}
enddef
sil! Func()
au TextChangedI * Func()
feedkeys('ii') This snippet correctly prints |
I actually think we should not delete the function body. This can be useful when the error message isn't clear and perhaps the script where it was defined is not easy to find. We then use a separate flag to specify that the function has an error and can't be executed. This does mean that for an autocommand you get an error every time. That's not different from using a not compiled function though. |
The error message is different depending on whether the first invocation (when the function was compiled) was prefixed with vim9script
def Func()
var x = 0 + {}
enddef
Func()
au TextChangedI * Func()
feedkeys('ii')
vim9script
def Func()
var x = 0 + {}
enddef
sil! Func()
au TextChangedI * Func()
feedkeys('ii')
This seems inconsistent. I think the second message should tell us that |
That was fixed with patch 8.2.2743 |
Describe the bug
In Vim9 script,
:silent!
might prevent Vim from clearing the body of a broken function.To Reproduce
Run this shell command:
E1051
is raised:This is expected.
The body of the function – as given by
:def Func
– remains the same:This is not expected.
Expected behavior
The body of
Func()
is empty.Environment
Additional context
silent!
doesn't prevent Vim from clearing the body of a broken function for other errors.For example, if we try to re-declare a variable:
Or if we try to execute an invalid command:
Or if we try to change the type of a variable:
Notice that in all these snippets,
Func()
was invoked withsilent!
which correctly suppressed the error raised during the compilation. And notice that afterward, in all of them, the body of the function was empty.If
silent!
does not prevent Vim from clearing the body of a broken function for these 3 errors, I would expect it does not prevent Vim from doing the same for the first one (E1051).The fact that Vim clears the body of a function for which an error has been raised at compile time is neat. It's especially useful when the latter is invoked frequently; e.g. in an autocmd:
This snippet raises
E476
because of the initialFunc()
invocation on line 5:This is expected. But afterward, whenever a character is inserted, no error is raised. That's because Vim has cleared the body of the function after an error was raised during its compilation; which makes sense, if it can't be compiled, it will never work, and there's no reason to run anything; that would only bother the user whenever they try to insert a character.
This definition clearing should be done consistently and whenever possible. That's not the case when the error is
E728
:Notice that this error is raised by the
TextChangedI
autocmd. And it will be repeated on every single keypress. This is useless. The function will never work; its definition should have been cleared during the compilation on its first invocation, regardless of whethersilent!
was used then.The text was updated successfully, but these errors were encountered: