Skip to content

Commit 2bca7b8

Browse files
authored
handle multi-var stmts (#141)
* handle multi-var stmts * fix fmt
1 parent 83eaa85 commit 2bca7b8

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

stmt.v

+39-26
Original file line numberDiff line numberDiff line change
@@ -164,43 +164,56 @@ fn (mut app App) decl_stmt(d DeclStmt) {
164164
for spec in d.decl.specs {
165165
match spec {
166166
ValueSpec {
167-
n := spec.names[0].name
168-
if app.cur_fn_names[n] {
169-
println('${n} already declared in cur fn. skipping. (why does this happen?)')
170-
return
171-
}
172-
// app.genln('// value spec')
173167
app.gen('mut ')
174-
if n == 'layerDuplicates2' {
175-
// app.genln('${d}')
176-
println('=================')
177-
print_backtrace()
178-
println('1111111111111111111111')
168+
for idx in 0 .. spec.names.len {
169+
if idx > 0 {
170+
app.gen(',')
171+
}
172+
n := spec.names[idx].name
173+
if app.cur_fn_names[n] {
174+
println('${n} already declared in cur fn. skipping. (why does this happen?)')
175+
return
176+
}
177+
if n == 'layerDuplicates2' {
178+
// app.genln('${d}')
179+
println('=================')
180+
print_backtrace()
181+
println('1111111111111111111111')
182+
}
183+
app.gen(n)
184+
app.cur_fn_names[n] = true
179185
}
180-
app.gen(n)
181186
app.gen(' := ')
182-
app.cur_fn_names[n] = true
183187
mut kind := 'int'
184188
if spec.values.len == 0 {
185-
// app.genln('NO SPEC VALUES')
186-
// `var x int` declaration without initialization
187189
app.force_upper = true
188190
app.gen_zero_value(spec.typ)
189191
continue
190192
}
191-
value := spec.values[0]
192-
match value {
193-
BasicLit {
194-
kind = go2v_type(value.kind.to_lower())
195-
if kind != 'int' {
196-
app.gen('${kind}(')
193+
mut needs_cast := false
194+
for idx in 0 .. spec.values.len {
195+
if idx > 0 {
196+
app.gen(',')
197+
}
198+
value := spec.values[idx]
199+
match value {
200+
BasicLit {
201+
kind = go2v_type(value.kind.to_lower())
202+
if kind != 'int' && kind != 'string'
203+
&& value.kind.to_lower() != 'char' {
204+
needs_cast = true
205+
}
206+
if needs_cast {
207+
app.gen('${kind}(')
208+
}
197209
}
210+
else {}
198211
}
199-
else {}
200-
}
201-
app.expr(spec.values[0])
202-
if kind != 'int' {
203-
app.gen(')')
212+
app.expr(spec.values[idx])
213+
if needs_cast {
214+
app.gen(')')
215+
}
216+
needs_cast = false
204217
}
205218
}
206219
else {

tests/if_complex_condition/if_complex_condition.vv

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
}
1616
if 3 <= 4 && true || false {
1717
}
18-
mut c := u8(`X`)
18+
mut c := `X`
1919
if !(c == `(` || c == `B` || c == `C` || c == `D` || c == `F` || c == `I` || c == `J`
2020
|| c == `L` || c == `S` || c == `Z` || c == `[`) {
2121
println('Invalid')
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)