diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 36038cbf3d..0b27c6062f 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4052,7 +4052,7 @@ fn (mut g Gen) return_stmt(node ast.Return) { if node.exprs.len > 0 { // skip `return $vweb.html()` - if node.exprs[0] is ast.ComptimeCall { + if node.exprs[0] is ast.ComptimeCall && (node.exprs[0] as ast.ComptimeCall).is_vweb { g.expr(node.exprs[0]) g.writeln(';') return diff --git a/vlib/v/tests/return_comptime_call.v b/vlib/v/tests/return_comptime_call.v new file mode 100644 index 0000000000..d47292e2c8 --- /dev/null +++ b/vlib/v/tests/return_comptime_call.v @@ -0,0 +1,25 @@ +struct App {} + +fn (mut app App) method_one() string { + return '1' +} + +fn (mut app App) method_two() string { + return '2' +} + +fn reflect_call(method_name string) string { + a := App{} + $for method in App.methods { + if method.name == method_name { + return a.$method() + } + } + panic('Method not supported: $method_name') +} + +fn main() { + result := reflect_call('method_one') + println(result) + assert result == '1' +}