1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix lost return in ComptimeCall (fixes #14962) (#14995)

This commit is contained in:
shove 2022-07-09 13:55:01 +08:00 committed by GitHub
parent 70890b27a5
commit c5a290ffc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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

View File

@ -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'
}