Mercurial > vim
comparison src/testdir/test_vim9_assign.vim @ 27843:532a0c5de1ec v8.2.4447
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Commit: https://github.com/vim/vim/commit/afa048f0d4b5d63f2192c9ba340a9eb8b0822985
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 22 20:43:36 2022 +0000
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Problem: Vim9: can still use s:var in a compiled function.
Solution: Disallow using s:var for Vim9 script. (closes https://github.com/vim/vim/issues/9824)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 22 Feb 2022 21:45:03 +0100 |
parents | b081ba78675a |
children | 7d70b420de00 |
comparison
equal
deleted
inserted
replaced
27842:4b3c59be80c7 | 27843:532a0c5de1ec |
---|---|
218 def SomeFunc() | 218 def SomeFunc() |
219 s:var = 123 | 219 s:var = 123 |
220 enddef | 220 enddef |
221 defcompile | 221 defcompile |
222 END | 222 END |
223 v9.CheckScriptFailure(lines, 'E1089:') | 223 v9.CheckScriptFailure(lines, 'E1268:') |
224 | 224 |
225 g:inc_counter += 1 | 225 g:inc_counter += 1 |
226 assert_equal(2, g:inc_counter) | 226 assert_equal(2, g:inc_counter) |
227 | 227 |
228 if has('float') | 228 if has('float') |
2458 g:TermWait(buf) | 2458 g:TermWait(buf) |
2459 g:WaitForAssert(() => assert_match('\[\[1, 2, 3\], \[4, 5, 6\]\]', term_getline(buf, 6))) | 2459 g:WaitForAssert(() => assert_match('\[\[1, 2, 3\], \[4, 5, 6\]\]', term_getline(buf, 6))) |
2460 g:StopVimInTerminal(buf) | 2460 g:StopVimInTerminal(buf) |
2461 enddef | 2461 enddef |
2462 | 2462 |
2463 def Test_using_s_var_in_function() | |
2464 var lines =<< trim END | |
2465 vim9script | |
2466 var scriptlevel = 123 | |
2467 def SomeFunc() | |
2468 echo s:scriptlevel | |
2469 enddef | |
2470 SomeFunc() | |
2471 END | |
2472 v9.CheckScriptFailure(lines, 'E1268:') | |
2473 | |
2474 # OK in legacy script | |
2475 lines =<< trim END | |
2476 let s:scriptlevel = 123 | |
2477 def s:SomeFunc() | |
2478 echo s:scriptlevel | |
2479 enddef | |
2480 call s:SomeFunc() | |
2481 END | |
2482 v9.CheckScriptSuccess(lines) | |
2483 | |
2484 lines =<< trim END | |
2485 vim9script | |
2486 var scriptlevel = 123 | |
2487 def SomeFunc() | |
2488 s:scriptlevel = 456 | |
2489 enddef | |
2490 SomeFunc() | |
2491 END | |
2492 v9.CheckScriptFailure(lines, 'E1268:') | |
2493 | |
2494 # OK in legacy script | |
2495 lines =<< trim END | |
2496 let s:scriptlevel = 123 | |
2497 def s:SomeFunc() | |
2498 s:scriptlevel = 456 | |
2499 enddef | |
2500 call s:SomeFunc() | |
2501 call assert_equal(456, s:scriptlevel) | |
2502 END | |
2503 v9.CheckScriptSuccess(lines) | |
2504 enddef | |
2505 | |
2463 | 2506 |
2464 | 2507 |
2465 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 2508 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |