Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 25800:fe8d153cb268 v8.2.3435
patch 8.2.3435: Vim9: dict is not passed to dict function
Commit: https://github.com/vim/vim/commit/b1b6f4de2b0edc3b6622912132ddb8994ec52709
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 13 18:25:54 2021 +0200
patch 8.2.3435: Vim9: dict is not passed to dict function
Problem: Vim9: dict is not passed to dict function.
Solution: Keep the dict used until a function call.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 13 Sep 2021 18:30:04 +0200 |
parents | 9edad9a8cca6 |
children | e861c5aaedd8 |
comparison
equal
deleted
inserted
replaced
25799:0493410eba74 | 25800:fe8d153cb268 |
---|---|
2555 'try', 'catch', 'finally', 'endtry'] | 2555 'try', 'catch', 'finally', 'endtry'] |
2556 CheckDefFailure(['legacy ' .. cmd .. ' expr'], 'E1189:') | 2556 CheckDefFailure(['legacy ' .. cmd .. ' expr'], 'E1189:') |
2557 endfor | 2557 endfor |
2558 enddef | 2558 enddef |
2559 | 2559 |
2560 def Test_call_legacy_with_dict() | |
2561 var lines =<< trim END | |
2562 vim9script | |
2563 func Legacy() dict | |
2564 let g:result = self.value | |
2565 endfunc | |
2566 def TestDirect() | |
2567 var d = {value: 'yes', func: Legacy} | |
2568 d.func() | |
2569 enddef | |
2570 TestDirect() | |
2571 assert_equal('yes', g:result) | |
2572 unlet g:result | |
2573 | |
2574 def TestIndirect() | |
2575 var d = {value: 'foo', func: Legacy} | |
2576 var Fi = d.func | |
2577 Fi() | |
2578 enddef | |
2579 TestIndirect() | |
2580 assert_equal('foo', g:result) | |
2581 unlet g:result | |
2582 | |
2583 var d = {value: 'bar', func: Legacy} | |
2584 d.func() | |
2585 assert_equal('bar', g:result) | |
2586 unlet g:result | |
2587 END | |
2588 CheckScriptSuccess(lines) | |
2589 enddef | |
2590 | |
2560 def DoFilterThis(a: string): list<string> | 2591 def DoFilterThis(a: string): list<string> |
2561 # closure nested inside another closure using argument | 2592 # closure nested inside another closure using argument |
2562 var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0) | 2593 var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0) |
2563 return ['x', 'y', 'a', 'x2', 'c']->Filter() | 2594 return ['x', 'y', 'a', 'x2', 'c']->Filter() |
2564 enddef | 2595 enddef |