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

cgen: fix printing for mut v in arr (#17137)

This commit is contained in:
yuyi 2023-01-28 16:15:28 +08:00 committed by GitHub
parent b732dd6816
commit d3e4058aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -16,6 +16,9 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) {
mut base := 0 // numeric base
mut upper_case := false // set upercase for the result string
mut typ := g.unwrap_generic(node.expr_types[i])
if node.exprs[i].is_auto_deref_var() {
typ = typ.deref()
}
sym := g.table.sym(typ)
if sym.kind == .alias {

View File

@ -0,0 +1,4 @@
mutable num is 255
imutable element is 255
mutable element is 255
mutable element is 255

View File

@ -0,0 +1,21 @@
fn main() {
// check to see if mutable integers work as expected
mut num := 255
println('mutable num is ${num}')
mut arr := [255]
// check to see if mutable arrays with immutable iteration work as expected
for elem in arr {
println('imutable element is ${elem}')
}
// check to see if mutable arrays with mutable iteration work as expected
for mut elem in arr {
println('mutable element is ${elem}')
}
// check to see if mutable arrays with mutable iteration work as expected (explicit format)
for mut elem in arr {
println('mutable element is ${elem:d}')
}
}