Skip to content

Commit c5a290f

Browse files
authored
cgen: fix lost return in ComptimeCall (fixes #14962) (#14995)
1 parent 70890b2 commit c5a290f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4052,7 +4052,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
40524052

40534053
if node.exprs.len > 0 {
40544054
// skip `return $vweb.html()`
4055-
if node.exprs[0] is ast.ComptimeCall {
4055+
if node.exprs[0] is ast.ComptimeCall && (node.exprs[0] as ast.ComptimeCall).is_vweb {
40564056
g.expr(node.exprs[0])
40574057
g.writeln(';')
40584058
return

vlib/v/tests/return_comptime_call.v

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
struct App {}
2+
3+
fn (mut app App) method_one() string {
4+
return '1'
5+
}
6+
7+
fn (mut app App) method_two() string {
8+
return '2'
9+
}
10+
11+
fn reflect_call(method_name string) string {
12+
a := App{}
13+
$for method in App.methods {
14+
if method.name == method_name {
15+
return a.$method()
16+
}
17+
}
18+
panic('Method not supported: $method_name')
19+
}
20+
21+
fn main() {
22+
result := reflect_call('method_one')
23+
println(result)
24+
assert result == '1'
25+
}

0 commit comments

Comments
 (0)