diff src/testdir/test_vim9_assign.vim @ 24377:f9f8cceaece3 v8.2.2729

patch 8.2.2729: Vim9: wrong error message for referring to legacy script var Commit: https://github.com/vim/vim/commit/643ce6c0c694667a2afd24bb39d8e9d36d94d7a9 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 6 21:17:27 2021 +0200 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var Problem: Vim9: wrong error message for referring to legacy script variable. Solution: Do allow referring to a variable in legacy script without "s:" if it exists at compile time. (closes #8076)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Apr 2021 21:30:04 +0200
parents 95b8937804d3
children 78343859f42d
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -1476,6 +1476,41 @@ def Test_var_declaration_fails()
   CheckDefFailure(['const foo: number'], 'E1021:')
 enddef
 
+def Test_script_local_in_legacy()
+  # OK to define script-local later when prefixed with s:
+  var lines =<< trim END
+    def SetLater()
+      s:legacy = 'two'
+    enddef
+    defcompile
+    let s:legacy = 'one'
+    call SetLater()
+    call assert_equal('two', s:legacy)
+  END
+  CheckScriptSuccess(lines)
+
+  # OK to leave out s: prefix when script-local already defined
+  lines =<< trim END
+    let s:legacy = 'one'
+    def SetNoPrefix()
+      legacy = 'two'
+    enddef
+    call SetNoPrefix()
+    call assert_equal('two', s:legacy)
+  END
+  CheckScriptSuccess(lines)
+
+  # Not OK to leave out s: prefix when script-local defined later
+  lines =<< trim END
+    def SetLaterNoPrefix()
+      legacy = 'two'
+    enddef
+    defcompile
+    let s:legacy = 'one'
+  END
+  CheckScriptFailure(lines, 'E476:', 1)
+enddef
+
 def Test_var_type_check()
   var lines =<< trim END
     vim9script