mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix match
This commit is contained in:
parent
9846fecd84
commit
968e310793
@ -513,8 +513,16 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
g.write('$type_sym.name $tmp = ')
|
||||
g.expr(it.cond)
|
||||
g.writeln(';') // $it.blocks.len')
|
||||
for branch in it.branches {
|
||||
g.write('if ')
|
||||
for j, branch in it.branches {
|
||||
if j == it.branches.len - 1 {
|
||||
// last block is an `else{}`
|
||||
g.writeln('else {')
|
||||
}
|
||||
else {
|
||||
if j > 0 {
|
||||
g.write('else ')
|
||||
}
|
||||
g.write('if (')
|
||||
for i, expr in branch.exprs {
|
||||
g.write('$tmp == ')
|
||||
g.expr(expr)
|
||||
@ -522,7 +530,8 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
g.write(' || ')
|
||||
}
|
||||
}
|
||||
g.writeln('{')
|
||||
g.writeln(') {')
|
||||
}
|
||||
g.stmts(branch.stmts)
|
||||
g.writeln('}')
|
||||
}
|
||||
|
@ -148,13 +148,15 @@ void println(string s) {
|
||||
void matches() {
|
||||
int a = 100;
|
||||
int tmp1 = a;
|
||||
if tmp1 == 10{
|
||||
if (tmp1 == 10) {
|
||||
println(tos3("10"));
|
||||
|
||||
}
|
||||
if tmp1 == 20{
|
||||
else if (tmp1 == 20) {
|
||||
int k = a + 1;
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
;
|
||||
}
|
||||
|
@ -147,6 +147,7 @@ fn matches() {
|
||||
20 {
|
||||
k := a + 1
|
||||
}
|
||||
else{}
|
||||
}
|
||||
/*
|
||||
n := match a {
|
||||
|
Loading…
Reference in New Issue
Block a user