mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
8327c9afc1
commit
c704a49283
@ -551,6 +551,14 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
|
|||||||
p.tok.position())
|
p.tok.position())
|
||||||
}
|
}
|
||||||
mut label_names := []string{}
|
mut label_names := []string{}
|
||||||
|
mut func := table.Fn{
|
||||||
|
params: args
|
||||||
|
is_variadic: is_variadic
|
||||||
|
return_type: return_type
|
||||||
|
}
|
||||||
|
name := 'anon_fn_${p.table.fn_type_signature(func)}_$p.tok.pos'
|
||||||
|
keep_fn_name := p.cur_fn_name
|
||||||
|
p.cur_fn_name = name
|
||||||
if p.tok.kind == .lcbr {
|
if p.tok.kind == .lcbr {
|
||||||
tmp := p.label_names
|
tmp := p.label_names
|
||||||
p.label_names = []
|
p.label_names = []
|
||||||
@ -558,13 +566,8 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
|
|||||||
label_names = p.label_names
|
label_names = p.label_names
|
||||||
p.label_names = tmp
|
p.label_names = tmp
|
||||||
}
|
}
|
||||||
|
p.cur_fn_name = keep_fn_name
|
||||||
p.close_scope()
|
p.close_scope()
|
||||||
mut func := table.Fn{
|
|
||||||
params: args
|
|
||||||
is_variadic: is_variadic
|
|
||||||
return_type: return_type
|
|
||||||
}
|
|
||||||
name := 'anon_fn_${p.table.fn_type_signature(func)}_$p.tok.pos'
|
|
||||||
func.name = name
|
func.name = name
|
||||||
idx := p.table.find_or_register_fn_type(p.mod, func, true, false)
|
idx := p.table.find_or_register_fn_type(p.mod, func, true, false)
|
||||||
typ := table.new_type(idx)
|
typ := table.new_type(idx)
|
||||||
|
@ -13,6 +13,26 @@ age: 25
|
|||||||
numbers: [1, 2, 3]
|
numbers: [1, 2, 3]
|
||||||
|
|
||||||
|
|
||||||
|
1
|
||||||
|
|
||||||
|
2
|
||||||
|
|
||||||
|
3'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_tmpl_in_anon_fn() {
|
||||||
|
anon := fn (name string, age int, numbers []int) string {
|
||||||
|
return $tmpl('tmpl/1.txt')
|
||||||
|
}
|
||||||
|
|
||||||
|
println(anon('Peter', 25, [1, 2, 3]))
|
||||||
|
assert anon('Peter', 25, [1, 2, 3]).trim_space() == 'name: Peter
|
||||||
|
|
||||||
|
age: 25
|
||||||
|
|
||||||
|
numbers: [1, 2, 3]
|
||||||
|
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
||||||
2
|
2
|
||||||
|
Loading…
Reference in New Issue
Block a user