Skip to content

Conversation

@thinca
Copy link
Contributor

@thinca thinca commented Sep 1, 2022

In Vim, defining a User function that starts with a lowercase letter is not allowed because it could overwrite a built-in function.
However, defining an autoload function that starts with a lowercase letter is permitted because it does not cause the above problem.

For the same reason, Vim does not allow Funcref to be assigned to a global variable whose name begins with a lowercase letter.
This also applies to the autoload variable; let foo#tr = function('tr') is not allowed and must be let Foo#tr = function('tr').
I see no need for this restriction. let foo#tr = function('tr') should be allowed.

@codecov
Copy link

codecov bot commented Sep 1, 2022

Codecov Report

Merging #11031 (9e95088) into master (be807d5) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #11031      +/-   ##
==========================================
- Coverage   82.47%   82.39%   -0.08%     
==========================================
  Files         152      152              
  Lines      177682   177683       +1     
  Branches    40341    40341              
==========================================
- Hits       146539   146410     -129     
- Misses      18948    19049     +101     
- Partials    12195    12224      +29     
Flag Coverage Δ
huge-clang-none 82.68% <100.00%> (-0.01%) ⬇️
huge-gcc-none ?
huge-gcc-testgui 52.93% <100.00%> (-0.01%) ⬇️
huge-gcc-unittests 0.29% <0.00%> (ø)
linux 82.39% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/evalvars.c 91.30% <100.00%> (+<0.01%) ⬆️
src/main.c 81.18% <0.00%> (-3.53%) ⬇️
src/clipboard.c 71.68% <0.00%> (-1.78%) ⬇️
src/message.c 78.48% <0.00%> (-1.15%) ⬇️
src/popupmenu.c 78.87% <0.00%> (-0.81%) ⬇️
src/beval.c 63.30% <0.00%> (-0.72%) ⬇️
src/if_xcmdsrv.c 76.70% <0.00%> (-0.71%) ⬇️
src/profiler.c 82.63% <0.00%> (-0.70%) ⬇️
src/ex_cmds2.c 81.21% <0.00%> (-0.49%) ⬇️
src/mouse.c 78.74% <0.00%> (-0.32%) ⬇️
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@brammool
Copy link
Contributor

brammool commented Sep 1, 2022 via email

@thinca
Copy link
Contributor Author

thinca commented Sep 2, 2022

In legacy Vim script, name# prefix is always necessary.

" autoload/name.vim

echo foo  " This is g:foo, not name#foo
echo s:foo  " This is s:foo, not name#foo

function name#func()
  echo foo  " This is l:foo, not name#foo
endfunction

In Vim9 script, as you say, exported variable is an autoload variable and can be access without prefix.
But there is no problem.

vim9script
# autoload/name.vim

# This occurs an error "E704: Funcref variable name must start with a capital: tr"
export var tr = () => 'tr'
vim9script
# autoload/name.vim

# This variable can rewrite by `let name#tr = { -> 'tr' }` from outside of script with this patch.
export var tr = ''

def Foo()
  # But this `tr()` is always built-in function.  Vim9 script is compiled first.
  echo tr('foo', 'o', 'a')
enddef

@brammool brammool closed this in 6c667bd Sep 2, 2022
@brammool
Copy link
Contributor

brammool commented Sep 2, 2022 via email

@thinca thinca deleted the allow-assigning-funcref-to-autoload-variable branch September 6, 2022 14:49
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Nov 6, 2022
Problem:    Check for uppercase char in autoload name is wrong, it checks the
            name of the script.
Solution:   Remove the check. (closes vim/vim#11031)

vim/vim@6c667bd

Co-authored-by: thinca <thinca@gmail.com>
yesean pushed a commit to yesean/neovim that referenced this pull request Mar 25, 2023
Problem:    Check for uppercase char in autoload name is wrong, it checks the
            name of the script.
Solution:   Remove the check. (closes vim/vim#11031)

vim/vim@6c667bd

Co-authored-by: thinca <thinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants