Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 22, 2025
1 parent 6b0c272 commit 90b15ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,8 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
}
}
}
} else if stmt is ast.Return {
g.stmt(stmt)
}
} else if g.inside_if_result || g.inside_match_result {
g.set_current_pos_as_last_stmt_pos()
Expand Down
28 changes: 28 additions & 0 deletions vlib/v/tests/options/option_multi_return_if_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module main

fn test_main() {
s := 'post = [id:66][title:A link 2 Ze Past][date:1737560206][dir:./push_66]'

id, title, date, dir := parse_post_values('post', s) or {
eprintln('Failed to parse !')
return
}
assert 'Results : id=${id} title=${title} date=${date} dir=${dir}' == 'Results : id=66 title=A link 2 Ze Past date=1737560206 dir=./push_66'
}

pub fn parse_post_values(label string, s string) ?(u64, string, i64, string) {
if s.starts_with(label) {
id := s.find_between('[id:', ']').u64()
title := s.find_between('[title:', ']')
date := s.find_between('[date:', ']').i64()
dir := s.find_between('[dir:', ']')

return if title.len == 0 {
none
} else {
println('${@FILE_LINE} ${@FN}: Success -> id=${id} title=${title} date=${date} dir=${dir}')
return id, title, date, dir
}
}
return none
}

0 comments on commit 90b15ec

Please sign in to comment.