Skip to content

Commit

Permalink
fix code generated to multiple var declaration (#114)
Browse files Browse the repository at this point in the history
Authored-by: Felipe Pena <felipe.pena@championx.com>
  • Loading branch information
felipensp authored Mar 21, 2023
1 parent 335a17e commit c589a9a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/c2v.v
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,9 @@ fn (mut c C2V) var_decl(mut decl_stmt Node) {
}
c.gen('${name} := ')
c.expr(expr)
if decl_stmt.inner.len > 1 {
c.gen('\n')
}
} else {
oldtyp := var_decl.ast_type.qualified
mut typ := typ_.name
Expand Down
3 changes: 3 additions & 0 deletions tests/15.multi_var_decl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
int n, r, sum = 0, temp;
}
9 changes: 9 additions & 0 deletions tests/15.multi_var_decl.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[translated]
module main

fn main() {
n := 0
r := 0
sum := 0
temp := 0
}

0 comments on commit c589a9a

Please sign in to comment.