From c6d533b0ad565a610a48386b0ad72cc591010fcb Mon Sep 17 00:00:00 2001 From: Karim Belabas Date: Tue, 22 Aug 2023 20:25:06 +0200 Subject: [PATCH 01/91] runtime(gp): update gp.vim syntax file for the GP language (version 2.15) (#12884) - add missing defaults - add missing control structures (incl. parallelism) - add missing scope declarations - whitespace edits (remove extra tabs) --- runtime/syntax/gp.vim | 47 ++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/runtime/syntax/gp.vim b/runtime/syntax/gp.vim index aecf7df48b..89f2d3f0ff 100644 --- a/runtime/syntax/gp.vim +++ b/runtime/syntax/gp.vim @@ -1,7 +1,7 @@ " Vim syntax file -" Language: gp (version 2.5) +" Language: gp (version 2.15) " Maintainer: Karim Belabas -" Last change: 2012 Jan 08 +" Last change: 2023 Aug 22 " URL: http://pari.math.u-bordeaux.fr " quit when a syntax file was already loaded @@ -14,23 +14,29 @@ set cpo&vim " control statements syntax keyword gpStatement break return next -syntax keyword gpConditional if -syntax keyword gpRepeat until while for fordiv forell forprime -syntax keyword gpRepeat forsubgroup forstep forvec +syntax keyword gpConditional if iferr +syntax keyword gpRepeat until while for forcomposite fordiv +syntax keyword gpRepeat fordivfactored foreach forell forfactored +syntax keyword gpRepeat forpart forperm forprime forprimestep forqfvec +syntax keyword gpRepeat forsquarefree forstep forsubgroup forsubset +syntax keyword gpRepeat forvec +syntax keyword gpRepeat parfor parforeach parforprime parforprimestep +syntax keyword gpRepeat parforvec " storage class -syntax keyword gpScope my local global +syntax keyword gpScope my local global export exportall " defaults syntax keyword gpInterfaceKey breakloop colors compatible -syntax keyword gpInterfaceKey datadir debug debugfiles debugmem -syntax keyword gpInterfaceKey echo factor_add_primes factor_proven format +syntax keyword gpInterfaceKey datadir debug debugfiles debugmem +syntax keyword gpInterfaceKey echo factor_add_primes factor_proven format syntax keyword gpInterfaceKey graphcolormap graphcolors -syntax keyword gpInterfaceKey help histfile histsize -syntax keyword gpInterfaceKey lines linewrap log logfile new_galois_format -syntax keyword gpInterfaceKey output parisize path prettyprinter primelimit -syntax keyword gpInterfaceKey prompt prompt_cont psfile -syntax keyword gpInterfaceKey readline realprecision recover -syntax keyword gpInterfaceKey secure seriesprecision simplify strictmatch -syntax keyword gpInterfaceKey TeXstyle timer +syntax keyword gpInterfaceKey help histfile histsize +syntax keyword gpInterfaceKey lines linewrap log logfile nbthreads +syntax keyword gpInterfaceKey new_galois_format output parisize parisizemax +syntax keyword gpInterfaceKey path plothsizes prettyprinter primelimit prompt +syntax keyword gpInterfaceKey prompt_cont psfile readline realbitprecision +syntax keyword gpInterfaceKey realprecision recover secure seriesprecision +syntax keyword gpInterfaceKey simplify sopath strictmatch TeXstyle +syntax keyword gpInterfaceKey threadsize threadsizemax timer syntax match gpInterface "^\s*\\[a-z].*" syntax keyword gpInterface default @@ -58,24 +64,23 @@ syntax region gpParen transparent start='(' end=')' contains=ALLBUT,gpParenErro syntax match gpParenError ")" syntax match gpInParen contained "[{}]" - -hi def link gpConditional Conditional +hi def link gpConditional Conditional hi def link gpRepeat Repeat hi def link gpError Error -hi def link gpParenError gpError +hi def link gpParenError gpError hi def link gpInParen gpError hi def link gpStatement Statement hi def link gpString String hi def link gpComment Comment hi def link gpInterface Type hi def link gpInput Type -hi def link gpInterfaceKey Statement +hi def link gpInterfaceKey Statement hi def link gpFunction Function hi def link gpScope Type " contained ones hi def link gpSpecial Special -hi def link gpTodo Todo -hi def link gpArgs Type +hi def link gpTodo Todo +hi def link gpArgs Type let b:current_syntax = "gp" let &cpo = s:cpo_save From e34b51e95fd0ea7b0e34a625db0f9ed7e051e0dd Mon Sep 17 00:00:00 2001 From: dkearns Date: Wed, 23 Aug 2023 04:28:42 +1000 Subject: [PATCH 02/91] runtime(solidity): add new ftplugin (#12877) Set undo_{ftplugin,indent} closes #11240 Co-authored-by: cothi --- .github/CODEOWNERS | 3 +++ runtime/ftplugin/solidity.vim | 15 +++++++++++++++ runtime/indent/solidity.vim | 14 +++++++++----- runtime/syntax/solidity.vim | 10 +++++----- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 runtime/ftplugin/solidity.vim diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 03c269cf14..213b9af868 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -210,6 +210,7 @@ runtime/ftplugin/scss.vim @tpope runtime/ftplugin/sdoc.vim @gpanders runtime/ftplugin/sed.vim @dkearns runtime/ftplugin/sh.vim @dkearns +runtime/ftplugin/solidity.vim @cothi runtime/ftplugin/solution.vim @dkearns runtime/ftplugin/spec.vim @ignatenkobrain runtime/ftplugin/ssa.vim @ObserverOfTime @@ -299,6 +300,7 @@ runtime/indent/sass.vim @tpope runtime/indent/scala.vim @derekwyatt runtime/indent/scss.vim @tpope runtime/indent/sh.vim @chrisbra +runtime/indent/solidity.vim @cothi runtime/indent/systemverilog.vim @Kocha runtime/indent/tcl.vim @dkearns runtime/indent/tcsh.vim @dkearns @@ -470,6 +472,7 @@ runtime/syntax/sdoc.vim @gpanders runtime/syntax/sed.vim @dkearns runtime/syntax/sh.vim @cecamp runtime/syntax/sm.vim @cecamp +runtime/syntax/solidity.vim @cothi runtime/syntax/spec.vim @ignatenkobrain runtime/syntax/sqloracle.vim @chrisbra runtime/syntax/squirrel.vim @zenmatic diff --git a/runtime/ftplugin/solidity.vim b/runtime/ftplugin/solidity.vim new file mode 100644 index 0000000000..abe9f2ff26 --- /dev/null +++ b/runtime/ftplugin/solidity.vim @@ -0,0 +1,15 @@ +" Vim filetype plugin file +" Language: Solidity +" Maintainer: Cothi (jiungdev@gmail.com) +" Original Author: tomlion (https://github.com/tomlion/vim-solidity) +" Last Change: 2022 Sep 27 +" 2023 Aug 22 Vim Project (did_ftplugin, undo_ftplugin) + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +setlocal commentstring=//\ %s + +let b:undo_ftplugin = "setlocal commentstring<" diff --git a/runtime/indent/solidity.vim b/runtime/indent/solidity.vim index caed726c0a..55a07c015a 100644 --- a/runtime/indent/solidity.vim +++ b/runtime/indent/solidity.vim @@ -1,9 +1,11 @@ " Vim indent file -" Language: Solidity -" Acknowledgement: Based off of vim-javascript -" Maintainer: Cothi (jiungdev@gmail.com) -" Original Author: tomlion (https://github.com/tomlion/vim-solidity) -" Last Changed: 2022 Sep 27 +" Language: Solidity +" Maintainer: Cothi (jiungdev@gmail.com) +" Original Author: tomlion (https://github.com/tomlion/vim-solidity) +" Last Change: 2022 Sep 27 +" 2023 Aug 22 Vim Project (undo_indent) +" +" Acknowledgement: Based off of vim-javascript " " 0. Initialization {{{1 " ================= @@ -20,6 +22,8 @@ setlocal nosmartindent setlocal indentexpr=GetSolidityIndent() setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e +let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<" + " Only define the function once. if exists("*GetSolidityIndent") finish diff --git a/runtime/syntax/solidity.vim b/runtime/syntax/solidity.vim index e552446e10..a46d041a10 100644 --- a/runtime/syntax/solidity.vim +++ b/runtime/syntax/solidity.vim @@ -1,10 +1,10 @@ " Vim syntax file -" Language: Solidity -" Maintainer: Cothi (jiungdev@gmail.com) -" Original Author: tomlion (https://github.com/tomlion/vim-solidity/blob/master/syntax/solidity.vim) -" Last Changed: 2022 Sep 27 +" Language: Solidity +" Maintainer: Cothi (jiungdev@gmail.com) +" Original Author: tomlion (https://github.com/tomlion/vim-solidity/blob/master/syntax/solidity.vim) +" Last Change: 2022 Sep 27 " -" Additional contributors: +" Contributors: " Modified by thesis (https://github.com/thesis/vim-solidity/blob/main/indent/solidity.vim) if exists("b:current_syntax") From b0d584d97ab6f5cb070caba3882ba387b81448c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9-Paul=20D?= Date: Tue, 22 Aug 2023 20:29:19 +0200 Subject: [PATCH 03/91] runtime(go): Update Go syntax file with 1.21 builtins (#12876) * Update Go syntax file with 1.21 builtins --- runtime/syntax/go.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/syntax/go.vim b/runtime/syntax/go.vim index bf967fdcd9..4272e807f3 100644 --- a/runtime/syntax/go.vim +++ b/runtime/syntax/go.vim @@ -5,7 +5,7 @@ " go.vim: Vim syntax file for Go. " Language: Go " Maintainer: Billie Cleek -" Latest Revision: 2023-02-19 +" Latest Revision: 2023-08-21 " License: BSD-style. See LICENSE file in source repository. " Repository: https://github.com/fatih/vim-go @@ -130,8 +130,8 @@ hi def link goFloats Type hi def link goComplexes Type " Predefined functions and values -syn keyword goBuiltins append cap close complex copy delete imag len -syn keyword goBuiltins make new panic print println real recover +syn keyword goBuiltins append cap clear close complex copy delete imag len +syn keyword goBuiltins make max min new panic print println real recover syn keyword goBoolean true false syn keyword goPredefinedIdentifiers nil iota From a76f3221cdcfff6880213839de4d04cf0c7c60f8 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 22 Aug 2023 19:30:29 +0100 Subject: [PATCH 04/91] runtime(termdebug): Fix various Termdebug issues (#12875) * Fix some Termdebug issues after #12403 Problem: Cleanup for :Var and :Asm buffers did not apply to prompt mode, and E86 was possible if they were hidden. Solution: Move cleanup to s:EndDebugCommon. Check that the buffers exist before switching. * Fix :Asm in Termdebug prompt mode Problem: :Asm does not work in prompt mode. Solution: Make it work by handling disassembly-related messages properly. The previous implementation depended on the typed or sent (via s:SendCommand()) "disassemble ..." message being visible to s:CommOutput(), but this was only true for the terminal-based job. A more robust solution would be to use GDB MI's -data-disassemble command. I may implement this in a future PR. * Fix Termdebug s:DecodeMessage escaping logic Problem: Termdebug does not escape gdb messages properly. Solution: Improve the logic. Do not mangle messages if they have inner escaped quotes. Use line continuation comments properly. Interestingly, due to the missing line continuation comments (`"\`), most of these substitutions were ignored. Presumably, this logic still isn't exact. For example, if a message ends in `\\"`, the quote may be preserved, even though it's the `\` being escaped (similar issues may exist for the other escapes). This may not be a problem in practice, though. --- .../dist/opt/termdebug/plugin/termdebug.vim | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index 466a77fd84..384cef27a3 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -229,10 +229,10 @@ endfunc func s:CloseBuffers() exe 'bwipe! ' . s:ptybuf exe 'bwipe! ' . s:commbuf - if s:asmbuf > 0 + if s:asmbuf > 0 && bufexists(s:asmbuf) exe 'bwipe! ' . s:asmbuf endif - if s:varbuf > 0 + if s:varbuf > 0 && bufexists(s:varbuf) exe 'bwipe! ' . s:varbuf endif s:running = 0 @@ -617,9 +617,16 @@ endfunc func s:GdbOutCallback(channel, text) call ch_log('received from gdb: ' . a:text) + " Disassembly messages need to be forwarded as-is. + if s:parsing_disasm_msg + call s:CommOutput(a:channel, a:text) + return + end + " Drop the gdb prompt, we have our own. " Drop status and echo'd commands. - if a:text == '(gdb) ' || a:text == '^done' || a:text[0] == '&' + if a:text == '(gdb) ' || a:text == '^done' || + \ (a:text[0] == '&' && a:text !~ '^&"disassemble') return endif if a:text =~ '^\^error,msg=' @@ -647,8 +654,9 @@ func s:GdbOutCallback(channel, text) endfunc " Decode a message from gdb. "quotedText" starts with a ", return the text up -" to the next ", unescaping characters: +" to the next unescaped ", unescaping characters: " - remove line breaks (unless "literal" is v:true) +" - change \" to " " - change \\t to \t (unless "literal" is v:true) " - change \0xhh to \xhh (disabled for now) " - change \ooo to octal @@ -659,24 +667,25 @@ func s:DecodeMessage(quotedText, literal) return endif let msg = a:quotedText - \ ->substitute('^"\|".*', '', 'g') - " multi-byte characters arrive in octal form - " NULL-values must be kept encoded as those break the string otherwise + \ ->substitute('^"\|[^\\]\zs".*', '', 'g') + \ ->substitute('\\"', '"', 'g') + "\ multi-byte characters arrive in octal form + "\ NULL-values must be kept encoded as those break the string otherwise \ ->substitute('\\000', s:NullRepl, 'g') \ ->substitute('\\\o\o\o', {-> eval('"' .. submatch(0) .. '"')}, 'g') - " Note: GDB docs also mention hex encodings - the translations below work - " but we keep them out for performance-reasons until we actually see - " those in mi-returns - " \ ->substitute('\\0x\(\x\x\)', {-> eval('"\x' .. submatch(1) .. '"')}, 'g') - " \ ->substitute('\\0x00', s:NullRepl, 'g') + "\ Note: GDB docs also mention hex encodings - the translations below work + "\ but we keep them out for performance-reasons until we actually see + "\ those in mi-returns + "\ \ ->substitute('\\0x\(\x\x\)', {-> eval('"\x' .. submatch(1) .. '"')}, 'g') + "\ \ ->substitute('\\0x00', s:NullRepl, 'g') \ ->substitute('\\\\', '\', 'g') \ ->substitute(s:NullRepl, '\\000', 'g') if !a:literal - return msg + return msg \ ->substitute('\\t', "\t", 'g') \ ->substitute('\\n', '', 'g') else - return msg + return msg endif endfunc const s:NullRepl = 'XXXNULLXXX' @@ -709,15 +718,7 @@ func s:EndTermDebug(job, status) endif exe 'bwipe! ' . s:commbuf - if s:asmbuf > 0 - exe 'bwipe! ' . s:asmbuf - endif - if s:varbuf > 0 - exe 'bwipe! ' . s:varbuf - endif - let s:running = 0 unlet s:gdbwin - call s:EndDebugCommon() endfunc @@ -727,6 +728,13 @@ func s:EndDebugCommon() if exists('s:ptybuf') && s:ptybuf exe 'bwipe! ' . s:ptybuf endif + if s:asmbuf > 0 && bufexists(s:asmbuf) + exe 'bwipe! ' . s:asmbuf + endif + if s:varbuf > 0 && bufexists(s:varbuf) + exe 'bwipe! ' . s:varbuf + endif + let s:running = 0 " Restore 'signcolumn' in all buffers for which it was set. call win_gotoid(s:sourcewin) @@ -789,7 +797,6 @@ endfunc " Disassembly window - added by Michael Sartain " -" - CommOutput: disassemble $pc " - CommOutput: &"disassemble $pc\n" " - CommOutput: ~"Dump of assembler code for function main(int, char**):\n" " - CommOutput: ~" 0x0000555556466f69 <+0>:\tpush rbp\n" @@ -799,7 +806,6 @@ endfunc " - CommOutput: ~"End of assembler dump.\n" " - CommOutput: ^done -" - CommOutput: disassemble $pc " - CommOutput: &"disassemble $pc\n" " - CommOutput: &"No function contains specified address.\n" " - CommOutput: ^error,msg="No function contains specified address." @@ -831,12 +837,12 @@ func s:HandleDisasmMsg(msg) call s:SendCommand('disassemble $pc,+100') endif let s:parsing_disasm_msg = 0 - elseif a:msg =~ '\&\"disassemble \$pc' + elseif a:msg =~ '^&"disassemble \$pc' if a:msg =~ '+100' " This is our second disasm attempt let s:parsing_disasm_msg = 2 endif - else + elseif a:msg !~ '^&"disassemble' let value = substitute(a:msg, '^\~\"[ ]*', '', '') let value = substitute(value, '^=>[ ]*', '', '') let value = substitute(value, '\\n\"\r$', '', '') @@ -920,9 +926,10 @@ func s:CommOutput(chan, msg) call s:HandleEvaluate(msg) elseif msg =~ '^\^error,msg=' call s:HandleError(msg) - elseif msg =~ '^disassemble' + elseif msg =~ '^&"disassemble' let s:parsing_disasm_msg = 1 let s:asm_lines = [] + call s:HandleDisasmMsg(msg) elseif msg =~ '^\^done,variables=' call s:HandleVariablesMsg(msg) endif @@ -1358,7 +1365,7 @@ func s:GotoAsmwinOrCreateIt() setlocal signcolumn=no setlocal modifiable - if s:asmbuf > 0 + if s:asmbuf > 0 && bufexists(s:asmbuf) exe 'buffer' . s:asmbuf else silent file Termdebug-asm-listing @@ -1420,7 +1427,7 @@ func s:GotoVariableswinOrCreateIt() setlocal signcolumn=no setlocal modifiable - if s:varbuf > 0 + if s:varbuf > 0 && bufexists(s:varbuf) exe 'buffer' . s:varbuf else silent file Termdebug-variables-listing From 8dabccd295271104ad5af0abc48e283d644cff59 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Aug 2023 21:22:24 +0200 Subject: [PATCH 05/91] patch 9.0.1779: Need more state() tests Problem: Need more state() tests Solution: Add a few more tests for operater pending mode and register yank command closes: #12883 Signed-off-by: Christian Brabandt Co-authored-by: author --- src/testdir/test_functions.vim | 14 ++++++++++++++ src/version.c | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index a500b734b2..0eda5de380 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -2901,6 +2901,20 @@ func Test_state() call term_sendkeys(buf, getstate) call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000) + " A operator is pending + call term_sendkeys(buf, ":call RunTimer()\y") + call TermWait(buf, 25) + call term_sendkeys(buf, "y") + call term_sendkeys(buf, getstate) + call WaitForAssert({-> assert_match('state: oSc; mode: n', term_getline(buf, 6))}, 1000) + + " A register was specified + call term_sendkeys(buf, ":call RunTimer()\\"r") + call TermWait(buf, 25) + call term_sendkeys(buf, "yy") + call term_sendkeys(buf, getstate) + call WaitForAssert({-> assert_match('state: oSc; mode: n', term_getline(buf, 6))}, 1000) + " Insert mode completion (bit slower on Mac) call term_sendkeys(buf, ":call RunTimer()\Got\") call TermWait(buf, 25) diff --git a/src/version.c b/src/version.c index 50e2187c4c..3ca3167cb9 100644 --- a/src/version.c +++ b/src/version.c @@ -699,6 +699,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1779, /**/ 1778, /**/ From 618e47d1cd93954bad26d47e5353b4f1432daa5e Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 22 Aug 2023 21:29:28 +0200 Subject: [PATCH 06/91] patch 9.0.1780: Vim9 type not defined during object creation Problem: Vim9 type not defined during object creation Solution: Define type during object creation and not during class definition, parse mulit-line member initializers, fix lock initialization If type is not specified for a member, set it during object creation instead of during class definition. Add a runtime type check for the object member initialization expression Also, while at it, when copying an object or class, make sure the lock is correctly initialized. And finally, parse multi-line member initializers correctly. closes: #11957 closes: #12868 closes: #12869 closes: #12881 Signed-off-by: Christian Brabandt Co-authored-by: Yegappan Lakshmanan Co-authored-by: LemonBoy --- runtime/doc/vim9class.txt | 6 ++ src/testdir/test_vim9_class.vim | 97 +++++++++++++++++++++++++++++++-- src/version.c | 2 + src/vim9class.c | 76 +++++++++++--------------- src/vim9compile.c | 13 +++++ 5 files changed, 147 insertions(+), 47 deletions(-) diff --git a/runtime/doc/vim9class.txt b/runtime/doc/vim9class.txt index a68b97c87b..c68288a0c5 100644 --- a/runtime/doc/vim9class.txt +++ b/runtime/doc/vim9class.txt @@ -423,6 +423,12 @@ Each member and function name can be used only once. It is not possible to define a function with the same name and different type of arguments. +Member Initialization ~ +If the type of a member is not explicitly specified in a class, then it is set +to "any" during class definition. When an object is instantiated from the +class, then the type of the member is set. + + Extending a class ~ *extends* A class can extend one other class. *E1352* *E1353* *E1354* diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index dbd4c3bcbe..7e33c6d448 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -210,6 +210,17 @@ def Test_class_basic() var v = a.Foo(,) END v9.CheckScriptFailure(lines, 'E15:') + + lines =<< trim END + vim9script + class A + this.y = { + X: 1 + } + endclass + var a = A.new() + END + v9.CheckScriptSuccess(lines) enddef def Test_class_defined_twice() @@ -668,14 +679,28 @@ def Test_class_object_member_inits() END v9.CheckScriptFailure(lines, 'E1022:') + # If the type is not specified for a member, then it should be set during + # object creation and not when defining the class. lines =<< trim END vim9script - class TextPosition - this.lnum = v:none + + var init_count = 0 + def Init(): string + init_count += 1 + return 'foo' + enddef + + class A + this.str1 = Init() + this.str2: string = Init() this.col = 1 endclass + + assert_equal(init_count, 0) + var a = A.new() + assert_equal(init_count, 2) END - v9.CheckScriptFailure(lines, 'E1330:') + v9.CheckScriptSuccess(lines) # Test for initializing an object member with an unknown variable/type lines =<< trim END @@ -683,8 +708,9 @@ def Test_class_object_member_inits() class A this.value = init_val endclass + var a = A.new() END - v9.CheckScriptFailureList(lines, ['E121:', 'E1329:']) + v9.CheckScriptFailure(lines, 'E1001:') enddef def Test_class_object_member_access() @@ -2625,4 +2651,67 @@ def Test_new_return_type() v9.CheckScriptFailure(lines, 'E1365:') enddef +" Test for checking a member initialization type at run time. +def Test_runtime_type_check_for_member_init() + var lines =<< trim END + vim9script + + var retnum: bool = false + + def F(): any + retnum = !retnum + if retnum + return 1 + else + return "hello" + endif + enddef + + class C + this._foo: bool = F() + endclass + + var c1 = C.new() + var c2 = C.new() + END + v9.CheckScriptFailure(lines, 'E1012:') +enddef + +" Test for locking a variable referring to an object and reassigning to another +" object. +def Test_object_lockvar() + var lines =<< trim END + vim9script + + class C + this.val: number + def new(this.val) + enddef + endclass + + var some_dict: dict = { a: C.new(1), b: C.new(2), c: C.new(3), } + lockvar 2 some_dict + + var current: C + current = some_dict['c'] + assert_equal(3, current.val) + current = some_dict['b'] + assert_equal(2, current.val) + + def F() + current = some_dict['c'] + enddef + + def G() + current = some_dict['b'] + enddef + + F() + assert_equal(3, current.val) + G() + assert_equal(2, current.val) + END + v9.CheckScriptSuccess(lines) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index 3ca3167cb9..7b0615208d 100644 --- a/src/version.c +++ b/src/version.c @@ -699,6 +699,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1780, /**/ 1779, /**/ diff --git a/src/vim9class.c b/src/vim9class.c index e4130459b2..00b1f7d98f 100644 --- a/src/vim9class.c +++ b/src/vim9class.c @@ -67,66 +67,48 @@ parse_member( return FAIL; } - char_u *expr_start = skipwhite(type_arg); - char_u *expr_end = expr_start; - if (type == NULL && *expr_start != '=') + char_u *init_arg = skipwhite(type_arg); + if (type == NULL && *init_arg != '=') { emsg(_(e_type_or_initialization_required)); return FAIL; } - if (*expr_start == '=') + if (init_expr == NULL && *init_arg == '=') { - if (!VIM_ISWHITE(expr_start[-1]) || !VIM_ISWHITE(expr_start[1])) + emsg(_(e_cannot_initialize_member_in_interface)); + return FAIL; + } + + if (*init_arg == '=') + { + evalarg_T evalarg; + char_u *expr_start, *expr_end; + + if (!VIM_ISWHITE(init_arg[-1]) || !VIM_ISWHITE(init_arg[1])) { semsg(_(e_white_space_required_before_and_after_str_at_str), "=", type_arg); return FAIL; } - expr_start = skipwhite(expr_start + 1); + init_arg = skipwhite(init_arg + 1); - expr_end = expr_start; - evalarg_T evalarg; fill_evalarg_from_eap(&evalarg, eap, FALSE); - skip_expr(&expr_end, NULL); + (void)skip_expr_concatenate(&init_arg, &expr_start, &expr_end, &evalarg); + // No type specified for the member. Set it to "any" and the correct type will be + // set when the object is instantiated. if (type == NULL) - { - // No type specified, use the type of the initializer. - typval_T tv; - tv.v_type = VAR_UNKNOWN; - char_u *expr = expr_start; - int res = eval0(expr, &tv, eap, &evalarg); + type = &t_any; - if (res == OK) - { - type = typval2type(&tv, get_copyID(), type_list, - TVTT_DO_MEMBER); - clear_tv(&tv); - } - if (type == NULL) - { - semsg(_(e_cannot_get_object_member_type_from_initializer_str), - expr_start); - clear_evalarg(&evalarg, NULL); - return FAIL; - } - } + *init_expr = vim_strnsave(expr_start, expr_end - expr_start); + // Free the memory pointed by expr_start. clear_evalarg(&evalarg, NULL); } - if (!valid_declaration_type(type)) + else if (!valid_declaration_type(type)) return FAIL; *type_ret = type; - if (expr_end > expr_start) - { - if (init_expr == NULL) - { - emsg(_(e_cannot_initialize_member_in_interface)); - return FAIL; - } - *init_expr = vim_strnsave(expr_start, expr_end - expr_start); - } return OK; } @@ -1740,9 +1722,13 @@ inside_class(cctx_T *cctx_arg, class_T *cl) void copy_object(typval_T *from, typval_T *to) { - *to = *from; - if (to->vval.v_object != NULL) + if (from->vval.v_object == NULL) + to->vval.v_object = NULL; + else + { + to->vval.v_object = from->vval.v_object; ++to->vval.v_object->obj_refcount; + } } /* @@ -1787,9 +1773,13 @@ object_unref(object_T *obj) void copy_class(typval_T *from, typval_T *to) { - *to = *from; - if (to->vval.v_class != NULL) + if (from->vval.v_class == NULL) + to->vval.v_class = NULL; + else + { + to->vval.v_class = from->vval.v_class; ++to->vval.v_class->class_refcount; + } } /* diff --git a/src/vim9compile.c b/src/vim9compile.c index 028b0ca152..09b4bf143b 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -3150,6 +3150,19 @@ compile_def_function( semsg(_(e_trailing_characters_str), expr); goto erret; } + + type_T *type = get_type_on_stack(&cctx, 0); + if (m->ocm_type->tt_type != type->tt_type) + { + // The type of the member initialization expression is + // determined at run time. Add a runtime type check. + where_T where = WHERE_INIT; + where.wt_kind = WT_MEMBER; + where.wt_func_name = (char *)m->ocm_name; + if (need_type_where(type, m->ocm_type, FALSE, -1, + where, &cctx, FALSE, FALSE) == FAIL) + goto erret; + } } else push_default_value(&cctx, m->ocm_type->tt_type, From 757593c07a4f4ac43eb6c6e52fc299abc9bc08bc Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Tue, 22 Aug 2023 21:44:10 +0200 Subject: [PATCH 07/91] patch 9.0.1781: Problems when setting bin/paste option Problem: Problems when setting bin/paste option Solution: When setting binary/paste, remember that this also affects depending options, so that :verbose set returns the right location. Mention if depending options for 'binary' or 'paste' have been reset indirectly. Add a test to verify it works. Also noticed as small bug, that the global option value for expandtab was not reset when paste option is set, so fix that while at it. closes: #12837 closes: #12879 Signed-off-by: Christian Brabandt Co-authored-by: zeertzjq --- src/option.c | 41 ++++++++++++++++++ src/testdir/test_options.vim | 81 ++++++++++++++++++++++++++++++++++++ src/version.c | 2 + 3 files changed, 124 insertions(+) diff --git a/src/option.c b/src/option.c index a6d73d2f55..15febb73c0 100644 --- a/src/option.c +++ b/src/option.c @@ -68,6 +68,21 @@ static void check_winopt(winopt_T *wop); static int wc_use_keyname(char_u *varp, long *wcp); static void compatible_set(void); +#if defined(FEAT_EVAL) || defined(PROTO) +static char *(p_bin_dep_opts[]) = {"textwidth", "wrapmargin", "modeline", "expandtab", NULL}; +static char *(p_paste_dep_opts[]) = {"autoindent", "expandtab", "ruler", "showmatch", "smarttab", + "softtabstop", "textwidth", "wrapmargin", +#ifdef FEAT_RIGHTLEFT + "hkmap", "revins", +#endif +#ifdef FEAT_VARTABS + "varsofttabstop", +#endif + NULL}; +static void didset_options_sctx(int opt_flags, char **buf); +#endif + + /* * Initialize the 'shell' option to a default value. */ @@ -2763,6 +2778,10 @@ set_options_bin( p_et = p_et_nobin; } } +#if defined(FEAT_EVAL) || defined(PROTO) + // Remember where the dependent option were reset + didset_options_sctx(opt_flags, p_bin_dep_opts); +#endif } /* @@ -3846,6 +3865,7 @@ did_set_paste(optset_T *args UNUSED) p_wm = 0; p_sts = 0; p_ai = 0; + p_et = 0; #ifdef FEAT_VARTABS if (p_vsts) free_string_option(p_vsts); @@ -3902,6 +3922,11 @@ did_set_paste(optset_T *args UNUSED) old_p_paste = p_paste; +#if defined(FEAT_EVAL) || defined(PROTO) + // Remember where the dependent options were reset + didset_options_sctx((OPT_LOCAL | OPT_GLOBAL), p_paste_dep_opts); +#endif + return NULL; } @@ -8170,3 +8195,19 @@ option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED) return FAIL; #endif } + +#if defined(FEAT_EVAL) || defined(PROTO) + static void +didset_options_sctx(int opt_flags, char **buf) +{ + for (int i = 0; ; ++i) + { + if (buf[i] == NULL) + break; + + int idx = findoption((char_u *)buf[i]); + if (idx >= 0) + set_option_sctx_idx(idx, opt_flags, current_sctx); + } +} +#endif diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim index 5bacebc35e..fec8d2a94c 100644 --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -1774,4 +1774,85 @@ func Test_set_option_window_global_local_all() bw! endfunc +func Test_paste_depending_options() + " setting the paste option, resets all dependent options + " and will be reported correctly using :verbose set