Conversation
h-east
force-pushed
the
vim9-def-legacy-unknown-script-var
branch
from
September 27, 2026 16:05
4ab8a52 to
6f8ec13
Compare
h-east
marked this pull request as draft
September 27, 2026 16:22
Problem: A :def function in a legacy script can create a script-local
variable by assigning to it, while declaring one with "var"
gives E1101.
Solution: Give E1089 for assigning to an unknown script-local variable
in any :def function, not only in one defined in a Vim9
script. Remove uf_script_ctx_version, which was only used
for this check. Do not give it with ":source ++dryrun".
runtime/menu.vim created s:bmenu_short, s:bmenu_count, s:suglist,
s:fromword, s:changeitem, s:additem and s:ignoreitem this way, define
them at the script level.
":source ++dryrun" does not execute ":let" in a legacy script, thus
every script variable would be unknown when compiling. Document that
reading or calling such a variable without "s:" still gives an error,
and separate the paragraphs of ":source-dryrun" with blank lines.
Test_unlet() created s:somevar this way, define it at the script level
instead. Test_using_s_var_in_function() checks that assigning to
s:scriptlevel in a :def function of a legacy script gives E1089 when
the variable does not exist. Test_source_dryrun() checks that
assigning to a script variable with "s:" in a :def function of a
legacy script gives no error with ":source ++dryrun".
Assisted-by: Claude
Signed-off-by: Hirohito Higashi <[email protected]>
h-east
force-pushed
the
vim9-def-legacy-unknown-script-var
branch
from
September 27, 2026 18:40
6f8ec13 to
1d004b6
Compare
h-east
marked this pull request as ready for review
September 27, 2026 18:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes: #21378
runtime/menu.vim created s:bmenu_short, s:bmenu_count, s:suglist,
s:fromword, s:changeitem, s:additem and s:ignoreitem this way, define
them at the script level.
":source ++dryrun" does not execute ":let" in a legacy script, thus
every script variable would be unknown when compiling. Document that
reading or calling such a variable without "s:" still gives an error,
and separate the paragraphs of ":source-dryrun" with blank lines.
Test_unlet() created s:somevar this way, define it at the script level
instead. Test_using_s_var_in_function() checks that assigning to
s:scriptlevel in a :def function of a legacy script gives E1089 when
the variable does not exist. Test_source_dryrun() checks that
assigning to a script variable with "s:" in a :def function of a
legacy script gives no error with ":source ++dryrun".