mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
e356a74a4c
commit
0ca5b1f6ff
@ -126,6 +126,7 @@ mut:
|
|||||||
inside_match_result bool
|
inside_match_result bool
|
||||||
inside_vweb_tmpl bool
|
inside_vweb_tmpl bool
|
||||||
inside_return bool
|
inside_return bool
|
||||||
|
inside_return_tmpl bool
|
||||||
inside_struct_init bool
|
inside_struct_init bool
|
||||||
inside_or_block bool
|
inside_or_block bool
|
||||||
inside_call bool
|
inside_call bool
|
||||||
@ -4281,7 +4282,9 @@ fn (mut g Gen) return_stmt(node ast.Return) {
|
|||||||
if node.exprs.len > 0 {
|
if node.exprs.len > 0 {
|
||||||
// skip `return $vweb.html()`
|
// skip `return $vweb.html()`
|
||||||
if node.exprs[0] is ast.ComptimeCall && (node.exprs[0] as ast.ComptimeCall).is_vweb {
|
if node.exprs[0] is ast.ComptimeCall && (node.exprs[0] as ast.ComptimeCall).is_vweb {
|
||||||
|
g.inside_return_tmpl = true
|
||||||
g.expr(node.exprs[0])
|
g.expr(node.exprs[0])
|
||||||
|
g.inside_return_tmpl = false
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
|
|||||||
} else {
|
} else {
|
||||||
// return $tmpl string
|
// return $tmpl string
|
||||||
g.write(cur_line)
|
g.write(cur_line)
|
||||||
if g.inside_return {
|
if g.inside_return_tmpl {
|
||||||
g.write('return ')
|
g.write('return ')
|
||||||
}
|
}
|
||||||
g.write('_tmpl_res_$fn_name')
|
g.write('_tmpl_res_$fn_name')
|
||||||
|
1
vlib/v/tests/tmpl/template.txt
Normal file
1
vlib/v/tests/tmpl/template.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
@name
|
51
vlib/v/tests/tmpl_in_return_match_expr_test.v
Normal file
51
vlib/v/tests/tmpl_in_return_match_expr_test.v
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
fn foo1() string {
|
||||||
|
return match true {
|
||||||
|
true {
|
||||||
|
name := 'abc'
|
||||||
|
$tmpl('tmpl/template.txt')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
'else'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo2() string {
|
||||||
|
return if true {
|
||||||
|
name := 'abc'
|
||||||
|
$tmpl('tmpl/template.txt')
|
||||||
|
} else {
|
||||||
|
'else'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Res {
|
||||||
|
mut:
|
||||||
|
str string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo3() Res {
|
||||||
|
name := 'abc'
|
||||||
|
return Res{
|
||||||
|
str: $tmpl('tmpl/template.txt')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_res(str string) Res {
|
||||||
|
mut res := Res{}
|
||||||
|
res.str = str
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo4() Res {
|
||||||
|
name := 'abc'
|
||||||
|
return new_res($tmpl('tmpl/template.txt'))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_tmpl_in_return_match_expr() {
|
||||||
|
println(foo1())
|
||||||
|
println(foo2())
|
||||||
|
println(foo3())
|
||||||
|
println(foo4())
|
||||||
|
assert true
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user