Mercurial > vim
comparison src/testdir/test_vim9_import.vim @ 35037:5df4ad0a5200 v9.1.0369
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Commit: https://github.com/vim/vim/commit/3f821d6de2586d921fb23e2facb4764ef9eb3294
Author: Ernie Rael <errael@raelity.com>
Date: Wed Apr 24 20:07:50 2024 +0200
patch 9.1.0369: Vim9: problem when importing autoloaded scripts
Problem: Vim9: problem when importing autoloaded scripts
Solution: In `:def` handle storing to vim9 autoload export
(Ernie Rael)
Problem occurs when `import autoload ./.../autoload/...`. The autoload
in the specified path causes the use of an autoload_prefix which combines
with the `import autoload` to create trouble.
In `generate_store_var()` `case dest_script` use ISN_STOREEXPORT,
when needed, instead of ISN_STORES. When executing ISN_STOREEXPORT,
check for autoload_prefix.
fixes: #14606
closes: #14615
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 24 Apr 2024 20:15:03 +0200 |
parents | 97d3b04002f7 |
children | f2b94f240b7d |
comparison
equal
deleted
inserted
replaced
35036:26a9978d3a8c | 35037:5df4ad0a5200 |
---|---|
1204 " Test modifying exported autoload variable. Github issue: #14591 | 1204 " Test modifying exported autoload variable. Github issue: #14591 |
1205 def Test_autoload_export_variables() | 1205 def Test_autoload_export_variables() |
1206 mkdir('Xautoload_vars/autoload', 'pR') | 1206 mkdir('Xautoload_vars/autoload', 'pR') |
1207 var lines =<< trim END | 1207 var lines =<< trim END |
1208 vim9script | 1208 vim9script |
1209 g:Xautoload_vars_autoload = true | |
1209 export var val = 11 | 1210 export var val = 11 |
1210 val = 42 | 1211 val = 42 |
1211 END | 1212 END |
1212 | 1213 |
1213 # Test that the imported script, above, can modify the exported variable; | 1214 # Test that the imported script, above, can modify the exported variable; |
1214 # and test that the importing script, below, can modify the variable. | 1215 # and test that the importing script, below, can modify the variable. |
1215 writefile(lines, 'Xautoload_vars/autoload/Xauto_vars_f2.vim', 'D') | 1216 writefile(lines, 'Xautoload_vars/autoload/Xauto_vars_f2.vim', 'D') |
1216 lines =<< trim END | 1217 lines =<< trim END |
1217 vim9script | 1218 vim9script |
1219 g:Xautoload_vars_autoload = false | |
1218 | 1220 |
1219 import autoload './Xautoload_vars/autoload/Xauto_vars_f2.vim' as f2 | 1221 import autoload './Xautoload_vars/autoload/Xauto_vars_f2.vim' as f2 |
1222 # Verify that the import statement does not load the file. | |
1223 assert_equal(false, g:Xautoload_vars_autoload) | |
1220 | 1224 |
1221 def F(): number | 1225 def F(): number |
1222 return f2.val | 1226 return f2.val |
1223 enddef | 1227 enddef |
1228 # Verify compile does not load the file. | |
1229 defcompile F | |
1230 assert_equal(false, g:Xautoload_vars_autoload) | |
1231 | |
1232 # load the file by accessing the exported variable | |
1224 assert_equal(42, F()) | 1233 assert_equal(42, F()) |
1234 assert_equal(true, g:Xautoload_vars_autoload) | |
1235 unlet g:Xautoload_vars_autoload | |
1236 | |
1225 assert_equal(42, f2.val) | 1237 assert_equal(42, f2.val) |
1226 f2.val = 17 | 1238 f2.val = 17 |
1227 assert_equal(17, f2.val) | 1239 assert_equal(17, f2.val) |
1228 | 1240 |
1229 def G() | 1241 def G() |
1262 import autoload './Xautoload_vars/autoload/Xauto_vars_f4.vim' as f4 | 1274 import autoload './Xautoload_vars/autoload/Xauto_vars_f4.vim' as f4 |
1263 | 1275 |
1264 f4.val = 13 | 1276 f4.val = 13 |
1265 END | 1277 END |
1266 v9.CheckScriptFailure(lines, 'E46:') | 1278 v9.CheckScriptFailure(lines, 'E46:') |
1279 | |
1280 # Test const var is not modifiable from importing script from :def. | |
1281 # Github issue: #14606 | |
1282 lines =<< trim END | |
1283 vim9script | |
1284 export const val = 11 | |
1285 END | |
1286 writefile(lines, 'Xautoload_vars/autoload/Xauto_vars_f5.vim', 'D') | |
1287 lines =<< trim END | |
1288 vim9script | |
1289 | |
1290 import autoload './Xautoload_vars/autoload/Xauto_vars_f5.vim' as f5 | |
1291 | |
1292 def F() | |
1293 f5.val = 13 | |
1294 enddef | |
1295 F() | |
1296 END | |
1297 v9.CheckScriptFailure(lines, 'E741:') | |
1298 | |
1299 # Still part of Github issue: #14606 | |
1300 lines =<< trim END | |
1301 vim9script | |
1302 export var val = 11 | |
1303 END | |
1304 writefile(lines, 'Xautoload_vars/autoload/Xauto_vars_f6.vim', 'D') | |
1305 lines =<< trim END | |
1306 vim9script | |
1307 | |
1308 import autoload './Xautoload_vars/autoload/Xauto_vars_f6.vim' as f6 | |
1309 | |
1310 def F() | |
1311 f6.val = 13 | |
1312 enddef | |
1313 F() | |
1314 assert_equal(13, f6.val) | |
1315 END | |
1316 v9.CheckScriptSuccess(lines) | |
1267 enddef | 1317 enddef |
1268 | 1318 |
1269 def Test_autoload_import_relative_autoload_dir() | 1319 def Test_autoload_import_relative_autoload_dir() |
1270 mkdir('autoload', 'pR') | 1320 mkdir('autoload', 'pR') |
1271 var lines =<< trim END | 1321 var lines =<< trim END |